File tree 5 files changed +29
-5
lines changed
5 files changed +29
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Master (Unreleased)
4
4
5
+ * Add config to ` RSpec/VerifiedDoubles ` to enforcement of verification on unnamed doubles. ([ @BrentWheeldon ] [ ] )
5
6
* Fix ` FactoryBot/AttributeDefinedStatically ` not working when there is a non-symbol key. ([ @vzvu3k6k ] [ ] )
6
7
* Fix false positive in ` RSpec/ImplicitSubject ` when ` is_expected ` is used inside ` its() ` block. ([ @Darhazer ] [ ] )
7
8
* Add ` single_statement_only ` style to ` RSpec/ImplicitSubject ` as a more relaxed alternative to ` single_line_only ` . ([ @Darhazer ] [ ] )
@@ -379,3 +380,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
379
380
[ @composerinteralia ] : https://github.com/composerinteralia
380
381
[ @seanpdoyle ] : https://github.com/seanpdoyle
381
382
[ @vzvu3k6k ] : https://github.com/vzvu3k6k
383
+ [ @BrentWheeldon ] : https://github.com/BrentWheeldon
Original file line number Diff line number Diff line change @@ -402,6 +402,7 @@ RSpec/SubjectStub:
402
402
RSpec/VerifiedDoubles :
403
403
Description : Prefer using verifying doubles over normal doubles.
404
404
Enabled : true
405
+ IgnoreNameless : true
405
406
IgnoreSymbolicNames : false
406
407
StyleGuide : http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubles
407
408
Original file line number Diff line number Diff line change @@ -26,16 +26,23 @@ class VerifiedDoubles < Cop
26
26
MSG = 'Prefer using verifying doubles over normal doubles.' . freeze
27
27
28
28
def_node_matcher :unverified_double , <<-PATTERN
29
- {(send nil? {:double :spy} $_ ...) }
29
+ {(send nil? {:double :spy} $...)}
30
30
PATTERN
31
31
32
32
def on_send ( node )
33
- unverified_double ( node ) do |name |
34
- return if name . sym_type? && cop_config [ 'IgnoreSymbolicNames' ]
33
+ unverified_double ( node ) do |name , *_args |
34
+ return if name . nil? && cop_config [ 'IgnoreNameless' ]
35
+ return if symbol? ( name ) && cop_config [ 'IgnoreSymbolicNames' ]
35
36
36
37
add_offense ( node , location : :expression )
37
38
end
38
39
end
40
+
41
+ private
42
+
43
+ def symbol? ( name )
44
+ name && name . sym_type?
45
+ end
39
46
end
40
47
end
41
48
end
Original file line number Diff line number Diff line change @@ -2494,6 +2494,7 @@ end
2494
2494
2495
2495
Name | Default value | Configurable values
2496
2496
--- | --- | ---
2497
+ IgnoreNameless | ` true ` | Boolean
2497
2498
IgnoreSymbolicNames | ` false ` | Boolean
2498
2499
2499
2500
### References
Original file line number Diff line number Diff line change 53
53
end
54
54
end
55
55
56
- it 'ignores doubles without a name' do
57
- expect_no_offenses ( <<-RUBY )
56
+ it 'doubles that have no name specified ' do
57
+ expect_offense ( <<-RUBY )
58
58
it do
59
59
foo = double
60
+ ^^^^^^ Prefer using verifying doubles over normal doubles.
60
61
end
61
62
RUBY
62
63
end
63
64
65
+ context 'when configured to ignore nameless doubles' do
66
+ let ( :cop_config ) { { 'IgnoreNameless' => true } }
67
+
68
+ it 'ignores doubles that have no name specified' do
69
+ expect_no_offenses ( <<-RUBY )
70
+ it do
71
+ foo = double
72
+ end
73
+ RUBY
74
+ end
75
+ end
76
+
64
77
it 'ignores instance_doubles' do
65
78
expect_no_offenses ( <<-RUBY )
66
79
it do
You can’t perform that action at this time.
0 commit comments