brew vendor-gems: commit updates.

This commit is contained in:
Mike McQuaid 2019-07-23 14:52:02 +01:00
parent d517364d9f
commit afb2978995
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
97 changed files with 328 additions and 133 deletions

View File

@ -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/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/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/thor-0.20.3/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}/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/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}/gems/hpricot-0.8.6/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/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-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-mocks-3.8.1/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/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/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-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/simplecov-cobertura-1.3.1/lib"

View File

@ -50,7 +50,7 @@ RSpec/BeforeAfterAll:
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll
RSpec/ContextWording:
Description: "`context` block descriptions should start with 'when', or 'with'."
Description: Checks that `context` docstring starts with an allowed prefix.
Enabled: true
Prefixes:
- when
@ -251,6 +251,11 @@ RSpec/LeadingSubject:
Enabled: true
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:
Description: Checks for `let` definitions that come after an example.
Enabled: true

View File

@ -33,7 +33,6 @@ module RuboCop
disallowed_stub(node) do |method|
add_offense(
node,
location: :expression,
message: format(MSG, method: method)
)
end

View File

@ -51,7 +51,7 @@ module RuboCop
private
def add_no_arg_offense(node)
add_offense(node, location: :expression, message: MSG_NO_ARG)
add_offense(node, message: MSG_NO_ARG)
end
def check_for_unused_proxy(block, proxy)
@ -63,7 +63,6 @@ module RuboCop
add_offense(
proxy,
location: :expression,
message: format(MSG_UNUSED_ARG, arg: name)
)
end

View File

@ -37,7 +37,6 @@ module RuboCop
before_or_after_all(node) do |hook|
add_offense(
node,
location: :expression,
message: format(MSG, hook: hook.source)
)
end

View File

@ -3,18 +3,22 @@
module RuboCop
module Cop
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 http://www.betterspecs.org/#contexts
#
# @example `Prefixes` configuration option, defaults: 'when', 'with', and
# 'without'
# Prefixes:
# - when
# - with
# - without
# - if
# @example `Prefixes` configuration
#
# # .rubocop.yml
# # RSpec/ContextWording:
# # Prefixes:
# # - when
# # - with
# # - without
# # - if
# # - unless
# # - for
#
# @example
# # bad
@ -35,7 +39,8 @@ module RuboCop
def on_block(node)
context_wording(node) do |context|
add_offense(context, message: message)
add_offense(context,
message: format(MSG, prefixes: joined_prefixes))
end
end
@ -45,14 +50,6 @@ module RuboCop
!prefixes.include?(description.split.first)
end
def prefixes
cop_config['Prefixes'] || []
end
def message
format(MSG, prefixes: joined_prefixes)
end
def joined_prefixes
quoted = prefixes.map { |prefix| "'#{prefix}'" }
return quoted.first if quoted.size == 1
@ -60,6 +57,10 @@ module RuboCop
quoted << "or #{quoted.pop}"
quoted.join(', ')
end
def prefixes
cop_config['Prefixes'] || []
end
end
end
end

View File

@ -52,7 +52,7 @@ module RuboCop
return if pairs.any?(&method(:rails_metadata?))
end
add_offense(args.first, location: :expression)
add_offense(args.first)
end
end
end

View File

@ -27,7 +27,7 @@ module RuboCop
return unless second_arg&.str_type?
return if second_arg.str_content.start_with?('#', '.')
add_offense(second_arg, location: :expression)
add_offense(second_arg)
end
end
end

View File

@ -26,7 +26,7 @@ module RuboCop
def on_send(node)
describe_symbol?(node) do |match|
add_offense(match, location: :expression)
add_offense(match)
end
end
end

View File

@ -33,7 +33,6 @@ module RuboCop
# end
#
class DescribedClass < Cop
include RuboCop::RSpec::TopLevelDescribe
include ConfigurableEnforcedStyle
DESCRIBED_CLASS = 'described_class'
@ -48,20 +47,19 @@ module RuboCop
def_node_matcher :scope_changing_syntax?, '{def class module}'
def on_block(node)
# In case the explicit style is used, we needs to remember what's
# being described. Thus, we use an ivar for @described_class.
describe, @described_class, body = described_constant(node)
def_node_matcher :described_constant, <<-PATTERN
(block (send _ :describe $(const ...) ...) (args) $_)
PATTERN
return if body.nil?
return unless top_level_describe?(describe)
def on_block(node)
# 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|
add_offense(
match,
location: :expression,
message: message(match.const_name)
)
add_offense(match, message: message(match.const_name))
end
end
@ -108,16 +106,84 @@ module RuboCop
end
def skip_blocks?
cop_config['SkipBlocks'].equal?(true)
cop_config['SkipBlocks']
end
def offensive?(node)
if style == :described_class
node.eql?(@described_class)
offensive_described_class?(node)
else
node.send_type? && node.method_name == :described_class
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

