rubocop-rspec 1.41.0 → 1.44.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 +43 -2
- data/config/default.yml +41 -3
- data/lib/rubocop-rspec.rb +2 -1
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +12 -19
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +12 -19
- data/lib/rubocop/cop/rspec/any_instance.rb +1 -1
- data/lib/rubocop/cop/rspec/around_block.rb +2 -2
- data/lib/rubocop/cop/rspec/base.rb +76 -0
- data/lib/rubocop/cop/rspec/be.rb +2 -2
- data/lib/rubocop/cop/rspec/be_eql.rb +6 -6
- data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +19 -17
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +14 -12
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +1 -1
- data/lib/rubocop/cop/rspec/context_method.rb +7 -9
- data/lib/rubocop/cop/rspec/context_wording.rb +3 -3
- data/lib/rubocop/cop/rspec/cop.rb +2 -66
- data/lib/rubocop/cop/rspec/describe_class.rb +40 -30
- data/lib/rubocop/cop/rspec/describe_method.rb +14 -6
- data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
- data/lib/rubocop/cop/rspec/described_class.rb +12 -9
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +1 -1
- data/lib/rubocop/cop/rspec/dialect.rb +5 -12
- data/lib/rubocop/cop/rspec/empty_example_group.rb +124 -6
- data/lib/rubocop/cop/rspec/empty_hook.rb +6 -10
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +5 -7
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +5 -9
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +8 -8
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +5 -9
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +6 -6
- data/lib/rubocop/cop/rspec/example_length.rb +1 -1
- data/lib/rubocop/cop/rspec/example_without_description.rb +1 -1
- data/lib/rubocop/cop/rspec/example_wording.rb +10 -11
- data/lib/rubocop/cop/rspec/expect_actual.rb +8 -11
- data/lib/rubocop/cop/rspec/expect_change.rb +10 -35
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +3 -3
- data/lib/rubocop/cop/rspec/expect_output.rb +2 -2
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +20 -20
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +20 -22
- data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +7 -8
- data/lib/rubocop/cop/rspec/file_path.rb +25 -17
- data/lib/rubocop/cop/rspec/focus.rb +7 -11
- data/lib/rubocop/cop/rspec/hook_argument.rb +16 -23
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +13 -14
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +2 -3
- data/lib/rubocop/cop/rspec/implicit_expect.rb +7 -15
- data/lib/rubocop/cop/rspec/implicit_subject.rb +16 -11
- data/lib/rubocop/cop/rspec/instance_spy.rb +18 -12
- data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
- data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +3 -6
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +5 -6
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/leading_subject.rb +27 -20
- data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -1
- data/lib/rubocop/cop/rspec/let_before_examples.rb +13 -11
- data/lib/rubocop/cop/rspec/let_setup.rb +6 -3
- data/lib/rubocop/cop/rspec/message_chain.rb +7 -6
- data/lib/rubocop/cop/rspec/message_expectation.rb +2 -2
- data/lib/rubocop/cop/rspec/message_spies.rb +2 -3
- data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_describes.rb +11 -8
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +7 -11
- data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +148 -0
- data/lib/rubocop/cop/rspec/multiple_subjects.rb +18 -19
- data/lib/rubocop/cop/rspec/named_subject.rb +2 -2
- data/lib/rubocop/cop/rspec/nested_groups.rb +4 -4
- data/lib/rubocop/cop/rspec/not_to_not.rb +5 -6
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/pending.rb +1 -1
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +30 -67
- data/lib/rubocop/cop/rspec/rails/http_status.rb +5 -9
- data/lib/rubocop/cop/rspec/receive_counts.rb +15 -17
- data/lib/rubocop/cop/rspec/receive_never.rb +12 -12
- data/lib/rubocop/cop/rspec/repeated_description.rb +1 -1
- data/lib/rubocop/cop/rspec/repeated_example.rb +2 -2
- data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +1 -1
- data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +1 -1
- data/lib/rubocop/cop/rspec/repeated_include_example.rb +103 -0
- data/lib/rubocop/cop/rspec/return_from_stub.rb +9 -20
- data/lib/rubocop/cop/rspec/scattered_let.rb +8 -11
- data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/shared_context.rb +8 -21
- data/lib/rubocop/cop/rspec/shared_examples.rb +6 -9
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +15 -18
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +172 -0
- data/lib/rubocop/cop/rspec/subject_stub.rb +6 -6
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +1 -1
- data/lib/rubocop/cop/rspec/variable_definition.rb +6 -6
- data/lib/rubocop/cop/rspec/variable_name.rb +28 -9
- data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -1
- data/lib/rubocop/cop/rspec/void_expect.rb +1 -1
- data/lib/rubocop/cop/rspec/yield.rb +14 -11
- data/lib/rubocop/cop/rspec_cops.rb +3 -0
- data/lib/rubocop/rspec/corrector/move_node.rb +7 -5
- data/lib/rubocop/rspec/description_extractor.rb +1 -1
- data/lib/rubocop/rspec/{blank_line_separation.rb → empty_line_separation.rb} +13 -10
- data/lib/rubocop/rspec/example_group.rb +2 -2
- data/lib/rubocop/rspec/hook.rb +1 -5
- data/lib/rubocop/rspec/language.rb +12 -5
- data/lib/rubocop/rspec/language/node_pattern.rb +6 -1
- data/lib/rubocop/rspec/top_level_describe.rb +2 -2
- data/lib/rubocop/rspec/top_level_group.rb +26 -13
- data/lib/rubocop/rspec/variable.rb +1 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +40 -8
@@ -33,7 +33,8 @@ module RuboCop
|
|
33
33
|
# - If subjects are defined with `subject!` then we don't autocorrect.
|
34
34
|
# This is enough of an edge case that people can just move this to
|
35
35
|
# a `before` hook on their own
|
36
|
-
class MultipleSubjects <
|
36
|
+
class MultipleSubjects < Base
|
37
|
+
extend AutoCorrector
|
37
38
|
include RangeHelp
|
38
39
|
|
39
40
|
MSG = 'Do not set more than one subject per example group'
|
@@ -44,38 +45,36 @@ module RuboCop
|
|
44
45
|
subjects = RuboCop::RSpec::ExampleGroup.new(node).subjects
|
45
46
|
|
46
47
|
subjects[0...-1].each do |subject|
|
47
|
-
add_offense(subject)
|
48
|
+
add_offense(subject) do |corrector|
|
49
|
+
autocorrect(corrector, subject)
|
50
|
+
end
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
51
|
-
|
52
|
-
|
54
|
+
private
|
55
|
+
|
56
|
+
def autocorrect(corrector, subject)
|
57
|
+
return unless subject.method_name.equal?(:subject) # Ignore `subject!`
|
53
58
|
|
54
|
-
if named_subject?(
|
55
|
-
rename_autocorrect(
|
59
|
+
if named_subject?(subject)
|
60
|
+
rename_autocorrect(corrector, subject)
|
56
61
|
else
|
57
|
-
remove_autocorrect(
|
62
|
+
remove_autocorrect(corrector, subject)
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
61
|
-
private
|
62
|
-
|
63
66
|
def named_subject?(node)
|
64
67
|
node.send_node.arguments?
|
65
68
|
end
|
66
69
|
|
67
|
-
def rename_autocorrect(node)
|
68
|
-
|
69
|
-
corrector.replace(node.send_node.loc.selector, 'let')
|
70
|
-
end
|
70
|
+
def rename_autocorrect(corrector, node)
|
71
|
+
corrector.replace(node.send_node.loc.selector, 'let')
|
71
72
|
end
|
72
73
|
|
73
|
-
def remove_autocorrect(node)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
corrector.remove(range)
|
78
|
-
end
|
74
|
+
def remove_autocorrect(corrector, node)
|
75
|
+
range = range_by_whole_lines(node.source_range,
|
76
|
+
include_final_newline: true)
|
77
|
+
corrector.remove(range)
|
79
78
|
end
|
80
79
|
end
|
81
80
|
end
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
#
|
42
42
|
# it { is_expected.to be_valid }
|
43
43
|
# end
|
44
|
-
class NamedSubject <
|
44
|
+
class NamedSubject < Base
|
45
45
|
MSG = 'Name your test subject if you need '\
|
46
46
|
'to reference it explicitly.'
|
47
47
|
|
@@ -62,7 +62,7 @@ module RuboCop
|
|
62
62
|
return if !rspec_block?(node) || ignored_shared_example?(node)
|
63
63
|
|
64
64
|
subject_usage(node) do |subject_node|
|
65
|
-
add_offense(subject_node
|
65
|
+
add_offense(subject_node.loc.selector)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -85,9 +85,9 @@ module RuboCop
|
|
85
85
|
# end
|
86
86
|
# end
|
87
87
|
#
|
88
|
-
class NestedGroups <
|
88
|
+
class NestedGroups < Base
|
89
89
|
include ConfigurableMax
|
90
|
-
include RuboCop::RSpec::
|
90
|
+
include RuboCop::RSpec::TopLevelGroup
|
91
91
|
|
92
92
|
MSG = 'Maximum example group nesting exceeded [%<total>d/%<max>d].'
|
93
93
|
|
@@ -97,8 +97,8 @@ module RuboCop
|
|
97
97
|
"Configuration key `#{DEPRECATED_MAX_KEY}` for #{cop_name} is " \
|
98
98
|
'deprecated in favor of `Max`. Please use that instead.'
|
99
99
|
|
100
|
-
def
|
101
|
-
find_nested_example_groups(node
|
100
|
+
def on_top_level_group(node)
|
101
|
+
find_nested_example_groups(node) do |example_group, nesting|
|
102
102
|
self.max = nesting
|
103
103
|
add_offense(
|
104
104
|
example_group.send_node,
|
@@ -15,7 +15,8 @@ module RuboCop
|
|
15
15
|
# it '...' do
|
16
16
|
# expect(false).not_to be_true
|
17
17
|
# end
|
18
|
-
class NotToNot <
|
18
|
+
class NotToNot < Base
|
19
|
+
extend AutoCorrector
|
19
20
|
include ConfigurableEnforcedStyle
|
20
21
|
|
21
22
|
MSG = 'Prefer `%<replacement>s` over `%<original>s`.'
|
@@ -24,14 +25,12 @@ module RuboCop
|
|
24
25
|
|
25
26
|
def on_send(node)
|
26
27
|
not_to_not_offense(node, alternative_style) do
|
27
|
-
add_offense(node
|
28
|
+
add_offense(node.loc.selector) do |corrector|
|
29
|
+
corrector.replace(node.loc.selector, style.to_s)
|
30
|
+
end
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
|
-
def autocorrect(node)
|
32
|
-
->(corrector) { corrector.replace(node.loc.selector, style.to_s) }
|
33
|
-
end
|
34
|
-
|
35
34
|
private
|
36
35
|
|
37
36
|
def message(_node)
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
# let(:foo) { bar }
|
22
22
|
# let(:baz) { baz }
|
23
23
|
# let!(:other) { other }
|
24
|
-
class OverwritingSetup <
|
24
|
+
class OverwritingSetup < Base
|
25
25
|
MSG = '`%<name>s` is already defined.'
|
26
26
|
|
27
27
|
def_node_matcher :setup?, (Helpers::ALL + Subject::ALL).block_pattern
|
@@ -14,11 +14,14 @@ module RuboCop
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def check_inflected(node)
|
17
|
-
predicate_in_actual?(node) do |predicate|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
predicate_in_actual?(node) do |predicate, to, matcher|
|
18
|
+
msg = message_inflected(predicate)
|
19
|
+
add_offense(node, message: msg) do |corrector|
|
20
|
+
remove_predicate(corrector, predicate)
|
21
|
+
corrector.replace(node.loc.selector,
|
22
|
+
true?(to, matcher) ? 'to' : 'not_to')
|
23
|
+
rewrite_matcher(corrector, predicate, matcher)
|
24
|
+
end
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
@@ -76,17 +79,6 @@ module RuboCop
|
|
76
79
|
end
|
77
80
|
# rubocop:enable Metrics/MethodLength
|
78
81
|
|
79
|
-
def autocorrect_inflected(node)
|
80
|
-
predicate_in_actual?(node) do |predicate, to, matcher|
|
81
|
-
lambda do |corrector|
|
82
|
-
remove_predicate(corrector, predicate)
|
83
|
-
corrector.replace(node.loc.selector,
|
84
|
-
true?(to, matcher) ? 'to' : 'not_to')
|
85
|
-
rewrite_matcher(corrector, predicate, matcher)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
82
|
def remove_predicate(corrector, predicate)
|
91
83
|
range = predicate.loc.dot.with(
|
92
84
|
end_pos: predicate.loc.expression.end_pos
|
@@ -123,7 +115,6 @@ module RuboCop
|
|
123
115
|
end
|
124
116
|
|
125
117
|
# A helper for `explicit` style
|
126
|
-
# rubocop:disable Metrics/ModuleLength
|
127
118
|
module ExplicitHelper
|
128
119
|
include RuboCop::RSpec::Language
|
129
120
|
extend NodePattern::Macros
|
@@ -143,22 +134,21 @@ module RuboCop
|
|
143
134
|
end
|
144
135
|
|
145
136
|
def check_explicit(node) # rubocop:disable Metrics/MethodLength
|
146
|
-
predicate_matcher_block?(node) do |
|
147
|
-
add_offense(
|
148
|
-
node
|
149
|
-
|
150
|
-
|
137
|
+
predicate_matcher_block?(node) do |actual, matcher|
|
138
|
+
add_offense(node, message: message_explicit(matcher)) do |corrector|
|
139
|
+
to_node = node.send_node
|
140
|
+
corrector_explicit(corrector, to_node, actual, matcher, to_node)
|
141
|
+
end
|
151
142
|
ignore_node(node.children.first)
|
152
143
|
return
|
153
144
|
end
|
154
145
|
|
155
146
|
return if part_of_ignored_node?(node)
|
156
147
|
|
157
|
-
predicate_matcher?(node) do |
|
158
|
-
add_offense(
|
159
|
-
node,
|
160
|
-
|
161
|
-
)
|
148
|
+
predicate_matcher?(node) do |actual, matcher|
|
149
|
+
add_offense(node, message: message_explicit(matcher)) do |corrector|
|
150
|
+
corrector_explicit(corrector, node, actual, matcher, matcher)
|
151
|
+
end
|
162
152
|
end
|
163
153
|
end
|
164
154
|
|
@@ -193,31 +183,11 @@ module RuboCop
|
|
193
183
|
matcher_name: matcher.method_name)
|
194
184
|
end
|
195
185
|
|
196
|
-
def
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
def autocorrect_explicit_send(node)
|
202
|
-
predicate_matcher?(node) do |actual, matcher|
|
203
|
-
corrector_explicit(node, actual, matcher, matcher)
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
def autocorrect_explicit_block(node)
|
208
|
-
predicate_matcher_block?(node) do |actual, matcher|
|
209
|
-
to_node = node.send_node
|
210
|
-
corrector_explicit(to_node, actual, matcher, to_node)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def corrector_explicit(to_node, actual, matcher, block_child)
|
215
|
-
lambda do |corrector|
|
216
|
-
replacement_matcher = replacement_matcher(to_node)
|
217
|
-
corrector.replace(matcher.loc.expression, replacement_matcher)
|
218
|
-
move_predicate(corrector, actual, matcher, block_child)
|
219
|
-
corrector.replace(to_node.loc.selector, 'to')
|
220
|
-
end
|
186
|
+
def corrector_explicit(corrector, to_node, actual, matcher, block_child)
|
187
|
+
replacement_matcher = replacement_matcher(to_node)
|
188
|
+
corrector.replace(matcher.loc.expression, replacement_matcher)
|
189
|
+
move_predicate(corrector, actual, matcher, block_child)
|
190
|
+
corrector.replace(to_node.loc.selector, 'to')
|
221
191
|
end
|
222
192
|
|
223
193
|
def move_predicate(corrector, actual, matcher, block_child)
|
@@ -238,18 +208,20 @@ module RuboCop
|
|
238
208
|
'is_a?'
|
239
209
|
when 'be_an_instance_of', 'be_instance_of', 'an_instance_of'
|
240
210
|
'instance_of?'
|
241
|
-
when 'include'
|
242
|
-
|
211
|
+
when 'include'
|
212
|
+
'include?'
|
213
|
+
when 'respond_to'
|
214
|
+
'respond_to?'
|
243
215
|
when /^have_(.+)/
|
244
216
|
"has_#{Regexp.last_match(1)}?"
|
245
217
|
else
|
246
|
-
matcher[/^be_(.+)/, 1]
|
218
|
+
"#{matcher[/^be_(.+)/, 1]}?"
|
247
219
|
end
|
248
220
|
end
|
249
221
|
# rubocop:enable Metrics/MethodLength
|
250
222
|
|
251
223
|
def replacement_matcher(node)
|
252
|
-
case [cop_config['Strict'], node.
|
224
|
+
case [cop_config['Strict'], node.method?(:to)]
|
253
225
|
when [true, true]
|
254
226
|
'be(true)'
|
255
227
|
when [true, false]
|
@@ -261,7 +233,6 @@ module RuboCop
|
|
261
233
|
end
|
262
234
|
end
|
263
235
|
end
|
264
|
-
# rubocop:enable Metrics/ModuleLength
|
265
236
|
|
266
237
|
# Prefer using predicate matcher over using predicate method directly.
|
267
238
|
#
|
@@ -300,7 +271,8 @@ module RuboCop
|
|
300
271
|
#
|
301
272
|
# # good - the above code is rewritten to it by this cop
|
302
273
|
# expect(foo.something?).to be_truthy
|
303
|
-
class PredicateMatcher <
|
274
|
+
class PredicateMatcher < Base
|
275
|
+
extend AutoCorrector
|
304
276
|
include ConfigurableEnforcedStyle
|
305
277
|
include InflectedHelper
|
306
278
|
include ExplicitHelper
|
@@ -318,15 +290,6 @@ module RuboCop
|
|
318
290
|
check_explicit(node) if style == :explicit
|
319
291
|
end
|
320
292
|
|
321
|
-
def autocorrect(node)
|
322
|
-
case style
|
323
|
-
when :inflected
|
324
|
-
autocorrect_inflected(node)
|
325
|
-
when :explicit
|
326
|
-
autocorrect_explicit(node)
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
293
|
private
|
331
294
|
|
332
295
|
# returns args location with whitespace
|
@@ -30,7 +30,8 @@ module RuboCop
|
|
30
30
|
# it { is_expected.to have_http_status :success }
|
31
31
|
# it { is_expected.to have_http_status :error }
|
32
32
|
#
|
33
|
-
class HttpStatus <
|
33
|
+
class HttpStatus < Base
|
34
|
+
extend AutoCorrector
|
34
35
|
include ConfigurableEnforcedStyle
|
35
36
|
|
36
37
|
def_node_matcher :http_status, <<-PATTERN
|
@@ -42,14 +43,9 @@ module RuboCop
|
|
42
43
|
checker = checker_class.new(ast_node)
|
43
44
|
return unless checker.offensive?
|
44
45
|
|
45
|
-
add_offense(checker.node, message: checker.message)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
def autocorrect(node)
|
50
|
-
lambda do |corrector|
|
51
|
-
checker = checker_class.new(node)
|
52
|
-
corrector.replace(node.loc.expression, checker.preferred_style)
|
46
|
+
add_offense(checker.node, message: checker.message) do |corrector|
|
47
|
+
corrector.replace(checker.node, checker.preferred_style)
|
48
|
+
end
|
53
49
|
end
|
54
50
|
end
|
55
51
|
|
@@ -23,7 +23,9 @@ module RuboCop
|
|
23
23
|
# expect(foo).to receive(:bar).at_most(:once)
|
24
24
|
# expect(foo).to receive(:bar).at_most(:twice).times
|
25
25
|
#
|
26
|
-
class ReceiveCounts <
|
26
|
+
class ReceiveCounts < Base
|
27
|
+
extend AutoCorrector
|
28
|
+
|
27
29
|
MSG = 'Use `%<alternative>s` instead of `%<original>s`.'
|
28
30
|
|
29
31
|
def_node_matcher :receive_counts, <<-PATTERN
|
@@ -38,27 +40,23 @@ module RuboCop
|
|
38
40
|
|
39
41
|
offending_range = range(node, offending_node)
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
)
|
43
|
+
msg = message_for(offending_node, offending_range.source)
|
44
|
+
add_offense(offending_range, message: msg) do |corrector|
|
45
|
+
autocorrect(corrector, offending_node, offending_range)
|
46
|
+
end
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
|
50
|
-
lambda do |corrector|
|
51
|
-
replacement = matcher_for(
|
52
|
-
node.method_name,
|
53
|
-
node.first_argument.source.to_i
|
54
|
-
)
|
50
|
+
private
|
55
51
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
def autocorrect(corrector, node, range)
|
53
|
+
replacement = matcher_for(
|
54
|
+
node.method_name,
|
55
|
+
node.first_argument.source.to_i
|
56
|
+
)
|
60
57
|
|
61
|
-
|
58
|
+
corrector.replace(range, replacement)
|
59
|
+
end
|
62
60
|
|
63
61
|
def message_for(node, source)
|
64
62
|
alternative = matcher_for(
|
@@ -13,26 +13,26 @@ module RuboCop
|
|
13
13
|
# # good
|
14
14
|
# expect(foo).not_to receive(:bar)
|
15
15
|
#
|
16
|
-
class ReceiveNever <
|
16
|
+
class ReceiveNever < Base
|
17
|
+
extend AutoCorrector
|
17
18
|
MSG = 'Use `not_to receive` instead of `never`.'
|
18
19
|
|
19
20
|
def_node_search :method_on_stub?, '(send nil? :receive ...)'
|
20
21
|
|
21
22
|
def on_send(node)
|
22
|
-
return unless node.
|
23
|
+
return unless node.method?(:never) && method_on_stub?(node)
|
23
24
|
|
24
|
-
add_offense(
|
25
|
-
node
|
26
|
-
|
27
|
-
)
|
25
|
+
add_offense(node.loc.selector) do |corrector|
|
26
|
+
autocorrect(corrector, node)
|
27
|
+
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
private
|
31
|
+
|
32
|
+
def autocorrect(corrector, node)
|
33
|
+
corrector.replace(node.parent.loc.selector, 'not_to')
|
34
|
+
range = node.loc.dot.with(end_pos: node.loc.selector.end_pos)
|
35
|
+
corrector.remove(range)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|