rubocop-rspec 1.32.0 → 1.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/config/default.yml +6 -0
- data/lib/rubocop-rspec.rb +3 -0
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +1 -1
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +1 -1
- data/lib/rubocop/cop/rspec/any_instance.rb +3 -1
- data/lib/rubocop/cop/rspec/around_block.rb +4 -2
- data/lib/rubocop/cop/rspec/be.rb +4 -2
- data/lib/rubocop/cop/rspec/be_eql.rb +3 -1
- data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +5 -3
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -3
- data/lib/rubocop/cop/rspec/context_wording.rb +2 -2
- data/lib/rubocop/cop/rspec/describe_class.rb +4 -4
- data/lib/rubocop/cop/rspec/describe_method.rb +2 -2
- data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
- data/lib/rubocop/cop/rspec/described_class.rb +3 -3
- data/lib/rubocop/cop/rspec/dialect.rb +76 -0
- data/lib/rubocop/cop/rspec/empty_example_group.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/example_length.rb +1 -1
- data/lib/rubocop/cop/rspec/example_without_description.rb +2 -2
- data/lib/rubocop/cop/rspec/example_wording.rb +2 -2
- data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_change.rb +2 -2
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +21 -40
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +2 -2
- data/lib/rubocop/cop/rspec/file_path.rb +2 -2
- data/lib/rubocop/cop/rspec/focus.rb +3 -3
- data/lib/rubocop/cop/rspec/hook_argument.rb +4 -6
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +2 -5
- data/lib/rubocop/cop/rspec/implicit_expect.rb +2 -2
- data/lib/rubocop/cop/rspec/implicit_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/instance_spy.rb +1 -1
- data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
- data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +4 -2
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -1
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
- data/lib/rubocop/cop/rspec/leading_subject.rb +1 -2
- data/lib/rubocop/cop/rspec/let_before_examples.rb +2 -5
- data/lib/rubocop/cop/rspec/let_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/message_chain.rb +3 -1
- data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/message_spies.rb +3 -4
- data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_subjects.rb +6 -2
- data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
- data/lib/rubocop/cop/rspec/nested_groups.rb +3 -4
- data/lib/rubocop/cop/rspec/not_to_not.rb +3 -1
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/pending.rb +3 -3
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +17 -14
- data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -2
- data/lib/rubocop/cop/rspec/receive_counts.rb +5 -6
- data/lib/rubocop/cop/rspec/receive_never.rb +4 -7
- data/lib/rubocop/cop/rspec/repeated_description.rb +3 -1
- data/lib/rubocop/cop/rspec/repeated_example.rb +3 -1
- data/lib/rubocop/cop/rspec/return_from_stub.rb +2 -2
- data/lib/rubocop/cop/rspec/scattered_let.rb +1 -1
- data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/shared_context.rb +2 -2
- data/lib/rubocop/cop/rspec/shared_examples.rb +7 -7
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +3 -1
- data/lib/rubocop/cop/rspec/subject_stub.rb +1 -1
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +5 -3
- data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -2
- data/lib/rubocop/cop/rspec/void_expect.rb +1 -1
- data/lib/rubocop/cop/rspec/yield.rb +2 -4
- data/lib/rubocop/cop/rspec_cops.rb +3 -0
- data/lib/rubocop/rspec.rb +2 -0
- data/lib/rubocop/rspec/blank_line_separation.rb +3 -1
- data/lib/rubocop/rspec/config_formatter.rb +3 -1
- data/lib/rubocop/rspec/description_extractor.rb +3 -1
- data/lib/rubocop/rspec/factory_bot.rb +58 -0
- data/lib/rubocop/rspec/final_end_location.rb +2 -0
- data/lib/rubocop/rspec/inject.rb +2 -0
- data/lib/rubocop/rspec/language.rb +9 -2
- data/lib/rubocop/rspec/top_level_describe.rb +2 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/rubocop-rspec.gemspec +3 -1
- data/spec/project/changelog_spec.rb +2 -0
- data/spec/project/default_config_spec.rb +2 -0
- data/spec/project/project_requires_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +22 -37
- data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +21 -36
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/around_block_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/be_eql_spec.rb +25 -4
- data/spec/rubocop/cop/rspec/be_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/before_after_all_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/context_wording_spec.rb +32 -0
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/described_class_spec.rb +4 -1
- data/spec/rubocop/cop/rspec/dialect_spec.rb +78 -0
- data/spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb +40 -21
- data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +77 -69
- data/spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb +24 -19
- data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +16 -19
- data/spec/rubocop/cop/rspec/example_length_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/example_without_description_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +45 -24
- data/spec/rubocop/cop/rspec/expect_change_spec.rb +22 -14
- data/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +36 -0
- data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/file_path_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/focus_spec.rb +2 -2
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/hooks_before_examples_spec.rb +47 -32
- data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +20 -19
- data/spec/rubocop/cop/rspec/implicit_subject_spec.rb +56 -68
- data/spec/rubocop/cop/rspec/instance_spy_spec.rb +16 -15
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +10 -12
- data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/leading_subject_spec.rb +31 -47
- data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +27 -26
- data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/missing_example_group_argument_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +24 -37
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +22 -32
- data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/pending_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/receive_counts_spec.rb +47 -8
- data/spec/rubocop/cop/rspec/receive_never_spec.rb +16 -4
- data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +95 -72
- data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/shared_context_spec.rb +29 -34
- data/spec/rubocop/cop/rspec/shared_examples_spec.rb +16 -34
- data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +44 -48
- data/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/void_expect_spec.rb +2 -0
- data/spec/rubocop/cop/rspec/yield_spec.rb +22 -21
- data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
- data/spec/rubocop/rspec/description_extractor_spec.rb +2 -0
- data/spec/rubocop/rspec/language/selector_set_spec.rb +2 -0
- data/spec/rubocop/rspec/util/one_spec.rb +2 -0
- data/spec/rubocop/rspec/wording_spec.rb +2 -0
- data/spec/shared/autocorrect_behavior.rb +2 -0
- data/spec/shared/detects_style_behavior.rb +2 -0
- data/spec/shared/smoke_test_examples.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/expect_offense.rb +3 -1
- metadata +8 -4
@@ -51,8 +51,8 @@ module RuboCop
|
|
51
51
|
include ConfigurableEnforcedStyle
|
52
52
|
|
53
53
|
MSG_DEFAULT_ARGUMENT = 'Omit the argument when you want to ' \
|
54
|
-
'have auto-generated description.'
|
55
|
-
MSG_ADD_DESCRIPTION = 'Add a description.'
|
54
|
+
'have auto-generated description.'
|
55
|
+
MSG_ADD_DESCRIPTION = 'Add a description.'
|
56
56
|
|
57
57
|
def_node_matcher :example_description, '(send nil? _ $(str $_))'
|
58
58
|
|
@@ -30,8 +30,8 @@ module RuboCop
|
|
30
30
|
# it 'does things' do
|
31
31
|
# end
|
32
32
|
class ExampleWording < Cop
|
33
|
-
MSG_SHOULD = 'Do not use should when describing your tests.'
|
34
|
-
MSG_IT = "Do not repeat 'it' when describing your tests."
|
33
|
+
MSG_SHOULD = 'Do not use should when describing your tests.'
|
34
|
+
MSG_IT = "Do not repeat 'it' when describing your tests."
|
35
35
|
|
36
36
|
SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
|
37
37
|
IT_PREFIX = /\Ait /i.freeze
|
@@ -32,8 +32,8 @@ module RuboCop
|
|
32
32
|
class ExpectChange < Cop
|
33
33
|
include ConfigurableEnforcedStyle
|
34
34
|
|
35
|
-
MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'
|
36
|
-
MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'
|
35
|
+
MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'
|
36
|
+
MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'
|
37
37
|
|
38
38
|
def_node_matcher :expect_change_with_arguments, <<-PATTERN
|
39
39
|
(send nil? :change ({const send} nil? $_) (sym $_))
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
# expect(something).to eq 'foo'
|
22
22
|
# end
|
23
23
|
class ExpectInHook < Cop
|
24
|
-
MSG = 'Do not use `%<expect>s` in `%<hook>s` hook'
|
24
|
+
MSG = 'Do not use `%<expect>s` in `%<hook>s` hook'
|
25
25
|
|
26
26
|
def_node_search :expectation, Expectations::ALL.send_pattern
|
27
27
|
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
# expect { my_app.print_report }.to output('Hello World').to_stdout
|
17
17
|
class ExpectOutput < Cop
|
18
18
|
MSG = 'Use `expect { ... }.to output(...).to_%<name>s` '\
|
19
|
-
'instead of mutating $%<name>s.'
|
19
|
+
'instead of mutating $%<name>s.'
|
20
20
|
|
21
21
|
def on_gvasgn(node)
|
22
22
|
return unless inside_example_scope?(node)
|
@@ -25,53 +25,19 @@ module RuboCop
|
|
25
25
|
# # good
|
26
26
|
# count { 1 }
|
27
27
|
class AttributeDefinedStatically < Cop
|
28
|
-
MSG = 'Use a block to declare attribute values.'
|
29
|
-
|
30
|
-
ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze
|
31
|
-
|
32
|
-
UNPROXIED_METHODS = %i[
|
33
|
-
__send__
|
34
|
-
__id__
|
35
|
-
nil?
|
36
|
-
send
|
37
|
-
object_id
|
38
|
-
extend
|
39
|
-
instance_eval
|
40
|
-
initialize
|
41
|
-
block_given?
|
42
|
-
raise
|
43
|
-
caller
|
44
|
-
method
|
45
|
-
].freeze
|
46
|
-
|
47
|
-
DEFINITION_PROXY_METHODS = %i[
|
48
|
-
add_attribute
|
49
|
-
after
|
50
|
-
association
|
51
|
-
before
|
52
|
-
callback
|
53
|
-
ignore
|
54
|
-
initialize_with
|
55
|
-
sequence
|
56
|
-
skip_create
|
57
|
-
to_create
|
58
|
-
].freeze
|
59
|
-
|
60
|
-
RESERVED_METHODS =
|
61
|
-
DEFINITION_PROXY_METHODS +
|
62
|
-
UNPROXIED_METHODS +
|
63
|
-
ATTRIBUTE_DEFINING_METHODS
|
28
|
+
MSG = 'Use a block to declare attribute values.'
|
64
29
|
|
65
30
|
def_node_matcher :value_matcher, <<-PATTERN
|
66
|
-
(send
|
31
|
+
(send _ !#reserved_method? $...)
|
67
32
|
PATTERN
|
68
33
|
|
69
34
|
def_node_search :factory_attributes, <<-PATTERN
|
70
|
-
(block (send
|
35
|
+
(block (send _ #attribute_defining_method? ...) _ { (begin $...) $(send ...) } )
|
71
36
|
PATTERN
|
72
37
|
|
73
38
|
def on_block(node)
|
74
39
|
factory_attributes(node).to_a.flatten.each do |attribute|
|
40
|
+
next unless offensive_receiver?(attribute.receiver, node)
|
75
41
|
next if proc?(attribute) || association?(attribute)
|
76
42
|
|
77
43
|
add_offense(attribute, location: :expression)
|
@@ -88,6 +54,20 @@ module RuboCop
|
|
88
54
|
|
89
55
|
private
|
90
56
|
|
57
|
+
def offensive_receiver?(receiver, node)
|
58
|
+
receiver.nil? ||
|
59
|
+
receiver.self_type? ||
|
60
|
+
receiver_matches_first_block_argument?(receiver, node)
|
61
|
+
end
|
62
|
+
|
63
|
+
def receiver_matches_first_block_argument?(receiver, node)
|
64
|
+
first_block_argument = node.arguments.first
|
65
|
+
|
66
|
+
!first_block_argument.nil? &&
|
67
|
+
receiver.lvar_type? &&
|
68
|
+
receiver.node_parts == first_block_argument.node_parts
|
69
|
+
end
|
70
|
+
|
91
71
|
def proc?(attribute)
|
92
72
|
value_matcher(attribute).to_a.all?(&:block_pass_type?)
|
93
73
|
end
|
@@ -134,11 +114,12 @@ module RuboCop
|
|
134
114
|
end
|
135
115
|
|
136
116
|
def reserved_method?(method_name)
|
137
|
-
|
117
|
+
RuboCop::RSpec::FactoryBot.reserved_methods.include?(method_name)
|
138
118
|
end
|
139
119
|
|
140
120
|
def attribute_defining_method?(method_name)
|
141
|
-
|
121
|
+
RuboCop::RSpec::FactoryBot.attribute_defining_methods
|
122
|
+
.include?(method_name)
|
142
123
|
end
|
143
124
|
end
|
144
125
|
end
|
@@ -27,8 +27,8 @@ module RuboCop
|
|
27
27
|
class CreateList < Cop
|
28
28
|
include ConfigurableEnforcedStyle
|
29
29
|
|
30
|
-
MSG_CREATE_LIST = 'Prefer create_list.'
|
31
|
-
MSG_N_TIMES = 'Prefer %<number>s.times.'
|
30
|
+
MSG_CREATE_LIST = 'Prefer create_list.'
|
31
|
+
MSG_N_TIMES = 'Prefer %<number>s.times.'
|
32
32
|
|
33
33
|
def_node_matcher :n_times_block_without_arg?, <<-PATTERN
|
34
34
|
(block
|
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
class FilePath < Cop
|
45
45
|
include RuboCop::RSpec::TopLevelDescribe
|
46
46
|
|
47
|
-
MSG = 'Spec path should end with `%<suffix>s`.'
|
47
|
+
MSG = 'Spec path should end with `%<suffix>s`.'
|
48
48
|
|
49
49
|
def_node_search :const_described?, '(send _ :describe (const ...) ...)'
|
50
50
|
def_node_search :routing_metadata?, '(pair (sym :type) (sym :routing))'
|
@@ -75,7 +75,7 @@ module RuboCop
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def name_glob(name)
|
78
|
-
return unless name
|
78
|
+
return unless name&.str_type?
|
79
79
|
|
80
80
|
"*#{name.str_content.gsub(/\W/, '')}" unless ignore_methods?
|
81
81
|
end
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
# describe MyClass do
|
21
21
|
# end
|
22
22
|
class Focus < Cop
|
23
|
-
MSG = 'Focused spec found.'
|
23
|
+
MSG = 'Focused spec found.'
|
24
24
|
|
25
25
|
focusable =
|
26
26
|
ExampleGroups::GROUPS +
|
@@ -36,8 +36,8 @@ module RuboCop
|
|
36
36
|
FOCUS_TRUE = s(:pair, FOCUS_SYMBOL, s(:true))
|
37
37
|
|
38
38
|
def_node_matcher :metadata, <<-PATTERN
|
39
|
-
{(send {
|
40
|
-
(send {
|
39
|
+
{(send #{RSPEC} #{FOCUSABLE_SELECTORS} ... (hash $...))
|
40
|
+
(send #{RSPEC} #{FOCUSABLE_SELECTORS} $...)}
|
41
41
|
PATTERN
|
42
42
|
|
43
43
|
def_node_matcher :focused_block?, focused.send_pattern
|
@@ -59,11 +59,10 @@ module RuboCop
|
|
59
59
|
# end
|
60
60
|
class HookArgument < Cop
|
61
61
|
include ConfigurableEnforcedStyle
|
62
|
-
include RangeHelp
|
63
62
|
|
64
63
|
IMPLICIT_MSG = 'Omit the default `%<scope>p` ' \
|
65
|
-
'argument for RSpec hooks.'
|
66
|
-
EXPLICIT_MSG = 'Use `%<scope>p` for RSpec hooks.'
|
64
|
+
'argument for RSpec hooks.'
|
65
|
+
EXPLICIT_MSG = 'Use `%<scope>p` for RSpec hooks.'
|
67
66
|
|
68
67
|
HOOKS = Hooks::ALL.node_pattern_union.freeze
|
69
68
|
|
@@ -125,9 +124,8 @@ module RuboCop
|
|
125
124
|
end
|
126
125
|
|
127
126
|
def argument_range(send_node)
|
128
|
-
|
129
|
-
send_node.loc.
|
130
|
-
send_node.loc.expression.end_pos
|
127
|
+
send_node.loc.selector.end.with(
|
128
|
+
end_pos: send_node.loc.expression.end_pos
|
131
129
|
)
|
132
130
|
end
|
133
131
|
end
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
include RangeHelp
|
28
28
|
include RuboCop::RSpec::FinalEndLocation
|
29
29
|
|
30
|
-
MSG = 'Move `%<hook>s` above the examples in the group.'
|
30
|
+
MSG = 'Move `%<hook>s` above the examples in the group.'
|
31
31
|
|
32
32
|
def_node_matcher :example_or_group?, <<-PATTERN
|
33
33
|
{
|
@@ -88,10 +88,7 @@ module RuboCop
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def node_range(node)
|
91
|
-
|
92
|
-
node.loc.expression.begin_pos,
|
93
|
-
final_end_location(node).end_pos
|
94
|
-
)
|
91
|
+
node.loc.expression.with(end_pos: final_end_location(node).end_pos)
|
95
92
|
end
|
96
93
|
end
|
97
94
|
end
|
@@ -27,12 +27,12 @@ module RuboCop
|
|
27
27
|
class ImplicitExpect < Cop
|
28
28
|
include ConfigurableEnforcedStyle
|
29
29
|
|
30
|
-
MSG = 'Prefer `%<good>s` over `%<bad>s`.'
|
30
|
+
MSG = 'Prefer `%<good>s` over `%<bad>s`.'
|
31
31
|
|
32
32
|
def_node_matcher :implicit_expect, <<-PATTERN
|
33
33
|
{
|
34
34
|
(send nil? ${:should :should_not} ...)
|
35
|
-
(send (send nil? $:is_expected) {
|
35
|
+
(send (send nil? $:is_expected) #{Runners::ALL.node_pattern_union} ...)
|
36
36
|
}
|
37
37
|
PATTERN
|
38
38
|
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
class ImplicitSubject < Cop
|
30
30
|
include ConfigurableEnforcedStyle
|
31
31
|
|
32
|
-
MSG = "Don't use implicit subject."
|
32
|
+
MSG = "Don't use implicit subject."
|
33
33
|
|
34
34
|
def_node_matcher :implicit_subject?, <<-PATTERN
|
35
35
|
(send nil? {:should :should_not :is_expected} ...)
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
# end
|
48
48
|
#
|
49
49
|
class InstanceVariable < Cop
|
50
|
-
MSG = 'Replace instance variable with local variable or `let`.'
|
50
|
+
MSG = 'Replace instance variable with local variable or `let`.'
|
51
51
|
|
52
52
|
EXAMPLE_GROUP_METHODS = ExampleGroups::ALL + SharedGroups::ALL
|
53
53
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RuboCop
|
2
4
|
module Cop
|
3
5
|
module RSpec
|
@@ -14,10 +16,10 @@ module RuboCop
|
|
14
16
|
# # good
|
15
17
|
# expect(foo).to be_something
|
16
18
|
class InvalidPredicateMatcher < Cop
|
17
|
-
MSG = 'Omit `?` from `%<matcher>s`.'
|
19
|
+
MSG = 'Omit `?` from `%<matcher>s`.'
|
18
20
|
|
19
21
|
def_node_matcher :invalid_predicate_matcher?, <<-PATTERN
|
20
|
-
(send (send nil? :expect ...) {
|
22
|
+
(send (send nil? :expect ...) #{Runners::ALL.node_pattern_union} $(send nil? #predicate?))
|
21
23
|
PATTERN
|
22
24
|
|
23
25
|
def on_send(node)
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
include ConfigurableEnforcedStyle
|
23
23
|
|
24
24
|
MSG = 'Prefer `%<replacement>s` over `%<original>s` when including '\
|
25
|
-
'examples in a nested context.'
|
25
|
+
'examples in a nested context.'
|
26
26
|
|
27
27
|
def_node_matcher :example_inclusion_offense, '(send _ % ...)'
|
28
28
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RuboCop
|
2
4
|
module Cop
|
3
5
|
module RSpec
|
@@ -15,7 +17,7 @@ module RuboCop
|
|
15
17
|
# end
|
16
18
|
class IteratedExpectation < Cop
|
17
19
|
MSG = 'Prefer using the `all` matcher instead ' \
|
18
|
-
'of iterating over an array.'
|
20
|
+
'of iterating over an array.'
|
19
21
|
|
20
22
|
def_node_matcher :each?, <<-PATTERN
|
21
23
|
(block
|
@@ -34,8 +34,7 @@ module RuboCop
|
|
34
34
|
class LeadingSubject < Cop
|
35
35
|
include RangeHelp
|
36
36
|
|
37
|
-
MSG = 'Declare `subject` above any other `%<offending>s` '
|
38
|
-
'declarations.'.freeze
|
37
|
+
MSG = 'Declare `subject` above any other `%<offending>s` declarations.'
|
39
38
|
|
40
39
|
def on_block(node)
|
41
40
|
return unless subject?(node) && !in_spec_block?(node)
|
@@ -34,7 +34,7 @@ module RuboCop
|
|
34
34
|
include RangeHelp
|
35
35
|
include RuboCop::RSpec::FinalEndLocation
|
36
36
|
|
37
|
-
MSG = 'Move `let` before the examples in the group.'
|
37
|
+
MSG = 'Move `let` before the examples in the group.'
|
38
38
|
|
39
39
|
def_node_matcher :example_or_group?, <<-PATTERN
|
40
40
|
{
|
@@ -91,10 +91,7 @@ module RuboCop
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def node_range(node)
|
94
|
-
|
95
|
-
node.loc.expression.begin_pos,
|
96
|
-
final_end_location(node).end_pos
|
97
|
-
)
|
94
|
+
node.loc.expression.with(end_pos: final_end_location(node).end_pos)
|
98
95
|
end
|
99
96
|
end
|
100
97
|
end
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
class LetSetup < Cop
|
29
29
|
include RuboCop::RSpec::TopLevelDescribe
|
30
30
|
|
31
|
-
MSG = 'Do not use `let!` for test setup.'
|
31
|
+
MSG = 'Do not use `let!` for test setup.'
|
32
32
|
|
33
33
|
def_node_search :let_bang, <<-PATTERN
|
34
34
|
(block $(send nil? :let! (sym $_)) args ...)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RuboCop
|
2
4
|
module Cop
|
3
5
|
module RSpec
|
@@ -12,7 +14,7 @@ module RuboCop
|
|
12
14
|
# allow(foo).to receive(bar: thing)
|
13
15
|
#
|
14
16
|
class MessageChain < Cop
|
15
|
-
MSG = 'Avoid stubbing using `%<method>s`.'
|
17
|
+
MSG = 'Avoid stubbing using `%<method>s`.'
|
16
18
|
|
17
19
|
def_node_matcher :message_chain, <<-PATTERN
|
18
20
|
(send _ {:receive_message_chain :stub_chain} ...)
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
class MessageExpectation < Cop
|
28
28
|
include ConfigurableEnforcedStyle
|
29
29
|
|
30
|
-
MSG = 'Prefer `%<style>s` for setting message expectations.'
|
30
|
+
MSG = 'Prefer `%<style>s` for setting message expectations.'
|
31
31
|
|
32
32
|
SUPPORTED_STYLES = %w[allow expect].freeze
|
33
33
|
|
@@ -27,17 +27,16 @@ module RuboCop
|
|
27
27
|
class MessageSpies < Cop
|
28
28
|
include ConfigurableEnforcedStyle
|
29
29
|
|
30
|
-
MSG_RECEIVE = 'Prefer `receive` for setting message '
|
31
|
-
'expectations.'.freeze
|
30
|
+
MSG_RECEIVE = 'Prefer `receive` for setting message expectations.'
|
32
31
|
|
33
32
|
MSG_HAVE_RECEIVED = 'Prefer `have_received` for setting message '\
|
34
33
|
'expectations. Setup `%<source>s` as a spy using '\
|
35
|
-
'`allow` or `instance_spy`.'
|
34
|
+
'`allow` or `instance_spy`.'
|
36
35
|
|
37
36
|
SUPPORTED_STYLES = %w[have_received receive].freeze
|
38
37
|
|
39
38
|
def_node_matcher :message_expectation, %(
|
40
|
-
(send (send nil? :expect $_) {
|
39
|
+
(send (send nil? :expect $_) #{Runners::ALL.node_pattern_union} ...)
|
41
40
|
)
|
42
41
|
|
43
42
|
def_node_search :receive_message, %(
|