View File

@ -70,7 +70,7 @@ module RuboCop
def on_block(node)
return unless example_group?(node) && !contains_example?(node)
add_offense(node.send_node, location: :expression)
add_offense(node.send_node)
end
private

View File

@ -24,7 +24,7 @@ module RuboCop
return if last_child?(node)
missing_separating_line(node) do |location|
add_offense(node, location: location, message: MSG)
add_offense(node, location: location)
end
end

View File

@ -37,7 +37,7 @@ module RuboCop
return unless length > max_length
add_offense(node, location: :expression, message: message(length))
add_offense(node, message: message(length))
end
private

View File

@ -36,10 +36,12 @@ module RuboCop
SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
IT_PREFIX = /\Ait /i.freeze
def_node_matcher(
:it_description,
'(block (send _ :it $(str $_) ...) ...)'
)
def_node_matcher :it_description, <<-PATTERN
(block (send _ :it ${
(str $_)
(dstr (str $_ ) ...)
} ...) ...)
PATTERN
def on_block(node)
it_description(node) do |description_node, message|

View File

@ -45,7 +45,7 @@ module RuboCop
def on_send(node)
expect_literal(node) do |argument|
add_offense(argument, location: :expression)
add_offense(argument)
end
end

View File

@ -21,7 +21,9 @@ module RuboCop
def on_gvasgn(node)
return unless inside_example_scope?(node)
# rubocop:disable InternalAffairs/NodeDestructuring
variable_name, _rhs = *node
# rubocop:enable InternalAffairs/NodeDestructuring
name = variable_name[1..-1]
return unless name.eql?('stdout') || name.eql?('stderr')

View File

@ -40,7 +40,7 @@ module RuboCop
next unless offensive_receiver?(attribute.receiver, node)
next if proc?(attribute) || association?(attribute)
add_offense(attribute, location: :expression)
add_offense(attribute)
end
end

View File

@ -51,8 +51,7 @@ module RuboCop
return unless n_times_block_without_arg?(node)
return unless contains_only_factory?(node.body)
add_offense(node.send_node,
location: :expression, message: MSG_CREATE_LIST)
add_offense(node.send_node, message: MSG_CREATE_LIST)
end
def on_send(node)

View File

@ -44,7 +44,7 @@ module RuboCop
def on_send(node)
focus_metadata(node) do |focus|
add_offense(focus, location: :expression)
add_offense(focus)
end
end

View File

@ -80,7 +80,6 @@ module RuboCop
style_detected(scope_name)
add_offense(
method_send,
location: :expression,
message: explicit_message(scope_name)
)
end

View File

@ -43,7 +43,7 @@ module RuboCop
null_double(node) do |var, receiver|
have_received_usage(node) do |expected|
add_offense(receiver, location: :expression) if expected == var
add_offense(receiver) if expected == var
end
end
end

View File

@ -68,7 +68,7 @@ module RuboCop
return if inside_dynamic_class?(ivar)
return if assignment_only? && !ivar_assigned?(node, name)
add_offense(ivar, location: :expression)
add_offense(ivar)
end
end

View File

@ -24,7 +24,7 @@ module RuboCop
def on_send(node)
invalid_predicate_matcher?(node) do |predicate|
add_offense(predicate, location: :expression)
add_offense(predicate)
end
end

View File

@ -28,7 +28,7 @@ module RuboCop
def on_send(node)
example_inclusion_offense(node, alternative_style) do
add_offense(node, location: :expression)
add_offense(node)
end
end

View File

@ -34,7 +34,7 @@ module RuboCop
def on_block(node)
each?(node) do |arg, body|
if single_expectation?(body, arg) || only_expectations?(body, arg)
add_offense(node.send_node, location: :expression)
add_offense(node.send_node)
end
end
end

View File

@ -47,7 +47,6 @@ module RuboCop
if offending?(sibling)
add_offense(
node,
location: :expression,
message: format(MSG, offending: sibling.method_name)
)
end

