Merge pull request #6123 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-0.69.0

build: bump rubocop from 0.68.1 to 0.69.0 in /Library/Homebrew
This commit is contained in:
Mike McQuaid 2019-05-13 14:48:20 +01:00 committed by GitHub
commit 1226a82067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
97 changed files with 373 additions and 209 deletions

View File

@ -80,16 +80,16 @@ GEM
rspec-support (3.8.0)
rspec-wait (0.0.9)
rspec (>= 3, < 4)
rubocop (0.68.1)
rubocop (0.69.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
parser (>= 2.6)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.6)
unicode-display_width (>= 1.4.0, < 1.7)
rubocop-performance (1.2.0)
rubocop (>= 0.68.0)
rubocop-rspec (1.32.0)
rubocop-rspec (1.33.0)
rubocop (>= 0.60.0)
ruby-macho (2.2.0)
ruby-progressbar (1.10.0)
@ -110,7 +110,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.6)
unicode-display_width (1.5.0)
unicode-display_width (1.6.0)
webrobots (0.1.2)
PLATFORMS

View File

@ -60,9 +60,9 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-its-1.3.0/lib"
$:.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.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-1.5.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.68.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.69.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.2.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.32.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.33.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

@ -83,6 +83,12 @@ RSpec/DescribedClass:
- explicit
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass
RSpec/Dialect:
Description: This cop enforces custom RSpec dialects.
Enabled: false
PreferredMethods: {}
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Dialect
RSpec/EmptyExampleGroup:
Description: Checks if an example group does not include any tests.
Enabled: true

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'pathname'
require 'yaml'
@ -18,6 +20,7 @@ require_relative 'rubocop/rspec/example'
require_relative 'rubocop/rspec/hook'
require_relative 'rubocop/cop/rspec/cop'
require_relative 'rubocop/rspec/align_let_brace'
require_relative 'rubocop/rspec/factory_bot'
require_relative 'rubocop/rspec/final_end_location'
require_relative 'rubocop/rspec/blank_line_separation'

View File

@ -18,7 +18,7 @@ module RuboCop
# let(:a) { b }
#
class AlignLeftLetBrace < Cop
MSG = 'Align left let brace'.freeze
MSG = 'Align left let brace'
def self.autocorrect_incompatible_with
[Layout::ExtraSpacing]

View File

