brew vendor-gems: commit updates.
This commit is contained in:
parent
d517364d9f
commit
afb2978995
10
Library/Homebrew/vendor/bundle/bundler/setup.rb
vendored
10
Library/Homebrew/vendor/bundle/bundler/setup.rb
vendored
@ -18,7 +18,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/json-2.2.0/lib"
|
|||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/docile-1.3.2/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/docile-1.3.2/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-html-0.10.2/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-html-0.10.2/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-0.16.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-0.16.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tins-1.20.3/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tins-1.21.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/term-ansicolor-1.7.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/term-ansicolor-1.7.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/thor-0.20.3/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/thor-0.20.3/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/coveralls-0.8.23/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/coveralls-0.8.23/lib"
|
||||||
@ -26,7 +26,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/diff-lcs-1.3/lib"
|
|||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-18/2.3.0/unf_ext-0.0.7.6"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-18/2.3.0/unf_ext-0.0.7.6"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unf_ext-0.0.7.6/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unf_ext-0.0.7.6/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unf-0.1.4/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unf-0.1.4/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/domain_name-0.5.20180417/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/domain_name-0.5.20190701/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-18/2.3.0/hpricot-0.8.6"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-18/2.3.0/hpricot-0.8.6"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/hpricot-0.8.6/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/hpricot-0.8.6/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/http-cookie-1.0.3/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/http-cookie-1.0.3/lib"
|
||||||
@ -52,7 +52,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwi
|
|||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rdiscount-2.2.0.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rdiscount-2.2.0.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ronn-0.7.3/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ronn-0.7.3/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-support-3.8.2/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-support-3.8.2/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-core-3.8.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-core-3.8.2/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-expectations-3.8.4/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-expectations-3.8.4/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-mocks-3.8.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-mocks-3.8.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-3.8.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-3.8.0/lib"
|
||||||
@ -61,8 +61,8 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-retry-0.6.1/lib
|
|||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-wait-0.0.9/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-wait-0.0.9/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.10.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.10.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-1.6.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-1.6.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.72.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.73.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.4.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.4.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.33.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.34.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.2.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.2.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-cobertura-1.3.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-cobertura-1.3.1/lib"
|
||||||
|
|||||||
@ -50,7 +50,7 @@ RSpec/BeforeAfterAll:
|
|||||||
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll
|
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll
|
||||||
|
|
||||||
RSpec/ContextWording:
|
RSpec/ContextWording:
|
||||||
Description: "`context` block descriptions should start with 'when', or 'with'."
|
Description: Checks that `context` docstring starts with an allowed prefix.
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Prefixes:
|
Prefixes:
|
||||||
- when
|
- when
|
||||||
@ -251,6 +251,11 @@ RSpec/LeadingSubject:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LeadingSubject
|
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LeadingSubject
|
||||||
|
|
||||||
|
RSpec/LeakyConstantDeclaration:
|
||||||
|
Description: Checks that no class, module, or constant is declared.
|
||||||
|
Enabled: true
|
||||||
|
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LeakyConstantDeclaration
|
||||||
|
|
||||||
RSpec/LetBeforeExamples:
|
RSpec/LetBeforeExamples:
|
||||||
Description: Checks for `let` definitions that come after an example.
|
Description: Checks for `let` definitions that come after an example.
|
||||||
Enabled: true
|
Enabled: true
|
||||||
@ -33,7 +33,6 @@ module RuboCop
|
|||||||
disallowed_stub(node) do |method|
|
disallowed_stub(node) do |method|
|
||||||
add_offense(
|
add_offense(
|
||||||
node,
|
node,
|
||||||
location: :expression,
|
|
||||||
message: format(MSG, method: method)
|
message: format(MSG, method: method)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -51,7 +51,7 @@ module RuboCop
|
|||||||
private
|
private
|
||||||
|
|
||||||
def add_no_arg_offense(node)
|
def add_no_arg_offense(node)
|
||||||
add_offense(node, location: :expression, message: MSG_NO_ARG)
|
add_offense(node, message: MSG_NO_ARG)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_for_unused_proxy(block, proxy)
|
def check_for_unused_proxy(block, proxy)
|
||||||
@ -63,7 +63,6 @@ module RuboCop
|
|||||||
|
|
||||||
add_offense(
|
add_offense(
|
||||||
proxy,
|
proxy,
|
||||||
location: :expression,
|
|
||||||
message: format(MSG_UNUSED_ARG, arg: name)
|
message: format(MSG_UNUSED_ARG, arg: name)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -37,7 +37,6 @@ module RuboCop
|
|||||||
before_or_after_all(node) do |hook|
|
before_or_after_all(node) do |hook|
|
||||||
add_offense(
|
add_offense(
|
||||||
node,
|
node,
|
||||||
location: :expression,
|
|
||||||
message: format(MSG, hook: hook.source)
|
message: format(MSG, hook: hook.source)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -3,18 +3,22 @@
|
|||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
# `context` block descriptions should start with 'when', or 'with'.
|
# Checks that `context` docstring starts with an allowed prefix.
|
||||||
#
|
#
|
||||||
# @see https://github.com/reachlocal/rspec-style-guide#context-descriptions
|
# @see https://github.com/reachlocal/rspec-style-guide#context-descriptions
|
||||||
# @see http://www.betterspecs.org/#contexts
|
# @see http://www.betterspecs.org/#contexts
|
||||||
#
|
#
|
||||||
# @example `Prefixes` configuration option, defaults: 'when', 'with', and
|
# @example `Prefixes` configuration
|
||||||
# 'without'
|
#
|
||||||
# Prefixes:
|
# # .rubocop.yml
|
||||||
# - when
|
# # RSpec/ContextWording:
|
||||||
# - with
|
# # Prefixes:
|
||||||
# - without
|
# # - when
|
||||||
# - if
|
# # - with
|
||||||
|
# # - without
|
||||||
|
# # - if
|
||||||
|
# # - unless
|
||||||
|
# # - for
|
||||||
#
|
#
|
||||||
# @example
|
# @example
|
||||||
# # bad
|
# # bad
|
||||||
@ -35,7 +39,8 @@ module RuboCop
|
|||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
context_wording(node) do |context|
|
context_wording(node) do |context|
|
||||||
add_offense(context, message: message)
|
add_offense(context,
|
||||||
|
message: format(MSG, prefixes: joined_prefixes))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -45,14 +50,6 @@ module RuboCop
|
|||||||
!prefixes.include?(description.split.first)
|
!prefixes.include?(description.split.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prefixes
|
|
||||||
cop_config['Prefixes'] || []
|
|
||||||
end
|
|
||||||
|
|
||||||
def message
|
|
||||||
format(MSG, prefixes: joined_prefixes)
|
|
||||||
end
|
|
||||||
|
|
||||||
def joined_prefixes
|
def joined_prefixes
|
||||||
quoted = prefixes.map { |prefix| "'#{prefix}'" }
|
quoted = prefixes.map { |prefix| "'#{prefix}'" }
|
||||||
return quoted.first if quoted.size == 1
|
return quoted.first if quoted.size == 1
|
||||||
@ -60,6 +57,10 @@ module RuboCop
|
|||||||
quoted << "or #{quoted.pop}"
|
quoted << "or #{quoted.pop}"
|
||||||
quoted.join(', ')
|
quoted.join(', ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prefixes
|
||||||
|
cop_config['Prefixes'] || []
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -52,7 +52,7 @@ module RuboCop
|
|||||||
return if pairs.any?(&method(:rails_metadata?))
|
return if pairs.any?(&method(:rails_metadata?))
|
||||||
end
|
end
|
||||||
|
|
||||||
add_offense(args.first, location: :expression)
|
add_offense(args.first)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -27,7 +27,7 @@ module RuboCop
|
|||||||
return unless second_arg&.str_type?
|
return unless second_arg&.str_type?
|
||||||
return if second_arg.str_content.start_with?('#', '.')
|
return if second_arg.str_content.start_with?('#', '.')
|
||||||
|
|
||||||
add_offense(second_arg, location: :expression)
|
add_offense(second_arg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -26,7 +26,7 @@ module RuboCop
|
|||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
describe_symbol?(node) do |match|
|
describe_symbol?(node) do |match|
|
||||||
add_offense(match, location: :expression)
|
add_offense(match)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -33,7 +33,6 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class DescribedClass < Cop
|
class DescribedClass < Cop
|
||||||
include RuboCop::RSpec::TopLevelDescribe
|
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
DESCRIBED_CLASS = 'described_class'
|
DESCRIBED_CLASS = 'described_class'
|
||||||
@ -48,20 +47,19 @@ module RuboCop
|
|||||||
|
|
||||||
def_node_matcher :scope_changing_syntax?, '{def class module}'
|
def_node_matcher :scope_changing_syntax?, '{def class module}'
|
||||||
|
|
||||||
def on_block(node)
|
def_node_matcher :described_constant, <<-PATTERN
|
||||||
# In case the explicit style is used, we needs to remember what's
|
(block (send _ :describe $(const ...) ...) (args) $_)
|
||||||
# being described. Thus, we use an ivar for @described_class.
|
PATTERN
|
||||||
describe, @described_class, body = described_constant(node)
|
|
||||||
|
|
||||||
return if body.nil?
|
def on_block(node)
|
||||||
return unless top_level_describe?(describe)
|
# In case the explicit style is used, we need to remember what's
|
||||||
|
# being described.
|
||||||
|
@described_class, body = described_constant(node)
|
||||||
|
|
||||||
|
return unless body
|
||||||
|
|
||||||
find_usage(body) do |match|
|
find_usage(body) do |match|
|
||||||
add_offense(
|
add_offense(match, message: message(match.const_name))
|
||||||
match,
|
|
||||||
location: :expression,
|
|
||||||
message: message(match.const_name)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -108,16 +106,84 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def skip_blocks?
|
def skip_blocks?
|
||||||
cop_config['SkipBlocks'].equal?(true)
|
cop_config['SkipBlocks']
|
||||||
end
|
end
|
||||||
|
|
||||||
def offensive?(node)
|
def offensive?(node)
|
||||||
if style == :described_class
|
if style == :described_class
|
||||||
node.eql?(@described_class)
|
offensive_described_class?(node)
|
||||||
else
|
else
|
||||||
node.send_type? && node.method_name == :described_class
|
node.send_type? && node.method_name == :described_class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def offensive_described_class?(node)
|
||||||
|
return unless node.const_type?
|
||||||
|
|
||||||
|
nearest_described_class, = node.each_ancestor(:block)
|
||||||
|
.map { |ancestor| described_constant(ancestor) }.find(&:itself)
|
||||||
|
|
||||||
|
return if nearest_described_class.equal?(node)
|
||||||
|
|
||||||
|
full_const_name(nearest_described_class) == full_const_name(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def full_const_name(node)
|
||||||
|
collapse_namespace(namespace(node), const_name(node))
|
||||||
|
end
|
||||||
|
|
||||||
|
# @param namespace [Array<Symbol>]
|
||||||
|
# @param const [Array<Symbol>]
|
||||||
|
# @return [Array<Symbol>]
|
||||||
|
# @example
|
||||||
|
# # nil represents base constant
|
||||||
|
# collapse_namespace([], :C) # => [:C]
|
||||||
|
# collapse_namespace([:A, :B], [:C) # => [:A, :B, :C]
|
||||||
|
# collapse_namespace([:A, :B], [:B, :C) # => [:A, :B, :C]
|
||||||
|
# collapse_namespace([:A, :B], [nil, :C) # => [nil, :C]
|
||||||
|
# collapse_namespace([:A, :B], [nil, :B, :C) # => [nil, :B, :C]
|
||||||
|
def collapse_namespace(namespace, const)
|
||||||
|
return const if namespace.empty?
|
||||||
|
return const if const.first.nil?
|
||||||
|
|
||||||
|
start = [0, (namespace.length - const.length)].max
|
||||||
|
max = namespace.length
|
||||||
|
intersection = (start..max).find do |shift|
|
||||||
|
namespace[shift, max - shift] == const[0, max - shift]
|
||||||
|
end
|
||||||
|
[*namespace[0, intersection], *const]
|
||||||
|
end
|
||||||
|
|
||||||
|
# @param node [RuboCop::AST::Node]
|
||||||
|
# @return [Array<Symbol>]
|
||||||
|
# @example
|
||||||
|
# const_name(s(:const, nil, :C)) # => [:C]
|
||||||
|
# const_name(s(:const, s(:const, nil, :M), :C)) # => [:M, :C]
|
||||||
|
# const_name(s(:const, s(:cbase), :C)) # => [nil, :C]
|
||||||
|
def const_name(node)
|
||||||
|
# rubocop:disable InternalAffairs/NodeDestructuring
|
||||||
|
namespace, name = *node
|
||||||
|
# rubocop:enable InternalAffairs/NodeDestructuring
|
||||||
|
if !namespace
|
||||||
|
[name]
|
||||||
|
elsif namespace.cbase_type?
|
||||||
|
[nil, name]
|
||||||
|
else
|
||||||
|
[*const_name(namespace), name]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# @param node [RuboCop::AST::Node]
|
||||||
|
# @return [Array<Symbol>]
|
||||||
|
# @example
|
||||||
|
# namespace(node) # => [:A, :B, :C]
|
||||||
|
def namespace(node)
|
||||||
|
node
|
||||||
|
.each_ancestor(:class, :module)
|
||||||
|
.reverse_each
|
||||||
|
.flat_map { |ancestor| ancestor.defined_module_name.split('::') }
|
||||||
|
.map(&:to_sym)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -70,7 +70,7 @@ module RuboCop
|
|||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example_group?(node) && !contains_example?(node)
|
return unless example_group?(node) && !contains_example?(node)
|
||||||
|
|
||||||
add_offense(node.send_node, location: :expression)
|
add_offense(node.send_node)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -24,7 +24,7 @@ module RuboCop
|
|||||||
return if last_child?(node)
|
return if last_child?(node)
|
||||||
|
|
||||||
missing_separating_line(node) do |location|
|
missing_separating_line(node) do |location|
|
||||||
add_offense(node, location: location, message: MSG)
|
add_offense(node, location: location)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ module RuboCop
|
|||||||
|
|
||||||
return unless length > max_length
|
return unless length > max_length
|
||||||
|
|
||||||
add_offense(node, location: :expression, message: message(length))
|
add_offense(node, message: message(length))
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -36,10 +36,12 @@ module RuboCop
|
|||||||
SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
|
SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
|
||||||
IT_PREFIX = /\Ait /i.freeze
|
IT_PREFIX = /\Ait /i.freeze
|
||||||
|
|
||||||
def_node_matcher(
|
def_node_matcher :it_description, <<-PATTERN
|
||||||
:it_description,
|
(block (send _ :it ${
|
||||||
'(block (send _ :it $(str $_) ...) ...)'
|
(str $_)
|
||||||
)
|
(dstr (str $_ ) ...)
|
||||||
|
} ...) ...)
|
||||||
|
PATTERN
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
it_description(node) do |description_node, message|
|
it_description(node) do |description_node, message|
|
||||||
@ -45,7 +45,7 @@ module RuboCop
|
|||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
expect_literal(node) do |argument|
|
expect_literal(node) do |argument|
|
||||||
add_offense(argument, location: :expression)
|
add_offense(argument)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -21,7 +21,9 @@ module RuboCop
|
|||||||
def on_gvasgn(node)
|
def on_gvasgn(node)
|
||||||
return unless inside_example_scope?(node)
|
return unless inside_example_scope?(node)
|
||||||
|
|
||||||
|
# rubocop:disable InternalAffairs/NodeDestructuring
|
||||||
variable_name, _rhs = *node
|
variable_name, _rhs = *node
|
||||||
|
# rubocop:enable InternalAffairs/NodeDestructuring
|
||||||
name = variable_name[1..-1]
|
name = variable_name[1..-1]
|
||||||
return unless name.eql?('stdout') || name.eql?('stderr')
|
return unless name.eql?('stdout') || name.eql?('stderr')
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ module RuboCop
|
|||||||
next unless offensive_receiver?(attribute.receiver, node)
|
next unless offensive_receiver?(attribute.receiver, node)
|
||||||
next if proc?(attribute) || association?(attribute)
|
next if proc?(attribute) || association?(attribute)
|
||||||
|
|
||||||
add_offense(attribute, location: :expression)
|
add_offense(attribute)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -51,8 +51,7 @@ module RuboCop
|
|||||||
return unless n_times_block_without_arg?(node)
|
return unless n_times_block_without_arg?(node)
|
||||||
return unless contains_only_factory?(node.body)
|
return unless contains_only_factory?(node.body)
|
||||||
|
|
||||||
add_offense(node.send_node,
|
add_offense(node.send_node, message: MSG_CREATE_LIST)
|
||||||
location: :expression, message: MSG_CREATE_LIST)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
@ -59,7 +59,6 @@ module RuboCop
|
|||||||
|
|
||||||
add_offense(
|
add_offense(
|
||||||
node,
|
node,
|
||||||
location: :expression,
|
|
||||||
message: format(MSG, suffix: glob)
|
message: format(MSG, suffix: glob)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -44,7 +44,7 @@ module RuboCop
|
|||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
focus_metadata(node) do |focus|
|
focus_metadata(node) do |focus|
|
||||||
add_offense(focus, location: :expression)
|
add_offense(focus)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -80,7 +80,6 @@ module RuboCop
|
|||||||
style_detected(scope_name)
|
style_detected(scope_name)
|
||||||
add_offense(
|
add_offense(
|
||||||
method_send,
|
method_send,
|
||||||
location: :expression,
|
|
||||||
message: explicit_message(scope_name)
|
message: explicit_message(scope_name)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -43,7 +43,7 @@ module RuboCop
|
|||||||
|
|
||||||
null_double(node) do |var, receiver|
|
null_double(node) do |var, receiver|
|
||||||
have_received_usage(node) do |expected|
|
have_received_usage(node) do |expected|
|
||||||
add_offense(receiver, location: :expression) if expected == var
|
add_offense(receiver) if expected == var
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -68,7 +68,7 @@ module RuboCop
|
|||||||
return if inside_dynamic_class?(ivar)
|
return if inside_dynamic_class?(ivar)
|
||||||
return if assignment_only? && !ivar_assigned?(node, name)
|
return if assignment_only? && !ivar_assigned?(node, name)
|
||||||
|
|
||||||
add_offense(ivar, location: :expression)
|
add_offense(ivar)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ module RuboCop
|
|||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
invalid_predicate_matcher?(node) do |predicate|
|
invalid_predicate_matcher?(node) do |predicate|
|
||||||
add_offense(predicate, location: :expression)
|
add_offense(predicate)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ module RuboCop
|
|||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
example_inclusion_offense(node, alternative_style) do
|
example_inclusion_offense(node, alternative_style) do
|
||||||
add_offense(node, location: :expression)
|
add_offense(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ module RuboCop
|
|||||||
def on_block(node)
|
def on_block(node)
|
||||||
each?(node) do |arg, body|
|
each?(node) do |arg, body|
|
||||||
if single_expectation?(body, arg) || only_expectations?(body, arg)
|
if single_expectation?(body, arg) || only_expectations?(body, arg)
|
||||||
add_offense(node.send_node, location: :expression)
|
add_offense(node.send_node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -47,7 +47,6 @@ module RuboCop
|
|||||||
if offending?(sibling)
|
if offending?(sibling)
|
||||||
add_offense(
|
add_offense(
|
||||||
node,
|
node,
|
||||||
location: :expression,
|
|
||||||
message: format(MSG, offending: sibling.method_name)
|
message: format(MSG, offending: sibling.method_name)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -0,0 +1,128 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module RSpec
|
||||||
|
# Checks that no class, module, or constant is declared.
|
||||||
|
#
|
||||||
|
# Constants, including classes and modules, when declared in a block
|
||||||
|
# scope, are defined in global namespace, and leak between examples.
|
||||||
|
#
|
||||||
|
# If several examples may define a `DummyClass`, instead of being a
|
||||||
|
# blank slate class as it will be in the first example, subsequent
|
||||||
|
# examples will be reopening it and modifying its behaviour in
|
||||||
|
# unpredictable ways.
|
||||||
|
# Even worse when a class that exists in the codebase is reopened.
|
||||||
|
#
|
||||||
|
# Anonymous classes are fine, since they don't result in global
|
||||||
|
# namespace name clashes.
|
||||||
|
#
|
||||||
|
# @see https://relishapp.com/rspec/rspec-mocks/docs/mutating-constants
|
||||||
|
#
|
||||||
|
# @example Constants leak between examples
|
||||||
|
# # bad
|
||||||
|
# describe SomeClass do
|
||||||
|
# OtherClass = Struct.new
|
||||||
|
# CONSTANT_HERE = 'I leak into global namespace'
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# describe SomeClass do
|
||||||
|
# before do
|
||||||
|
# stub_const('OtherClass', Struct.new)
|
||||||
|
# stub_const('CONSTANT_HERE', 'I only exist during this example')
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# # bad
|
||||||
|
# describe SomeClass do
|
||||||
|
# class FooClass < described_class
|
||||||
|
# def double_that
|
||||||
|
# some_base_method * 2
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# it { expect(FooClass.new.double_that).to eq(4) }
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good - anonymous class, no constant needs to be defined
|
||||||
|
# let(:foo_class) do
|
||||||
|
# Class.new(described_class) do
|
||||||
|
# def double_that
|
||||||
|
# some_base_method * 2
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# it { expect(foo_class.new.double_that).to eq(4) }
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good - constant is stubbed
|
||||||
|
# describe SomeClass do
|
||||||
|
# before do
|
||||||
|
# foo_class = Class.new(described_class) do
|
||||||
|
# def do_something
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# stub_const('FooClass', foo_class)
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# it { expect(FooClass.new.double_that).to eq(4) }
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# # bad
|
||||||
|
# describe SomeClass do
|
||||||
|
# module SomeModule
|
||||||
|
# class SomeClass
|
||||||
|
# def do_something
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# describe SomeClass do
|
||||||
|
# before do
|
||||||
|
# foo_class = Class.new(described_class) do
|
||||||
|
# def do_something
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# stub_const('SomeModule::SomeClass', foo_class)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
class LeakyConstantDeclaration < Cop
|
||||||
|
MSG_CONST = 'Stub constant instead of declaring explicitly.'
|
||||||
|
MSG_CLASS = 'Stub class constant instead of declaring explicitly.'
|
||||||
|
MSG_MODULE = 'Stub module constant instead of declaring explicitly.'
|
||||||
|
|
||||||
|
def on_casgn(node)
|
||||||
|
return unless inside_describe_block?(node)
|
||||||
|
|
||||||
|
add_offense(node, message: MSG_CONST)
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_class(node)
|
||||||
|
return unless inside_describe_block?(node)
|
||||||
|
|
||||||
|
add_offense(node, message: MSG_CLASS)
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_module(node)
|
||||||
|
return unless inside_describe_block?(node)
|
||||||
|
|
||||||
|
add_offense(node, message: MSG_MODULE)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def inside_describe_block?(node)
|
||||||
|
node.each_ancestor(:block).any?(&method(:in_example_or_shared_group?))
|
||||||
|
end
|
||||||
|
|
||||||
|
def_node_matcher :in_example_or_shared_group?,
|
||||||
|
(ExampleGroups::ALL + SharedGroups::ALL).block_pattern
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -73,7 +73,7 @@ module RuboCop
|
|||||||
node.each_child_node do |child|
|
node.each_child_node do |child|
|
||||||
next if child.sibling_index < first_example.sibling_index
|
next if child.sibling_index < first_example.sibling_index
|
||||||
|
|
||||||
add_offense(child, location: :expression) if let?(child)
|
add_offense(child) if let?(child)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -26,9 +26,7 @@ module RuboCop
|
|||||||
# expect(Widget.count).to eq(1)
|
# expect(Widget.count).to eq(1)
|
||||||
# end
|
# end
|
||||||
class LetSetup < Cop
|
class LetSetup < Cop
|
||||||
include RuboCop::RSpec::TopLevelDescribe
|
MSG = 'Do not use `let!` to setup objects not referenced in tests.'
|
||||||
|
|
||||||
MSG = 'Do not use `let!` for test setup.'
|
|
||||||
|
|
||||||
def_node_search :let_bang, <<-PATTERN
|
def_node_search :let_bang, <<-PATTERN
|
||||||
(block $(send nil? :let! (sym $_)) args ...)
|
(block $(send nil? :let! (sym $_)) args ...)
|
||||||
@ -40,7 +38,7 @@ module RuboCop
|
|||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
|
|
||||||
unused_let_bang(node) do |let|
|
unused_let_bang(node) do |let|
|
||||||
add_offense(let, location: :expression)
|
add_offense(let)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -26,8 +26,7 @@ module RuboCop
|
|||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
return if node.send_node.arguments?
|
return if node.send_node.arguments?
|
||||||
|
|
||||||
add_offense(node, location: :expression,
|
add_offense(node, message: format(MSG, method: node.method_name))
|
||||||
message: format(MSG, method: node.method_name))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -32,7 +32,7 @@ module RuboCop
|
|||||||
return if single_top_level_describe?
|
return if single_top_level_describe?
|
||||||
return unless top_level_nodes.first.equal?(node)
|
return unless top_level_nodes.first.equal?(node)
|
||||||
|
|
||||||
add_offense(node, location: :expression)
|
add_offense(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -50,20 +50,20 @@ module RuboCop
|
|||||||
|
|
||||||
MSG = 'Example has too many expectations [%<total>d/%<max>d].'
|
MSG = 'Example has too many expectations [%<total>d/%<max>d].'
|
||||||
|
|
||||||
def_node_search :with_aggregated_failures?, '(sym :aggregate_failures)'
|
def_node_search :with_aggregate_failures?, '(sym :aggregate_failures)'
|
||||||
def_node_search :disabled_aggregated_failures?, <<-PATTERN
|
def_node_search :disabled_aggregate_failures?, <<-PATTERN
|
||||||
(pair (sym :aggregate_failures) (false))
|
(pair (sym :aggregate_failures) (false))
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def_node_matcher :expect?, Expectations::ALL.send_pattern
|
def_node_matcher :expect?, Expectations::ALL.send_pattern
|
||||||
def_node_matcher :aggregate_failures?, <<-PATTERN
|
def_node_matcher :aggregate_failures_block?, <<-PATTERN
|
||||||
(block (send _ :aggregate_failures ...) ...)
|
(block (send _ :aggregate_failures ...) ...)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example?(node)
|
return unless example?(node)
|
||||||
|
|
||||||
return if example_with_aggregated_failures?(node)
|
return if example_with_aggregate_failures?(node)
|
||||||
|
|
||||||
expectations_count = to_enum(:find_expectation, node).count
|
expectations_count = to_enum(:find_expectation, node).count
|
||||||
|
|
||||||
@ -76,19 +76,40 @@ module RuboCop
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def example_with_aggregated_failures?(node)
|
def example_with_aggregate_failures?(example_node)
|
||||||
example = node.send_node
|
node_with_aggregate_failures = find_aggregate_failures(example_node)
|
||||||
|
return false unless node_with_aggregate_failures
|
||||||
|
|
||||||
(aggregated_failures_by_default? ||
|
aggregate_failures?(node_with_aggregate_failures)
|
||||||
with_aggregated_failures?(example)) &&
|
end
|
||||||
!disabled_aggregated_failures?(example)
|
|
||||||
|
def find_aggregate_failures(example_node)
|
||||||
|
example_node.send_node.each_ancestor(:block)
|
||||||
|
.find { |block_node| aggregate_failures_present?(block_node) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def aggregate_failures_present?(node)
|
||||||
|
metadata(node)&.any?(&method(:with_aggregate_failures?))
|
||||||
|
end
|
||||||
|
|
||||||
|
def aggregate_failures?(example_or_group_node)
|
||||||
|
metadata(example_or_group_node)&.any? do |metadata|
|
||||||
|
with_aggregate_failures?(metadata) &&
|
||||||
|
!disabled_aggregate_failures?(metadata)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def metadata(example_or_group_node)
|
||||||
|
RuboCop::RSpec::Example
|
||||||
|
.new(example_or_group_node)
|
||||||
|
.metadata
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_expectation(node, &block)
|
def find_expectation(node, &block)
|
||||||
yield if expect?(node) || aggregate_failures?(node)
|
yield if expect?(node) || aggregate_failures_block?(node)
|
||||||
|
|
||||||
# do not search inside of aggregate_failures block
|
# do not search inside of aggregate_failures block
|
||||||
return if aggregate_failures?(node)
|
return if aggregate_failures_block?(node)
|
||||||
|
|
||||||
node.each_child_node do |child|
|
node.each_child_node do |child|
|
||||||
find_expectation(child, &block)
|
find_expectation(child, &block)
|
||||||
@ -98,7 +119,6 @@ module RuboCop
|
|||||||
def flag_example(node, expectation_count:)
|
def flag_example(node, expectation_count:)
|
||||||
add_offense(
|
add_offense(
|
||||||
node.send_node,
|
node.send_node,
|
||||||
location: :expression,
|
|
||||||
message: format(
|
message: format(
|
||||||
MSG,
|
MSG,
|
||||||
total: expectation_count,
|
total: expectation_count,
|
||||||
@ -110,10 +130,6 @@ module RuboCop
|
|||||||
def max_expectations
|
def max_expectations
|
||||||
Integer(cop_config.fetch('Max', 1))
|
Integer(cop_config.fetch('Max', 1))
|
||||||
end
|
end
|
||||||
|
|
||||||
def aggregated_failures_by_default?
|
|
||||||
cop_config.fetch('AggregateFailuresByDefault', false)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -44,7 +44,7 @@ module RuboCop
|
|||||||
subjects = RuboCop::RSpec::ExampleGroup.new(node).subjects
|
subjects = RuboCop::RSpec::ExampleGroup.new(node).subjects
|
||||||
|
|
||||||
subjects[0...-1].each do |subject|
|
subjects[0...-1].each do |subject|
|
||||||
add_offense(subject, location: :expression)
|
add_offense(subject)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -104,7 +104,6 @@ module RuboCop
|
|||||||
self.max = nesting
|
self.max = nesting
|
||||||
add_offense(
|
add_offense(
|
||||||
context.send_node,
|
context.send_node,
|
||||||
location: :expression,
|
|
||||||
message: message(nesting)
|
message: message(nesting)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -33,7 +33,6 @@ module RuboCop
|
|||||||
find_duplicates(node.body) do |duplicate, name|
|
find_duplicates(node.body) do |duplicate, name|
|
||||||
add_offense(
|
add_offense(
|
||||||
duplicate,
|
duplicate,
|
||||||
location: :expression,
|
|
||||||
message: format(MSG, name: name)
|
message: format(MSG, name: name)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -46,7 +46,7 @@ module RuboCop
|
|||||||
def on_send(node)
|
def on_send(node)
|
||||||
return unless pending_block?(node) || skipped_from_metadata?(node)
|
return unless pending_block?(node) || skipped_from_metadata?(node)
|
||||||
|
|
||||||
add_offense(node, location: :expression)
|
add_offense(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -17,7 +17,6 @@ module RuboCop
|
|||||||
predicate_in_actual?(node) do |predicate|
|
predicate_in_actual?(node) do |predicate|
|
||||||
add_offense(
|
add_offense(
|
||||||
node,
|
node,
|
||||||
location: :expression,
|
|
||||||
message: message_inflected(predicate)
|
message: message_inflected(predicate)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -143,7 +142,6 @@ module RuboCop
|
|||||||
predicate_matcher_block?(node) do |_actual, matcher|
|
predicate_matcher_block?(node) do |_actual, matcher|
|
||||||
add_offense(
|
add_offense(
|
||||||
node,
|
node,
|
||||||
location: :expression,
|
|
||||||
message: message_explicit(matcher)
|
message: message_explicit(matcher)
|
||||||
)
|
)
|
||||||
ignore_node(node.children.first)
|
ignore_node(node.children.first)
|
||||||
@ -155,7 +153,6 @@ module RuboCop
|
|||||||
predicate_matcher?(node) do |_actual, matcher|
|
predicate_matcher?(node) do |_actual, matcher|
|
||||||
add_offense(
|
add_offense(
|
||||||
node,
|
node,
|
||||||
location: :expression,
|
|
||||||
message: message_explicit(matcher)
|
message: message_explicit(matcher)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -36,7 +36,7 @@ module RuboCop
|
|||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
|
|
||||||
repeated_descriptions(node).each do |repeated_description|
|
repeated_descriptions(node).each do |repeated_description|
|
||||||
add_offense(repeated_description, location: :expression)
|
add_offense(repeated_description)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ module RuboCop
|
|||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
|
|
||||||
repeated_examples(node).each do |repeated_example|
|
repeated_examples(node).each do |repeated_example|
|
||||||
add_offense(repeated_example, location: :expression)
|
add_offense(repeated_example)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ module RuboCop
|
|||||||
lets.each_with_index do |node, idx|
|
lets.each_with_index do |node, idx|
|
||||||
next if node.sibling_index == first_let.sibling_index + idx
|
next if node.sibling_index == first_let.sibling_index + idx
|
||||||
|
|
||||||
add_offense(node, location: :expression)
|
add_offense(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -29,7 +29,7 @@ module RuboCop
|
|||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
|
|
||||||
analyzable_hooks(node).each do |repeated_hook|
|
analyzable_hooks(node).each do |repeated_hook|
|
||||||
add_offense(repeated_hook, location: :expression)
|
add_offense(repeated_hook)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -101,7 +101,6 @@ module RuboCop
|
|||||||
def add_shared_item_offense(node, message)
|
def add_shared_item_offense(node, message)
|
||||||
add_offense(
|
add_offense(
|
||||||
node,
|
node,
|
||||||
location: :expression,
|
|
||||||
message: message
|
message: message
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -75,7 +75,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def key_to_arg(node)
|
def key_to_arg(node)
|
||||||
key, = *node
|
key, = *node # rubocop:disable InternalAffairs/NodeDestructuring
|
||||||
node.sym_type? ? ":#{key}" : node.source
|
node.sym_type? ? ":#{key}" : node.source
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -6,6 +6,8 @@ module RuboCop
|
|||||||
# Checks for stubbed test subjects.
|
# Checks for stubbed test subjects.
|
||||||
#
|
#
|
||||||
# @see https://robots.thoughtbot.com/don-t-stub-the-system-under-test
|
# @see https://robots.thoughtbot.com/don-t-stub-the-system-under-test
|
||||||
|
# @see https://samphippen.com/introducing-rspec-smells-and-where-to-find-them#smell-1-stubject
|
||||||
|
# @see https://github.com/rubocop-hq/rspec-style-guide#dont-stub-subject
|
||||||
#
|
#
|
||||||
# @example
|
# @example
|
||||||
# # bad
|
# # bad
|
||||||
@ -18,9 +20,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class SubjectStub < Cop
|
class SubjectStub < Cop
|
||||||
include RuboCop::RSpec::TopLevelDescribe
|
MSG = 'Do not stub methods of the object under test.'
|
||||||
|
|
||||||
MSG = 'Do not stub your test subject.'
|
|
||||||
|
|
||||||
# @!method subject(node)
|
# @!method subject(node)
|
||||||
# Find a named or unnamed subject definition
|
# Find a named or unnamed subject definition
|
||||||
@ -56,31 +56,28 @@ module RuboCop
|
|||||||
# expect(foo).to receive(:bar).with(1)
|
# expect(foo).to receive(:bar).with(1)
|
||||||
# expect(foo).to receive(:bar).with(1).and_return(2)
|
# expect(foo).to receive(:bar).with(1).and_return(2)
|
||||||
#
|
#
|
||||||
# @example source that not matches
|
|
||||||
# expect(foo).to all(receive(:bar))
|
|
||||||
#
|
|
||||||
def_node_matcher :message_expectation?, <<-PATTERN
|
def_node_matcher :message_expectation?, <<-PATTERN
|
||||||
{
|
(send
|
||||||
(send nil? :allow (send nil? %))
|
{
|
||||||
(send (send nil? :expect (send nil? %)) :to #expectation?)
|
(send nil? { :expect :allow } (send nil? {% :subject}))
|
||||||
}
|
(send nil? :is_expected)
|
||||||
|
}
|
||||||
|
#{Runners::ALL.node_pattern_union}
|
||||||
|
#message_expectation_matcher?
|
||||||
|
)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def_node_matcher :all_matcher?, '(send nil? :all ...)'
|
def_node_search :message_expectation_matcher?, <<-PATTERN
|
||||||
|
(send nil? {
|
||||||
def_node_search :receive_message?, '(send nil? :receive ...)'
|
:receive :receive_messages :receive_message_chain :have_received
|
||||||
|
} ...)
|
||||||
def expectation?(node)
|
PATTERN
|
||||||
return if all_matcher?(node)
|
|
||||||
|
|
||||||
receive_message?(node)
|
|
||||||
end
|
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
|
|
||||||
find_subject_stub(node) do |stub|
|
find_subject_stub(node) do |stub|
|
||||||
add_offense(stub, location: :expression)
|
add_offense(stub)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -45,10 +45,7 @@ module RuboCop
|
|||||||
def on_send(node)
|
def on_send(node)
|
||||||
return unless empty_exception_matcher?(node)
|
return unless empty_exception_matcher?(node)
|
||||||
|
|
||||||
add_offense(
|
add_offense(node.children.last)
|
||||||
node.children.last,
|
|
||||||
location: :expression
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty_exception_matcher?(node)
|
def empty_exception_matcher?(node)
|
||||||
@ -34,7 +34,7 @@ module RuboCop
|
|||||||
return if name.nil? && cop_config['IgnoreNameless']
|
return if name.nil? && cop_config['IgnoreNameless']
|
||||||
return if symbol?(name) && cop_config['IgnoreSymbolicNames']
|
return if symbol?(name) && cop_config['IgnoreSymbolicNames']
|
||||||
|
|
||||||
add_offense(node, location: :expression)
|
add_offense(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ module RuboCop
|
|||||||
def check_expect(node)
|
def check_expect(node)
|
||||||
return unless void?(node)
|
return unless void?(node)
|
||||||
|
|
||||||
add_offense(node, location: :expression)
|
add_offense(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
def void?(expect)
|
def void?(expect)
|
||||||
@ -49,6 +49,7 @@ require_relative 'rspec/invalid_predicate_matcher'
|
|||||||
require_relative 'rspec/it_behaves_like'
|
require_relative 'rspec/it_behaves_like'
|
||||||
require_relative 'rspec/iterated_expectation'
|
require_relative 'rspec/iterated_expectation'
|
||||||
require_relative 'rspec/leading_subject'
|
require_relative 'rspec/leading_subject'
|
||||||
|
require_relative 'rspec/leaky_constant_declaration'
|
||||||
require_relative 'rspec/let_before_examples'
|
require_relative 'rspec/let_before_examples'
|
||||||
require_relative 'rspec/let_setup'
|
require_relative 'rspec/let_setup'
|
||||||
require_relative 'rspec/message_chain'
|
require_relative 'rspec/message_chain'
|
||||||
@ -4,7 +4,7 @@ module RuboCop
|
|||||||
module RSpec
|
module RSpec
|
||||||
# RSpec public API methods that are commonly used in cops
|
# RSpec public API methods that are commonly used in cops
|
||||||
module Language
|
module Language
|
||||||
RSPEC = '{(const nil? :RSpec) nil?}'
|
RSPEC = '{(const {nil? cbase} :RSpec) nil?}'
|
||||||
|
|
||||||
# Set of method selectors
|
# Set of method selectors
|
||||||
class SelectorSet
|
class SelectorSet
|
||||||
@ -6,10 +6,6 @@ module RuboCop
|
|||||||
module TopLevelDescribe
|
module TopLevelDescribe
|
||||||
extend NodePattern::Macros
|
extend NodePattern::Macros
|
||||||
|
|
||||||
def_node_matcher :described_constant, <<-PATTERN
|
|
||||||
(block $(send _ :describe $(const ...)) (args) $_)
|
|
||||||
PATTERN
|
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
return unless respond_to?(:on_top_level_describe)
|
return unless respond_to?(:on_top_level_describe)
|
||||||
return unless top_level_describe?(node)
|
return unless top_level_describe?(node)
|
||||||
@ -4,7 +4,7 @@ module RuboCop
|
|||||||
module RSpec
|
module RSpec
|
||||||
# Version information for the RSpec RuboCop plugin.
|
# Version information for the RSpec RuboCop plugin.
|
||||||
module Version
|
module Version
|
||||||
STRING = '1.33.0'
|
STRING = '1.34.0'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user