View File

@ -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

View File

@ -73,7 +73,7 @@ module RuboCop
node.each_child_node do |child|
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

View File

@ -26,9 +26,7 @@ module RuboCop
# expect(Widget.count).to eq(1)
# end
class LetSetup < Cop
include RuboCop::RSpec::TopLevelDescribe
MSG = 'Do not use `let!` for test setup.'
MSG = 'Do not use `let!` to setup objects not referenced in tests.'
def_node_search :let_bang, <<-PATTERN
(block $(send nil? :let! (sym $_)) args ...)
@ -40,7 +38,7 @@ module RuboCop
return unless example_group?(node)
unused_let_bang(node) do |let|
add_offense(let, location: :expression)
add_offense(let)
end
end

View File

@ -26,8 +26,7 @@ module RuboCop
return unless example_group?(node)
return if node.send_node.arguments?
add_offense(node, location: :expression,
message: format(MSG, method: node.method_name))
add_offense(node, message: format(MSG, method: node.method_name))
end
end
end

View File

@ -32,7 +32,7 @@ module RuboCop
return if single_top_level_describe?
return unless top_level_nodes.first.equal?(node)
add_offense(node, location: :expression)
add_offense(node)
end
end
end

View File

@ -50,20 +50,20 @@ module RuboCop
MSG = 'Example has too many expectations [%<total>d/%<max>d].'
def_node_search :with_aggregated_failures?, '(sym :aggregate_failures)'
def_node_search :disabled_aggregated_failures?, <<-PATTERN
def_node_search :with_aggregate_failures?, '(sym :aggregate_failures)'
def_node_search :disabled_aggregate_failures?, <<-PATTERN
(pair (sym :aggregate_failures) (false))
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 ...) ...)
PATTERN
def on_block(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
@ -76,19 +76,40 @@ module RuboCop
private
def example_with_aggregated_failures?(node)
example = node.send_node
def example_with_aggregate_failures?(example_node)
node_with_aggregate_failures = find_aggregate_failures(example_node)
return false unless node_with_aggregate_failures
(aggregated_failures_by_default? ||
with_aggregated_failures?(example)) &&
!disabled_aggregated_failures?(example)
aggregate_failures?(node_with_aggregate_failures)
end
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
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
return if aggregate_failures?(node)
return if aggregate_failures_block?(node)
node.each_child_node do |child|
find_expectation(child, &block)
@ -98,7 +119,6 @@ module RuboCop
def flag_example(node, expectation_count:)
add_offense(
node.send_node,
location: :expression,
message: format(
MSG,
total: expectation_count,
@ -110,10 +130,6 @@ module RuboCop
def max_expectations
Integer(cop_config.fetch('Max', 1))
end
def aggregated_failures_by_default?
cop_config.fetch('AggregateFailuresByDefault', false)
end
end
end
end

View File

@ -44,7 +44,7 @@ module RuboCop
subjects = RuboCop::RSpec::ExampleGroup.new(node).subjects
subjects[0...-1].each do |subject|
add_offense(subject, location: :expression)
add_offense(subject)
end
end

View File

@ -104,7 +104,6 @@ module RuboCop
self.max = nesting
add_offense(
context.send_node,
location: :expression,
message: message(nesting)
)
end

View File

@ -33,7 +33,6 @@ module RuboCop
find_duplicates(node.body) do |duplicate, name|
add_offense(
duplicate,
location: :expression,
message: format(MSG, name: name)
)
end

View File

@ -46,7 +46,7 @@ module RuboCop
def on_send(node)
return unless pending_block?(node) || skipped_from_metadata?(node)
add_offense(node, location: :expression)
add_offense(node)
end
private

View File

@ -17,7 +17,6 @@ module RuboCop
predicate_in_actual?(node) do |predicate|
add_offense(
node,
location: :expression,
message: message_inflected(predicate)
)
end
@ -143,7 +142,6 @@ module RuboCop
predicate_matcher_block?(node) do |_actual, matcher|
add_offense(
node,
location: :expression,
message: message_explicit(matcher)
)
ignore_node(node.children.first)
@ -155,7 +153,6 @@ module RuboCop
predicate_matcher?(node) do |_actual, matcher|
add_offense(
node,
location: :expression,
message: message_explicit(matcher)
)
end

View File

@ -36,7 +36,7 @@ module RuboCop
return unless example_group?(node)
repeated_descriptions(node).each do |repeated_description|
add_offense(repeated_description, location: :expression)
add_offense(repeated_description)
end
end

View File

@ -22,7 +22,7 @@ module RuboCop
return unless example_group?(node)
repeated_examples(node).each do |repeated_example|
add_offense(repeated_example, location: :expression)
add_offense(repeated_example)
end
end

View File

@ -44,7 +44,7 @@ module RuboCop
lets.each_with_index do |node, idx|
next if node.sibling_index == first_let.sibling_index + idx
add_offense(node, location: :expression)
add_offense(node)
end
end
end

View File

@ -29,7 +29,7 @@ module RuboCop
return unless example_group?(node)
analyzable_hooks(node).each do |repeated_hook|
add_offense(repeated_hook, location: :expression)
add_offense(repeated_hook)
end
end

View File

@ -101,7 +101,6 @@ module RuboCop
def add_shared_item_offense(node, message)
add_offense(
node,
location: :expression,
message: message
)
end

View File

@ -75,7 +75,7 @@ module RuboCop
end
def key_to_arg(node)
key, = *node
key, = *node # rubocop:disable InternalAffairs/NodeDestructuring
node.sym_type? ? ":#{key}" : node.source
end

View File

@ -6,6 +6,8 @@ module RuboCop
# Checks for stubbed test subjects.
#
# @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
# # bad
@ -18,9 +20,7 @@ module RuboCop
# end
#
class SubjectStub < Cop
include RuboCop::RSpec::TopLevelDescribe
MSG = 'Do not stub your test subject.'
MSG = 'Do not stub methods of the object under test.'
# @!method subject(node)
# 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).and_return(2)
#
# @example source that not matches
# expect(foo).to all(receive(:bar))
#
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
def_node_matcher :all_matcher?, '(send nil? :all ...)'
def_node_search :receive_message?, '(send nil? :receive ...)'
def expectation?(node)
return if all_matcher?(node)
receive_message?(node)
end
def_node_search :message_expectation_matcher?, <<-PATTERN
(send nil? {
:receive :receive_messages :receive_message_chain :have_received
} ...)
PATTERN
def on_block(node)
return unless example_group?(node)
find_subject_stub(node) do |stub|
add_offense(stub, location: :expression)
add_offense(stub)
end
end

View File

@ -45,10 +45,7 @@ module RuboCop
def on_send(node)
return unless empty_exception_matcher?(node)
add_offense(
node.children.last,
location: :expression
)
add_offense(node.children.last)
end
def empty_exception_matcher?(node)

View File

@ -34,7 +34,7 @@ module RuboCop
return if name.nil? && cop_config['IgnoreNameless']
return if symbol?(name) && cop_config['IgnoreSymbolicNames']
add_offense(node, location: :expression)
add_offense(node)
end
end

View File

@ -40,7 +40,7 @@ module RuboCop
def check_expect(node)
return unless void?(node)
add_offense(node, location: :expression)
add_offense(node)
end
def void?(expect)

View File

@ -49,6 +49,7 @@ require_relative 'rspec/invalid_predicate_matcher'
require_relative 'rspec/it_behaves_like'
require_relative 'rspec/iterated_expectation'
require_relative 'rspec/leading_subject'
require_relative 'rspec/leaky_constant_declaration'
require_relative 'rspec/let_before_examples'
require_relative 'rspec/let_setup'
require_relative 'rspec/message_chain'

View File

@ -4,7 +4,7 @@ module RuboCop
module RSpec
# RSpec public API methods that are commonly used in cops
module Language
RSPEC = '{(const nil? :RSpec) nil?}'
RSPEC = '{(const {nil? cbase} :RSpec) nil?}'
# Set of method selectors
class SelectorSet

View File

@ -6,10 +6,6 @@ module RuboCop
module TopLevelDescribe
extend NodePattern::Macros
def_node_matcher :described_constant, <<-PATTERN
(block $(send _ :describe $(const ...)) (args) $_)
PATTERN
def on_send(node)
return unless respond_to?(:on_top_level_describe)
return unless top_level_describe?(node)

View File

@ -4,7 +4,7 @@ module RuboCop
module RSpec
# Version information for the RSpec RuboCop plugin.
module Version
STRING = '1.33.0'
STRING = '1.34.0'
end
end
end