@ -18,7 +18,7 @@ module RuboCop
# let(:a) { b }
#
class AlignRightLetBrace < Cop
MSG = 'Align right let brace'.freeze
MSG = 'Align right let brace'
def self.autocorrect_incompatible_with
[Layout::ExtraSpacing]

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -21,7 +23,7 @@ module RuboCop
# end
# end
class AnyInstance < Cop
MSG = 'Avoid stubbing using `%<method>s`.'.freeze
MSG = 'Avoid stubbing using `%<method>s`.'
def_node_matcher :disallowed_stub, <<-PATTERN
(send _ ${:any_instance :allow_any_instance_of :expect_any_instance_of} ...)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -24,9 +26,9 @@ module RuboCop
# test.run
# end
class AroundBlock < Cop
MSG_NO_ARG = 'Test object should be passed to around block.'.freeze
MSG_NO_ARG = 'Test object should be passed to around block.'
MSG_UNUSED_ARG = 'You should call `%<arg>s.call` '\
'or `%<arg>s.run`.'.freeze
'or `%<arg>s.run`.'
def_node_matcher :hook, <<-PATTERN
(block {(send nil? :around) (send nil? :around sym)} (args $...) ...)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -18,10 +20,10 @@ module RuboCop
# expect(foo).to be(true)
#
class Be < Cop
MSG = 'Don\'t use `be` without an argument.'.freeze
MSG = 'Don\'t use `be` without an argument.'
def_node_matcher :be_without_args, <<-PATTERN
(send _ {:to :not_to :to_not} $(send nil? :be))
(send _ #{Runners::ALL.node_pattern_union} $(send nil? :be))
PATTERN
def on_send(node)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -34,7 +36,7 @@ module RuboCop
# coerce objects for comparison.
#
class BeEql < Cop
MSG = 'Prefer `be` over `eql`.'.freeze
MSG = 'Prefer `be` over `eql`.'
def_node_matcher :eql_type_with_identity, <<-PATTERN
(send _ :to $(send nil? :eql {true false int float sym nil_type?}))

View File

@ -27,7 +27,7 @@ module RuboCop
MSG = 'Beware of using `%<hook>s` as it may cause state to leak '\
'between tests. If you are using `rspec-rails`, and '\
'`use_transactional_fixtures` is enabled, then records created '\
'in `%<hook>s` are not automatically rolled back.'.freeze
'in `%<hook>s` are not automatically rolled back.'
def_node_matcher :before_or_after_all, <<-PATTERN
$(send _ {:before :after} (sym {:all :context}))

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -24,7 +26,7 @@ module RuboCop
class CurrentPathExpectation < Cop
MSG = 'Do not set an RSpec expectation on `current_path` in ' \
'Capybara feature specs - instead, use the ' \
'`have_current_path` matcher on `page`'.freeze
'`have_current_path` matcher on `page`'
def_node_matcher :expectation_set_on_current_path, <<-PATTERN
(send nil? :expect (send {(send nil? :page) nil?} :current_path))
@ -33,13 +35,13 @@ module RuboCop
# Supported matchers: eq(...) / match(/regexp/) / match('regexp')
def_node_matcher :as_is_matcher, <<-PATTERN
(send
#expectation_set_on_current_path ${:to :not_to :to_not}
#expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
${(send nil? :eq ...) (send nil? :match (regexp ...))})
PATTERN
def_node_matcher :regexp_str_matcher, <<-PATTERN
(send
#expectation_set_on_current_path ${:to :not_to :to_not}
#expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
$(send nil? :match (str $_)))
PATTERN

View File

@ -41,7 +41,7 @@ module RuboCop
# end
# end
class FeatureMethods < Cop
MSG = 'Use `%<replacement>s` instead of `%<method>s`.'.freeze
MSG = 'Use `%<replacement>s` instead of `%<method>s`.'
# https://git.io/v7Kwr
MAP = {
@ -55,13 +55,13 @@ module RuboCop
def_node_matcher :spec?, <<-PATTERN
(block
(send {(const nil? :RSpec) nil?} {:describe :feature} ...)
(send #{RSPEC} {:describe :feature} ...)
...)
PATTERN
def_node_matcher :feature_method, <<-PATTERN
(block
$(send {(const nil? :RSpec) nil?} ${#{MAP.keys.map(&:inspect).join(' ')}} ...)
$(send #{RSPEC} ${#{MAP.keys.map(&:inspect).join(' ')}} ...)
...)
PATTERN

View File

@ -27,10 +27,10 @@ module RuboCop
# # ...
# end
class ContextWording < Cop
MSG = 'Start context description with %<prefixes>s.'.freeze
MSG = 'Start context description with %<prefixes>s.'
def_node_matcher :context_wording, <<-PATTERN
(block (send _ { :context :shared_context } $(str #bad_prefix?)) ...)
(block (send #{RSPEC} { :context :shared_context } $(str #bad_prefix?) ...) ...)
PATTERN
def on_block(node)

View File

@ -20,17 +20,17 @@ module RuboCop
include RuboCop::RSpec::TopLevelDescribe
MSG = 'The first argument to describe should be '\
'the class or module being tested.'.freeze
'the class or module being tested.'
def_node_matcher :valid_describe?, <<-PATTERN
{
(send {(const nil? :RSpec) nil?} :describe const ...)
(send {(const nil? :RSpec) nil?} :describe)
(send #{RSPEC} :describe const ...)
(send #{RSPEC} :describe)
}
PATTERN
def_node_matcher :describe_with_metadata, <<-PATTERN
(send {(const nil? :RSpec) nil?} :describe
(send #{RSPEC} :describe
!const
...
(hash $...))

View File

@ -21,10 +21,10 @@ module RuboCop
include RuboCop::RSpec::Util
MSG = 'The second argument to describe should be the method '\
"being tested. '#instance' or '.class'.".freeze
"being tested. '#instance' or '.class'."
def on_top_level_describe(_node, (_, second_arg))
return unless second_arg && second_arg.str_type?
return unless second_arg&.str_type?
return if second_arg.str_content.start_with?('#', '.')
add_offense(second_arg, location: :expression)

View File

@ -18,10 +18,10 @@ module RuboCop
#
# @see https://github.com/rspec/rspec-core/issues/1610
class DescribeSymbol < Cop
MSG = 'Avoid describing symbols.'.freeze
MSG = 'Avoid describing symbols.'
def_node_matcher :describe_symbol?, <<-PATTERN
(send {(const nil? :RSpec) nil?} :describe $sym ...)
(send #{RSPEC} :describe $sym ...)
PATTERN
def on_send(node)

View File

@ -36,11 +36,11 @@ module RuboCop
include RuboCop::RSpec::TopLevelDescribe
include ConfigurableEnforcedStyle
DESCRIBED_CLASS = 'described_class'.freeze
MSG = 'Use `%<replacement>s` instead of `%<src>s`.'.freeze
DESCRIBED_CLASS = 'described_class'
MSG = 'Use `%<replacement>s` instead of `%<src>s`.'
def_node_matcher :common_instance_exec_closure?, <<-PATTERN
(block (send (const nil? {:Class :Module}) :new ...) ...)
(block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
PATTERN
def_node_matcher :rspec_block?,

View File

@ -0,0 +1,76 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# This cop enforces custom RSpec dialects.
#
# A dialect can be based on the following RSpec methods:
#
# - describe, context, feature, example_group
# - xdescribe, xcontext, xfeature
# - fdescribe, fcontext, ffeature
# - shared_examples, shared_examples_for, shared_context
# - it, specify, example, scenario, its
# - fit, fspecify, fexample, fscenario, focus
# - xit, xspecify, xexample, xscenario, skip
# - pending
# - prepend_before, before, append_before,
# - around
# - prepend_after, after, append_after
# - let, let!
# - subject, subject!
# - expect, is_expected, expect_any_instance_of
#
# By default all of the RSpec methods and aliases are allowed. By setting
# a config like:
#
# RSpec/Dialect:
# PreferredMethods:
# context: describe
#
# You can expect the following behavior:
#
# @example
# # bad
# context 'display name presence' do
# # ...
# end
#
# # good
# describe 'display name presence' do
# # ...
# end
class Dialect < Cop
include MethodPreference
MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
def_node_matcher :rspec_method?, ALL.send_pattern
def on_send(node)
return unless rspec_method?(node)
return unless preferred_methods[node.method_name]
add_offense(node)
end
def autocorrect(node)
lambda do |corrector|
current = node.loc.selector
preferred = preferred_method(current.source)
corrector.replace(current, preferred)
end
end
private
def message(node)
format(MSG, prefer: preferred_method(node.method_name),
current: node.method_name)
end
end
end
end
end

View File

@ -58,7 +58,7 @@ module RuboCop
# end
#
class EmptyExampleGroup < Cop
MSG = 'Empty example group detected.'.freeze
MSG = 'Empty example group detected.'
def_node_search :contains_example?, <<-PATTERN
{

View File

@ -26,7 +26,7 @@ module RuboCop
class EmptyLineAfterExampleGroup < Cop
include RuboCop::RSpec::BlankLineSeparation
MSG = 'Add an empty line after `%<example_group>s`.'.freeze
MSG = 'Add an empty line after `%<example_group>s`.'
def on_block(node)
return unless example_group?(node)

View File

@ -19,7 +19,7 @@ module RuboCop
class EmptyLineAfterFinalLet < Cop
include RuboCop::RSpec::BlankLineSeparation
MSG = 'Add an empty line after the last `let` block.'.freeze
MSG = 'Add an empty line after the last `let` block.'
def on_block(node)
return unless example_group_with_body?(node)

View File

@ -36,7 +36,7 @@ module RuboCop
class EmptyLineAfterHook < Cop
include RuboCop::RSpec::BlankLineSeparation
MSG = 'Add an empty line after `%<hook>s`.'.freeze
MSG = 'Add an empty line after `%<hook>s`.'
def on_block(node)
return unless hook?(node)

View File

@ -17,7 +17,7 @@ module RuboCop
class EmptyLineAfterSubject < Cop
include RuboCop::RSpec::BlankLineSeparation
MSG = 'Add empty line after `subject`.'.freeze
MSG = 'Add empty line after `subject`.'
def on_block(node)
return unless subject?(node) && !in_spec_block?(node)

View File

@ -28,7 +28,7 @@ module RuboCop
class ExampleLength < Cop
include CodeLength
MSG = 'Example has too many lines [%<total>d/%<max>d].'.freeze
MSG = 'Example has too many lines [%<total>d/%<max>d].'
def on_block(node)
return unless example?(node)

View File

@ -51,8 +51,8 @@ module RuboCop
include ConfigurableEnforcedStyle
MSG_DEFAULT_ARGUMENT = 'Omit the argument when you want to ' \
'have auto-generated description.'.freeze
MSG_ADD_DESCRIPTION = 'Add a description.'.freeze
'have auto-generated description.'
MSG_ADD_DESCRIPTION = 'Add a description.'
def_node_matcher :example_description, '(send nil? _ $(str $_))'

View File

@ -30,8 +30,8 @@ module RuboCop
# it 'does things' do
# end
class ExampleWording < Cop
MSG_SHOULD = 'Do not use should when describing your tests.'.freeze
MSG_IT = "Do not repeat 'it' when describing your tests.".freeze
MSG_SHOULD = 'Do not use should when describing your tests.'
MSG_IT = "Do not repeat 'it' when describing your tests."
SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
IT_PREFIX = /\Ait /i.freeze

View File

@ -17,7 +17,7 @@ module RuboCop
# expect(name).to eq("John")
#
class ExpectActual < Cop
MSG = 'Provide the actual you are testing to `expect(...)`.'.freeze
MSG = 'Provide the actual you are testing to `expect(...)`.'
SIMPLE_LITERALS = %i[
true

View File

@ -32,8 +32,8 @@ module RuboCop
class ExpectChange < Cop
include ConfigurableEnforcedStyle
MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'.freeze
MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'.freeze
MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'
MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'
def_node_matcher :expect_change_with_arguments, <<-PATTERN
(send nil? :change ({const send} nil? $_) (sym $_))

View File

@ -21,7 +21,7 @@ module RuboCop
# expect(something).to eq 'foo'
# end
class ExpectInHook < Cop
MSG = 'Do not use `%<expect>s` in `%<hook>s` hook'.freeze
MSG = 'Do not use `%<expect>s` in `%<hook>s` hook'
def_node_search :expectation, Expectations::ALL.send_pattern

View File

@ -16,7 +16,7 @@ module RuboCop
# expect { my_app.print_report }.to output('Hello World').to_stdout
class ExpectOutput < Cop
MSG = 'Use `expect { ... }.to output(...).to_%<name>s` '\
'instead of mutating $%<name>s.'.freeze
'instead of mutating $%<name>s.'
def on_gvasgn(node)
return unless inside_example_scope?(node)

View File

@ -25,53 +25,19 @@ module RuboCop
# # good
# count { 1 }
class AttributeDefinedStatically < Cop
MSG = 'Use a block to declare attribute values.'.freeze
ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze
UNPROXIED_METHODS = %i[
__send__
__id__
nil?
send
object_id
extend
instance_eval
initialize
block_given?
raise
caller
method
].freeze
DEFINITION_PROXY_METHODS = %i[
add_attribute
after
association
before
callback
ignore
initialize_with
sequence
skip_create
to_create
].freeze
RESERVED_METHODS =
DEFINITION_PROXY_METHODS +
UNPROXIED_METHODS +
ATTRIBUTE_DEFINING_METHODS
MSG = 'Use a block to declare attribute values.'
def_node_matcher :value_matcher, <<-PATTERN
(send {self nil?} !#reserved_method? $...)
(send _ !#reserved_method? $...)
PATTERN
def_node_search :factory_attributes, <<-PATTERN
(block (send nil? #attribute_defining_method? ...) _ { (begin $...) $(send ...) } )
(block (send _ #attribute_defining_method? ...) _ { (begin $...) $(send ...) } )
PATTERN
def on_block(node)
factory_attributes(node).to_a.flatten.each do |attribute|
next unless offensive_receiver?(attribute.receiver, node)
next if proc?(attribute) || association?(attribute)
add_offense(attribute, location: :expression)
@ -88,6 +54,20 @@ module RuboCop
private
def offensive_receiver?(receiver, node)
receiver.nil? ||
receiver.self_type? ||
receiver_matches_first_block_argument?(receiver, node)
end
def receiver_matches_first_block_argument?(receiver, node)
first_block_argument = node.arguments.first
!first_block_argument.nil? &&
receiver.lvar_type? &&
receiver.node_parts == first_block_argument.node_parts
end
def proc?(attribute)
value_matcher(attribute).to_a.all?(&:block_pass_type?)
end
@ -134,11 +114,12 @@ module RuboCop
end
def reserved_method?(method_name)
RESERVED_METHODS.include?(method_name)
RuboCop::RSpec::FactoryBot.reserved_methods.include?(method_name)
end
def attribute_defining_method?(method_name)
ATTRIBUTE_DEFINING_METHODS.include?(method_name)
RuboCop::RSpec::FactoryBot.attribute_defining_methods
.include?(method_name)
end
end
end

View File

@ -27,8 +27,8 @@ module RuboCop
class CreateList < Cop
include ConfigurableEnforcedStyle
MSG_CREATE_LIST = 'Prefer create_list.'.freeze
MSG_N_TIMES = 'Prefer %<number>s.times.'.freeze
MSG_CREATE_LIST = 'Prefer create_list.'
MSG_N_TIMES = 'Prefer %<number>s.times.'
def_node_matcher :n_times_block_without_arg?, <<-PATTERN
(block

View File

@ -44,7 +44,7 @@ module RuboCop
class FilePath < Cop
include RuboCop::RSpec::TopLevelDescribe
MSG = 'Spec path should end with `%<suffix>s`.'.freeze
MSG = 'Spec path should end with `%<suffix>s`.'
def_node_search :const_described?, '(send _ :describe (const ...) ...)'
def_node_search :routing_metadata?, '(pair (sym :type) (sym :routing))'
@ -75,7 +75,7 @@ module RuboCop
end
def name_glob(name)
return unless name && name.str_type?
return unless name&.str_type?
"*#{name.str_content.gsub(/\W/, '')}" unless ignore_methods?
end

View File

@ -20,7 +20,7 @@ module RuboCop
# describe MyClass do
# end
class Focus < Cop
MSG = 'Focused spec found.'.freeze
MSG = 'Focused spec found.'
focusable =
ExampleGroups::GROUPS +
@ -36,8 +36,8 @@ module RuboCop
FOCUS_TRUE = s(:pair, FOCUS_SYMBOL, s(:true))
def_node_matcher :metadata, <<-PATTERN
{(send {(const nil? :RSpec) nil?} #{FOCUSABLE_SELECTORS} ... (hash $...))
(send {(const nil? :RSpec) nil?} #{FOCUSABLE_SELECTORS} $...)}
{(send #{RSPEC} #{FOCUSABLE_SELECTORS} ... (hash $...))
(send #{RSPEC} #{FOCUSABLE_SELECTORS} $...)}
PATTERN
def_node_matcher :focused_block?, focused.send_pattern

View File

@ -59,11 +59,10 @@ module RuboCop
# end
class HookArgument < Cop
include ConfigurableEnforcedStyle
include RangeHelp
IMPLICIT_MSG = 'Omit the default `%<scope>p` ' \
'argument for RSpec hooks.'.freeze
EXPLICIT_MSG = 'Use `%<scope>p` for RSpec hooks.'.freeze
'argument for RSpec hooks.'
EXPLICIT_MSG = 'Use `%<scope>p` for RSpec hooks.'
HOOKS = Hooks::ALL.node_pattern_union.freeze
@ -125,9 +124,8 @@ module RuboCop
end
def argument_range(send_node)
range_between(
send_node.loc.selector.end_pos,
send_node.loc.expression.end_pos
send_node.loc.selector.end.with(
end_pos: send_node.loc.expression.end_pos
)
end
end

View File

@ -27,7 +27,7 @@ module RuboCop
include RangeHelp
include RuboCop::RSpec::FinalEndLocation
MSG = 'Move `%<hook>s` above the examples in the group.'.freeze
MSG = 'Move `%<hook>s` above the examples in the group.'
def_node_matcher :example_or_group?, <<-PATTERN
{
@ -88,10 +88,7 @@ module RuboCop
end
def node_range(node)
range_between(
node.loc.expression.begin_pos,
final_end_location(node).end_pos
)
node.loc.expression.with(end_pos: final_end_location(node).end_pos)
end
end
end

View File

@ -27,12 +27,12 @@ module RuboCop
class ImplicitExpect < Cop
include ConfigurableEnforcedStyle
MSG = 'Prefer `%<good>s` over `%<bad>s`.'.freeze
MSG = 'Prefer `%<good>s` over `%<bad>s`.'
def_node_matcher :implicit_expect, <<-PATTERN
{
(send nil? ${:should :should_not} ...)
(send (send nil? $:is_expected) {:to :to_not :not_to} ...)
(send (send nil? $:is_expected) #{Runners::ALL.node_pattern_union} ...)
}
PATTERN

View File

@ -29,7 +29,7 @@ module RuboCop
class ImplicitSubject < Cop
include ConfigurableEnforcedStyle
MSG = "Don't use implicit subject.".freeze
MSG = "Don't use implicit subject."
def_node_matcher :implicit_subject?, <<-PATTERN
(send nil? {:should :should_not :is_expected} ...)

View File

@ -20,7 +20,7 @@ module RuboCop
#
class InstanceSpy < Cop
MSG = 'Use `instance_spy` when you check your double '\
'with `have_received`.'.freeze
'with `have_received`.'
def_node_search :null_double, <<-PATTERN
(lvasgn $_

View File

@ -47,7 +47,7 @@ module RuboCop
# end
#
class InstanceVariable < Cop
MSG = 'Replace instance variable with local variable or `let`.'.freeze
MSG = 'Replace instance variable with local variable or `let`.'
EXAMPLE_GROUP_METHODS = ExampleGroups::ALL + SharedGroups::ALL

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -14,10 +16,10 @@ module RuboCop
# # good
# expect(foo).to be_something
class InvalidPredicateMatcher < Cop
MSG = 'Omit `?` from `%<matcher>s`.'.freeze
MSG = 'Omit `?` from `%<matcher>s`.'
def_node_matcher :invalid_predicate_matcher?, <<-PATTERN
(send (send nil? :expect ...) {:to :not_to :to_not} $(send nil? #predicate?))
(send (send nil? :expect ...) #{Runners::ALL.node_pattern_union} $(send nil? #predicate?))
PATTERN
def on_send(node)

View File

@ -22,7 +22,7 @@ module RuboCop
include ConfigurableEnforcedStyle
MSG = 'Prefer `%<replacement>s` over `%<original>s` when including '\
'examples in a nested context.'.freeze
'examples in a nested context.'
def_node_matcher :example_inclusion_offense, '(send _ % ...)'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -15,7 +17,7 @@ module RuboCop
# end
class IteratedExpectation < Cop
MSG = 'Prefer using the `all` matcher instead ' \
'of iterating over an array.'.freeze
'of iterating over an array.'
def_node_matcher :each?, <<-PATTERN
(block

View File

@ -34,8 +34,7 @@ module RuboCop
class LeadingSubject < Cop
include RangeHelp
MSG = 'Declare `subject` above any other `%<offending>s` ' \
'declarations.'.freeze
MSG = 'Declare `subject` above any other `%<offending>s` declarations.'
def on_block(node)
return unless subject?(node) && !in_spec_block?(node)

View File

@ -34,7 +34,7 @@ module RuboCop
include RangeHelp
include RuboCop::RSpec::FinalEndLocation
MSG = 'Move `let` before the examples in the group.'.freeze
MSG = 'Move `let` before the examples in the group.'
def_node_matcher :example_or_group?, <<-PATTERN
{
@ -91,10 +91,7 @@ module RuboCop
end
def node_range(node)
range_between(
node.loc.expression.begin_pos,
final_end_location(node).end_pos
)
node.loc.expression.with(end_pos: final_end_location(node).end_pos)
end
end
end

View File

@ -28,7 +28,7 @@ module RuboCop
class LetSetup < Cop
include RuboCop::RSpec::TopLevelDescribe
MSG = 'Do not use `let!` for test setup.'.freeze
MSG = 'Do not use `let!` for test setup.'
def_node_search :let_bang, <<-PATTERN
(block $(send nil? :let! (sym $_)) args ...)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -12,7 +14,7 @@ module RuboCop
# allow(foo).to receive(bar: thing)
#
class MessageChain < Cop
MSG = 'Avoid stubbing using `%<method>s`.'.freeze
MSG = 'Avoid stubbing using `%<method>s`.'
def_node_matcher :message_chain, <<-PATTERN
(send _ {:receive_message_chain :stub_chain} ...)

View File

@ -27,7 +27,7 @@ module RuboCop
class MessageExpectation < Cop
include ConfigurableEnforcedStyle
MSG = 'Prefer `%<style>s` for setting message expectations.'.freeze
MSG = 'Prefer `%<style>s` for setting message expectations.'
SUPPORTED_STYLES = %w[allow expect].freeze

View File

@ -27,17 +27,16 @@ module RuboCop
class MessageSpies < Cop
include ConfigurableEnforcedStyle
MSG_RECEIVE = 'Prefer `receive` for setting message '\
'expectations.'.freeze
MSG_RECEIVE = 'Prefer `receive` for setting message expectations.'
MSG_HAVE_RECEIVED = 'Prefer `have_received` for setting message '\
'expectations. Setup `%<source>s` as a spy using '\
'`allow` or `instance_spy`.'.freeze
'`allow` or `instance_spy`.'
SUPPORTED_STYLES = %w[have_received receive].freeze
def_node_matcher :message_expectation, %(
(send (send nil? :expect $_) {:to :to_not :not_to} ...)
(send (send nil? :expect $_) #{Runners::ALL.node_pattern_union} ...)
)
def_node_search :receive_message, %(

View File

@ -20,7 +20,7 @@ module RuboCop
# describe "A feature example" do
# end
class MissingExampleGroupArgument < Cop
MSG = 'The first argument to `%<method>s` should not be empty.'.freeze
MSG = 'The first argument to `%<method>s` should not be empty.'
def on_block(node)
return unless example_group?(node)

View File

@ -26,7 +26,7 @@ module RuboCop
include RuboCop::RSpec::TopLevelDescribe
MSG = 'Do not use multiple top level describes - '\
'try to nest them.'.freeze
'try to nest them.'
def on_top_level_describe(node, _args)
return if single_top_level_describe?

View File

@ -48,7 +48,7 @@ module RuboCop
class MultipleExpectations < Cop
include ConfigurableMax
MSG = 'Example has too many expectations [%<total>d/%<max>d].'.freeze
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

View File

@ -34,7 +34,9 @@ module RuboCop
# This is enough of an edge case that people can just move this to
# a `before` hook on their own
class MultipleSubjects < Cop
MSG = 'Do not set more than one subject per example group'.freeze
include RangeHelp
MSG = 'Do not set more than one subject per example group'
def on_block(node)
return unless example_group?(node)
@ -70,7 +72,9 @@ module RuboCop
def remove_autocorrect(node)
lambda do |corrector|
corrector.remove(node.loc.expression)
range = range_by_whole_lines(node.source_range,
include_final_newline: true)
corrector.remove(range)
end
end
end

View File

@ -43,7 +43,7 @@ module RuboCop
# end
class NamedSubject < Cop
MSG = 'Name your test subject if you need '\
'to reference it explicitly.'.freeze
'to reference it explicitly.'
def_node_matcher :rspec_block?, <<-PATTERN
{

View File

@ -89,14 +89,13 @@ module RuboCop
include ConfigurableMax
include RuboCop::RSpec::TopLevelDescribe
MSG = 'Maximum example group nesting exceeded ' \
'[%<total>d/%<max>d].'.freeze
MSG = 'Maximum example group nesting exceeded [%<total>d/%<max>d].'
DEPRECATED_MAX_KEY = 'MaxNesting'.freeze
DEPRECATED_MAX_KEY = 'MaxNesting'
DEPRECATION_WARNING =
"Configuration key `#{DEPRECATED_MAX_KEY}` for #{cop_name} is " \
'deprecated in favor of `Max`. Please use that instead.'.freeze
'deprecated in favor of `Max`. Please use that instead.'
def_node_search :find_contexts, ExampleGroups::ALL.block_pattern

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -16,7 +18,7 @@ module RuboCop
class NotToNot < Cop
include ConfigurableEnforcedStyle
MSG = 'Prefer `%<replacement>s` over `%<original>s`.'.freeze
MSG = 'Prefer `%<replacement>s` over `%<original>s`.'
def_node_matcher :not_to_not_offense, '(send _ % ...)'

View File

@ -22,7 +22,7 @@ module RuboCop
# let(:baz) { baz }
# let!(:other) { other }
class OverwritingSetup < Cop
MSG = '`%<name>s` is already defined.'.freeze
MSG = '`%<name>s` is already defined.'
def_node_matcher :setup?, (Helpers::ALL + Subject::ALL).block_pattern
def_node_matcher :first_argument_name, '(send _ _ ({str sym} $_))'

View File

@ -26,7 +26,7 @@ module RuboCop
# describe MyClass do
# end
class Pending < Cop
MSG = 'Pending spec found.'.freeze
MSG = 'Pending spec found.'
PENDING_EXAMPLES = Examples::PENDING + Examples::SKIPPED \
+ ExampleGroups::SKIPPED
@ -37,8 +37,8 @@ module RuboCop
PENDING_SYMBOL = s(:sym, :pending)
def_node_matcher :metadata, <<-PATTERN
{(send {(const nil? :RSpec) nil?} #{SKIPPABLE_SELECTORS} ... (hash $...))
(send {(const nil? :RSpec) nil?} #{SKIPPABLE_SELECTORS} $...)}
{(send #{RSPEC} #{SKIPPABLE_SELECTORS} ... (hash $...))
(send #{RSPEC} #{SKIPPABLE_SELECTORS} $...)}
PATTERN
def_node_matcher :pending_block?, PENDING_EXAMPLES.send_pattern

View File

@ -1,12 +1,15 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# A helper for `inflected` style
module InflectedHelper
include RuboCop::RSpec::Language
extend NodePattern::Macros
MSG_INFLECTED = 'Prefer using `%<matcher_name>s` matcher over ' \
'`%<predicate_name>s`.'.freeze
'`%<predicate_name>s`.'
private
@ -25,7 +28,7 @@ module RuboCop
(send nil? :expect {
(block $(send !nil? #predicate? ...) ...)
$(send !nil? #predicate? ...)})
${:to :not_to :to_not}
$#{Runners::ALL.node_pattern_union}
$#boolean_matcher?)
PATTERN
@ -86,10 +89,10 @@ module RuboCop
end
def remove_predicate(corrector, predicate)
range = range_between(
predicate.loc.dot.begin_pos,
predicate.loc.expression.end_pos
range = predicate.loc.dot.with(
end_pos: predicate.loc.expression.end_pos
)
corrector.remove(range)
block_range = block_loc(predicate)
@ -123,10 +126,11 @@ module RuboCop
# A helper for `explicit` style
# rubocop:disable Metrics/ModuleLength
module ExplicitHelper
include RuboCop::RSpec::Language
extend NodePattern::Macros
MSG_EXPLICIT = 'Prefer using `%<predicate_name>s` over ' \
'`%<matcher_name>s` matcher.'.freeze
'`%<matcher_name>s` matcher.'
BUILT_IN_MATCHERS = %w[
be_truthy be_falsey be_falsy
have_attributes have_received
@ -160,7 +164,7 @@ module RuboCop
def_node_matcher :predicate_matcher?, <<-PATTERN
(send
(send nil? :expect $!nil?)
{:to :not_to :to_not}
#{Runners::ALL.node_pattern_union}
{$(send nil? #predicate_matcher_name? ...)
(block $(send nil? #predicate_matcher_name? ...) ...)})
PATTERN
@ -169,7 +173,7 @@ module RuboCop
(block
(send
(send nil? :expect $!nil?)
{:to :not_to :to_not}
#{Runners::ALL.node_pattern_union}
$(send nil? #predicate_matcher_name?))
...)
PATTERN
@ -299,7 +303,6 @@ module RuboCop
include ConfigurableEnforcedStyle
include InflectedHelper
include ExplicitHelper
include RangeHelp
def on_send(node)
case style
@ -330,8 +333,9 @@ module RuboCop
# foo 1, 2
# ^^^^^
def args_loc(send_node)
range_between(send_node.loc.selector.end_pos,
send_node.loc.expression.end_pos)
send_node.loc.selector.end.with(
end_pos: send_node.loc.expression.end_pos
)
end
# returns block location with whitespace
@ -342,9 +346,8 @@ module RuboCop
parent = send_node.parent
return unless parent.block_type?
range_between(
send_node.loc.expression.end_pos,
parent.loc.expression.end_pos
send_node.loc.expression.end.with(
end_pos: parent.loc.expression.end_pos
)
end
end

View File

@ -67,7 +67,7 @@ module RuboCop
# :nodoc:
class SymbolicStyleChecker
MSG = 'Prefer `%<prefer>s` over `%<current>s` ' \
'to describe HTTP status code.'.freeze
'to describe HTTP status code.'
attr_reader :node
def initialize(node)
@ -105,7 +105,7 @@ module RuboCop
# :nodoc:
class NumericStyleChecker
MSG = 'Prefer `%<prefer>s` over `%<current>s` ' \
'to describe HTTP status code.'.freeze
'to describe HTTP status code.'
WHITELIST_STATUS = %i[error success missing redirect].freeze

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -22,9 +24,7 @@ module RuboCop
# expect(foo).to receive(:bar).at_most(:twice).times
#
class ReceiveCounts < Cop
include RangeHelp
MSG = 'Use `%<alternative>s` instead of `%<original>s`.'.freeze
MSG = 'Use `%<alternative>s` instead of `%<original>s`.'
def_node_matcher :receive_counts, <<-PATTERN
(send $(send _ {:exactly :at_least :at_most} (int {1 2})) :times)
@ -78,9 +78,8 @@ module RuboCop
end
def range(node, offending_node)
range_between(
offending_node.loc.dot.begin_pos,
node.loc.expression.end_pos
offending_node.loc.dot.with(
end_pos: node.loc.expression.end_pos
)
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -12,9 +14,7 @@ module RuboCop
# expect(foo).not_to receive(:bar)
#
class ReceiveNever < Cop
include RangeHelp
MSG = 'Use `not_to receive` instead of `never`.'.freeze
MSG = 'Use `not_to receive` instead of `never`.'
def_node_search :method_on_stub?, '(send nil? :receive ...)'
@ -30,10 +30,7 @@ module RuboCop
def autocorrect(node)
lambda do |corrector|
corrector.replace(node.parent.loc.selector, 'not_to')
range = range_between(
node.loc.dot.begin_pos,
node.loc.selector.end_pos
)
range = node.loc.dot.with(end_pos: node.loc.selector.end_pos)
corrector.remove(range)
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -28,7 +30,7 @@ module RuboCop
# end
#
class RepeatedDescription < Cop
MSG = "Don't repeat descriptions within an example group.".freeze
MSG = "Don't repeat descriptions within an example group."
def on_block(node)
return unless example_group?(node)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -14,7 +16,7 @@ module RuboCop
# end
#
class RepeatedExample < Cop
MSG = "Don't repeat examples within an example group.".freeze
MSG = "Don't repeat examples within an example group."
def on_block(node)
return unless example_group?(node)

View File

@ -36,8 +36,8 @@ module RuboCop
class ReturnFromStub < Cop
include ConfigurableEnforcedStyle
MSG_AND_RETURN = 'Use `and_return` for static values.'.freeze
MSG_BLOCK = 'Use block for static values.'.freeze
MSG_AND_RETURN = 'Use `and_return` for static values.'
MSG_BLOCK = 'Use block for static values.'
def_node_search :contains_stub?, '(send nil? :receive (...))'
def_node_search :and_return_value, <<-PATTERN

View File

@ -27,7 +27,7 @@ module RuboCop
# end
#
class ScatteredLet < Cop
MSG = 'Group all let/let! blocks in the example group together.'.freeze
MSG = 'Group all let/let! blocks in the example group together.'
def on_block(node)
return unless example_group_with_body?(node)

View File

@ -23,7 +23,7 @@ module RuboCop
# end
#
class ScatteredSetup < Cop
MSG = 'Do not define multiple hooks in the same example group.'.freeze
MSG = 'Do not define multiple hooks in the same example group.'
def on_block(node)
return unless example_group?(node)

View File

@ -52,10 +52,10 @@ module RuboCop
#
class SharedContext < Cop
MSG_EXAMPLES = "Use `shared_examples` when you don't "\
'define context.'.freeze
'define context.'
MSG_CONTEXT = "Use `shared_context` when you don't "\
'define examples.'.freeze
'define examples.'
examples = (Examples::ALL + Includes::EXAMPLES)
def_node_search :examples?, examples.send_pattern

View File

@ -21,14 +21,14 @@ module RuboCop
# include_examples 'foo bar baz'
#
class SharedExamples < Cop
def_node_matcher :shared_examples, <<-PATTERN
(send
{(const nil? :RSpec) nil?}
{#{(SharedGroups::ALL + Includes::ALL).node_pattern}} $sym ...)
PATTERN
def_node_matcher :shared_examples,
(SharedGroups::ALL + Includes::ALL).send_pattern
def on_send(node)
shared_examples(node) do |ast_node|
shared_examples(node) do
ast_node = node.first_argument
next unless ast_node&.sym_type?
checker = Checker.new(ast_node)
add_offense(checker.node, message: checker.message)
end
@ -44,7 +44,7 @@ module RuboCop
# :nodoc:
class Checker
MSG = 'Prefer %<prefer>s over `%<current>s` ' \
'to titleize shared examples.'.freeze
'to titleize shared examples.'
attr_reader :node
def initialize(node)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -16,7 +18,7 @@ module RuboCop
#
class SingleArgumentMessageChain < Cop
MSG = 'Use `%<recommended>s` instead of calling '\
'`%<called>s` with a single argument.'.freeze
'`%<called>s` with a single argument.'
def_node_matcher :message_chain, <<-PATTERN
(send _ {:receive_message_chain :stub_chain} $_)

View File

@ -20,7 +20,7 @@ module RuboCop
class SubjectStub < Cop
include RuboCop::RSpec::TopLevelDescribe
MSG = 'Do not stub your test subject.'.freeze
MSG = 'Do not stub your test subject.'
# @!method subject(node)
# Find a named or unnamed subject definition

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@ -29,9 +31,9 @@ module RuboCop
#
# expect { do_something }.not_to raise_error
class UnspecifiedException < Cop
MSG = 'Specify the exception being captured'.freeze
MSG = 'Specify the exception being captured'
def_node_matcher :empty_raise_error_or_exception, <<-PATTERN.freeze
def_node_matcher :empty_raise_error_or_exception, <<-PATTERN
(send
(block
(send nil? :expect) ...)
@ -54,7 +56,7 @@ module RuboCop
end
def block_with_args?(node)
return unless node && node.block_type?
return unless node&.block_type?
node.arguments?
end

View File

@ -23,7 +23,7 @@ module RuboCop
# instance_double("ClassName", method_name: 'returned value')
# end
class VerifiedDoubles < Cop
MSG = 'Prefer using verifying doubles over normal doubles.'.freeze
MSG = 'Prefer using verifying doubles over normal doubles.'
def_node_matcher :unverified_double, <<-PATTERN
{(send nil? {:double :spy} $...)}
@ -41,7 +41,7 @@ module RuboCop
private
def symbol?(name)
name && name.sym_type?
name&.sym_type?
end
end
end

View File

@ -13,7 +13,7 @@ module RuboCop
# expect(something).to be(1)
class VoidExpect < Cop
MSG = 'Do not use `expect()` without `.to` or `.not_to`. ' \
'Chain the methods or remove it.'.freeze
'Chain the methods or remove it.'
def_node_matcher :expect?, <<-PATTERN
(send nil? :expect ...)

View File

@ -14,7 +14,7 @@ module RuboCop
class Yield < Cop
include RangeHelp
MSG = 'Use `.and_yield`.'.freeze
MSG = 'Use `.and_yield`.'
def_node_search :method_on_stub?, '(send nil? :receive ...)'
@ -52,9 +52,7 @@ module RuboCop
end
def block_range(node)
block_start = node.loc.begin.begin_pos
block_end = node.loc.end.end_pos
range_between(block_start, block_end)
node.loc.begin.with(end_pos: node.loc.end.end_pos)
end
def generate_replacement(node)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative 'rspec/capybara/current_path_expectation'
require_relative 'rspec/capybara/feature_methods'
@ -22,6 +24,7 @@ require_relative 'rspec/describe_class'
require_relative 'rspec/describe_method'
require_relative 'rspec/describe_symbol'
require_relative 'rspec/described_class'
require_relative 'rspec/dialect'
require_relative 'rspec/empty_example_group'
require_relative 'rspec/empty_line_after_example_group'
require_relative 'rspec/empty_line_after_final_let'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
# RuboCop RSpec project namespace
module RSpec

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module RSpec
# Helps determine the offending location if there is not a blank line
@ -26,7 +28,7 @@ module RuboCop
end
def last_child?(node)
return true unless node.parent && node.parent.begin_type?
return true unless node.parent&.begin_type?
node.equal?(node.parent.children.last)
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'yaml'
module RuboCop
@ -5,7 +7,7 @@ module RuboCop
# Builds a YAML config file from two config hashes
class ConfigFormatter
NAMESPACES = /^(RSpec|Capybara|FactoryBot|Rails)/.freeze
STYLE_GUIDE_BASE_URL = 'http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'.freeze
STYLE_GUIDE_BASE_URL = 'http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'
def initialize(config, descriptions)
@config = config

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module RSpec
# Extracts cop descriptions from YARD docstrings
@ -20,7 +22,7 @@ module RuboCop
# Decorator of a YARD code object for working with documented rspec cops
class CodeObject
COP_CLASS_NAMES = %w[RuboCop::Cop RuboCop::Cop::RSpec::Cop].freeze
RSPEC_NAMESPACE = 'RuboCop::Cop::RSpec'.freeze
RSPEC_NAMESPACE = 'RuboCop::Cop::RSpec'
def initialize(yardoc)
@yardoc = yardoc

View File

@ -0,0 +1,58 @@
# frozen_string_literal: true
module RuboCop
module RSpec
# RuboCop FactoryBot project namespace
module FactoryBot
ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze
UNPROXIED_METHODS = %i[
__send__
__id__
nil?
send
object_id
extend
instance_eval
initialize
block_given?
raise
caller
method
].freeze
DEFINITION_PROXY_METHODS = %i[
add_attribute
after
association
before
callback
ignore
initialize_with
sequence
skip_create
to_create
].freeze
RESERVED_METHODS =
DEFINITION_PROXY_METHODS +
UNPROXIED_METHODS +
ATTRIBUTE_DEFINING_METHODS
private_constant(
:ATTRIBUTE_DEFINING_METHODS,
:UNPROXIED_METHODS,
:DEFINITION_PROXY_METHODS,
:RESERVED_METHODS
)
def self.attribute_defining_methods
ATTRIBUTE_DEFINING_METHODS
end
def self.reserved_methods
RESERVED_METHODS
end
end
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module RSpec
# Helps find the true end location of nodes which might contain heredocs.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RuboCop
module RSpec
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a

View File

@ -4,6 +4,8 @@ module RuboCop
module RSpec
# RSpec public API methods that are commonly used in cops
module Language
RSPEC = '{(const nil? :RSpec) nil?}'
# Set of method selectors
class SelectorSet
def initialize(selectors)
@ -27,7 +29,7 @@ module RuboCop
end
def send_pattern
"(send {(const nil? :RSpec) nil?} #{node_pattern_union} ...)"
"(send #{RSPEC} #{node_pattern_union} ...)"
end
def node_pattern_union
@ -106,6 +108,10 @@ module RuboCop
ALL = SelectorSet.new(%i[expect is_expected expect_any_instance_of])
end
module Runners
ALL = SelectorSet.new(%i[to to_not not_to])
end
ALL =
ExampleGroups::ALL +
SharedGroups::ALL +
@ -113,7 +119,8 @@ module RuboCop
Hooks::ALL +
Helpers::ALL +
Subject::ALL +
Expectations::ALL
Expectations::ALL +
Runners::ALL
end
end
end

View File

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