rubocop-rspec 1.43.2 → 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 +14 -3
- data/config/default.yml +28 -0
- data/lib/rubocop/cop/rspec/around_block.rb +1 -1
- data/lib/rubocop/cop/rspec/base.rb +2 -0
- data/lib/rubocop/cop/rspec/describe_class.rb +32 -13
- data/lib/rubocop/cop/rspec/empty_example_group.rb +35 -1
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +1 -2
- data/lib/rubocop/cop/rspec/repeated_include_example.rb +103 -0
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +172 -0
- data/lib/rubocop/cop/rspec/subject_stub.rb +4 -4
- data/lib/rubocop/cop/rspec_cops.rb +2 -0
- data/lib/rubocop/rspec/hook.rb +1 -5
- data/lib/rubocop/rspec/language.rb +6 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93297f5bb7dfcb8e201365ec296afe22e5e3bbc7150b7a48e7991a22739debdd
|
4
|
+
data.tar.gz: 6343b337cf3d879a50553d09c3f4e30e4ff320285c16b533b8fbd73b8732bcd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c3eabc2946eb2b36bdb7a2be61eda35605b32f6ba0a6433cd3bde30982e13f909ea3330111631293c89cbf0237a46d3e3782610448396cdcf6dd77726e5cbda
|
7
|
+
data.tar.gz: da8f502adeb29f94294eb5a947ee455168dcfb44e23a5ad83365e4503dcdf39225b46bdb5e8357f40a231a4644fc97e8ddb85933fbc78159c43d40bbf5dddc94
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 1.44.0 (2020-10-20)
|
6
|
+
|
7
|
+
* Move our documentation from rubocop-rspec.readthedocs.io to docs.rubocop.org/rubocop-rspec. ([@bquorning][])
|
8
|
+
* Add `RSpec/RepeatedIncludeExample` cop. ([@biinari][])
|
9
|
+
* Add `RSpec/StubbedMock` cop. ([@bquorning][], [@pirj][])
|
10
|
+
* Add `IgnoredMetadata` configuration option to `RSpec/DescribeClass`. ([@Rafix02][])
|
11
|
+
* Fix false positives in `RSpec/EmptyExampleGroup`. ([@pirj][])
|
12
|
+
* Fix a false positive for `RSpec/EmptyExampleGroup` when example is defined in an `if` branch. ([@koic][])
|
13
|
+
|
5
14
|
## 1.43.2 (2020-08-25)
|
6
15
|
|
7
16
|
* Fix `RSpec/FilePath` when checking a file with a shared example. ([@pirj][])
|
@@ -506,8 +515,8 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
506
515
|
[@rspeicher]: https://github.com/rspeicher
|
507
516
|
[@jonatas]: https://github.com/jonatas
|
508
517
|
[@pocke]: https://github.com/pocke
|
509
|
-
[@bmorrall]: https
|
510
|
-
[@zverok]: https
|
518
|
+
[@bmorrall]: https://github.com/bmorrall
|
519
|
+
[@zverok]: https://github.com/zverok
|
511
520
|
[@timrogers]: https://github.com/timrogers
|
512
521
|
[@yevhene]: https://github.com/yevhene
|
513
522
|
[@walf443]: https://github.com/walf443
|
@@ -552,6 +561,8 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
552
561
|
[@andrykonchin]: https://github.com/andrykonchin
|
553
562
|
[@harrylewis]: https://github.com/harrylewis
|
554
563
|
[@elliterate]: https://github.com/elliterate
|
555
|
-
[@mlarraz]: https://github.com/mlarraz
|
556
564
|
[@jtannas]: https://github.com/jtannas
|
557
565
|
[@mockdeep]: https://github.com/mockdeep
|
566
|
+
[@biinari]: https://github.com/biinari
|
567
|
+
[@koic]: https://github.com/koic
|
568
|
+
[@Rafix02]: https://github.com/Rafix02
|
data/config/default.yml
CHANGED
@@ -76,7 +76,23 @@ RSpec/ContextWording:
|
|
76
76
|
RSpec/DescribeClass:
|
77
77
|
Description: Check that the first argument to the top-level describe is a constant.
|
78
78
|
Enabled: true
|
79
|
+
IgnoredMetadata:
|
80
|
+
type:
|
81
|
+
- channel
|
82
|
+
- controller
|
83
|
+
- helper
|
84
|
+
- job
|
85
|
+
- mailer
|
86
|
+
- model
|
87
|
+
- request
|
88
|
+
- routing
|
89
|
+
- view
|
90
|
+
- feature
|
91
|
+
- system
|
92
|
+
- mailbox
|
93
|
+
- aruba
|
79
94
|
VersionAdded: '1.0'
|
95
|
+
VersionChanged: '1.44'
|
80
96
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribeClass
|
81
97
|
|
82
98
|
RSpec/DescribeMethod:
|
@@ -494,6 +510,12 @@ RSpec/RepeatedExampleGroupDescription:
|
|
494
510
|
VersionAdded: '1.38'
|
495
511
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedExampleGroupDescription
|
496
512
|
|
513
|
+
RSpec/RepeatedIncludeExample:
|
514
|
+
Description: Check for repeated include of shared examples.
|
515
|
+
Enabled: true
|
516
|
+
VersionAdded: '1.44'
|
517
|
+
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RepeatedIncludeExample
|
518
|
+
|
497
519
|
RSpec/ReturnFromStub:
|
498
520
|
Description: Checks for consistent style of stub's return setting.
|
499
521
|
Enabled: true
|
@@ -537,6 +559,12 @@ RSpec/SingleArgumentMessageChain:
|
|
537
559
|
VersionChanged: '1.10'
|
538
560
|
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SingleArgumentMessageChain
|
539
561
|
|
562
|
+
RSpec/StubbedMock:
|
563
|
+
Description: Checks that message expectations do not have a configured response.
|
564
|
+
Enabled: pending
|
565
|
+
VersionAdded: '1.44'
|
566
|
+
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/StubbedMock
|
567
|
+
|
540
568
|
RSpec/SubjectStub:
|
541
569
|
Description: Checks for stubbed test subjects.
|
542
570
|
Enabled: true
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
'or `%<arg>s.run`.'
|
32
32
|
|
33
33
|
def_node_matcher :hook, <<-PATTERN
|
34
|
-
(block
|
34
|
+
(block (send nil? :around sym ?) (args $...) ...)
|
35
35
|
PATTERN
|
36
36
|
|
37
37
|
def_node_search :find_arg_usage, <<-PATTERN
|
@@ -29,6 +29,8 @@ module RuboCop
|
|
29
29
|
.map(&Regexp.public_method(:new))
|
30
30
|
)
|
31
31
|
|
32
|
+
exclude_from_registry
|
33
|
+
|
32
34
|
# Invoke the original inherited hook so our cops are recognized
|
33
35
|
def self.inherited(subclass) # rubocop:disable Lint/MissingSuper
|
34
36
|
RuboCop::Cop::Base.inherited(subclass)
|
@@ -5,6 +5,19 @@ module RuboCop
|
|
5
5
|
module RSpec
|
6
6
|
# Check that the first argument to the top-level describe is a constant.
|
7
7
|
#
|
8
|
+
# It can be configured to ignore strings when certain metadata is passed.
|
9
|
+
#
|
10
|
+
# Ignores Rails and Aruba `type` metadata by default.
|
11
|
+
#
|
12
|
+
# @example `IgnoredMetadata` configuration
|
13
|
+
#
|
14
|
+
# # .rubocop.yml
|
15
|
+
# # RSpec/DescribeClass:
|
16
|
+
# # IgnoredMetadata:
|
17
|
+
# # type:
|
18
|
+
# # - request
|
19
|
+
# # - controller
|
20
|
+
#
|
8
21
|
# @example
|
9
22
|
# # bad
|
10
23
|
# describe 'Do something' do
|
@@ -27,36 +40,42 @@ module RuboCop
|
|
27
40
|
MSG = 'The first argument to describe should be '\
|
28
41
|
'the class or module being tested.'
|
29
42
|
|
30
|
-
def_node_matcher :
|
31
|
-
(
|
32
|
-
(sym :type)
|
33
|
-
(sym { :channel :controller :helper :job :mailer :model :request
|
34
|
-
:routing :view :feature :system :mailbox })
|
35
|
-
)
|
36
|
-
PATTERN
|
37
|
-
|
38
|
-
def_node_matcher :example_group_with_rails_metadata?, <<~PATTERN
|
39
|
-
(send #rspec? :describe ... (hash <#rails_metadata? ...>))
|
43
|
+
def_node_matcher :example_group_with_ignored_metadata?, <<~PATTERN
|
44
|
+
(send #rspec? :describe ... (hash <#ignored_metadata? ...>))
|
40
45
|
PATTERN
|
41
46
|
|
42
47
|
def_node_matcher :not_a_const_described, <<~PATTERN
|
43
48
|
(send #rspec? :describe $[!const !#string_constant?] ...)
|
44
49
|
PATTERN
|
45
50
|
|
46
|
-
|
47
|
-
|
51
|
+
def_node_matcher :sym_pair, <<~PATTERN
|
52
|
+
(pair $sym $sym)
|
53
|
+
PATTERN
|
48
54
|
|
49
|
-
|
55
|
+
def on_top_level_group(node)
|
56
|
+
return if example_group_with_ignored_metadata?(node.send_node)
|
57
|
+
|
58
|
+
not_a_const_described(node.send_node) do |described|
|
50
59
|
add_offense(described)
|
51
60
|
end
|
52
61
|
end
|
53
62
|
|
54
63
|
private
|
55
64
|
|
65
|
+
def ignored_metadata?(node)
|
66
|
+
sym_pair(node) do |key, value|
|
67
|
+
ignored_metadata[key.value.to_s].to_a.include?(value.value.to_s)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
56
71
|
def string_constant?(described)
|
57
72
|
described.str_type? &&
|
58
73
|
described.value.match?(/^(?:(?:::)?[A-Z]\w*)+$/)
|
59
74
|
end
|
75
|
+
|
76
|
+
def ignored_metadata
|
77
|
+
cop_config['IgnoredMetadata'] || {}
|
78
|
+
end
|
60
79
|
end
|
61
80
|
end
|
62
81
|
end
|
@@ -33,6 +33,11 @@ module RuboCop
|
|
33
33
|
# end
|
34
34
|
# end
|
35
35
|
#
|
36
|
+
# # good
|
37
|
+
# describe Bacon do
|
38
|
+
# pending 'will add tests later'
|
39
|
+
# end
|
40
|
+
#
|
36
41
|
# @example configuration
|
37
42
|
#
|
38
43
|
# # .rubocop.yml
|
@@ -83,11 +88,14 @@ module RuboCop
|
|
83
88
|
# it_behaves_like 'an animal'
|
84
89
|
# it_behaves_like('a cat') { let(:food) { 'milk' } }
|
85
90
|
# it_has_root_access
|
91
|
+
# skip
|
92
|
+
# it 'will be implemented later'
|
86
93
|
#
|
87
94
|
# @param node [RuboCop::AST::Node]
|
88
95
|
# @return [Array<RuboCop::AST::Node>] matching nodes
|
89
96
|
def_node_matcher :example_or_group_or_include?, <<~PATTERN
|
90
97
|
{
|
98
|
+
#{Examples::ALL.send_pattern}
|
91
99
|
#{Examples::ALL.block_pattern}
|
92
100
|
#{ExampleGroups::ALL.block_pattern}
|
93
101
|
#{Includes::ALL.send_pattern}
|
@@ -152,13 +160,39 @@ module RuboCop
|
|
152
160
|
PATTERN
|
153
161
|
|
154
162
|
def on_block(node)
|
163
|
+
return if node.each_ancestor(:def, :defs).any?
|
164
|
+
return if node.each_ancestor(:block).any? { |block| example?(block) }
|
165
|
+
|
155
166
|
example_group_body(node) do |body|
|
156
|
-
add_offense(node.send_node)
|
167
|
+
add_offense(node.send_node) if offensive?(body)
|
157
168
|
end
|
158
169
|
end
|
159
170
|
|
160
171
|
private
|
161
172
|
|
173
|
+
def offensive?(body)
|
174
|
+
return true unless body
|
175
|
+
return false if conditionals_with_examples?(body)
|
176
|
+
|
177
|
+
if body.if_type?
|
178
|
+
!examples_in_branches?(body)
|
179
|
+
else
|
180
|
+
!examples?(body)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def conditionals_with_examples?(body)
|
185
|
+
return unless body.begin_type?
|
186
|
+
|
187
|
+
body.each_descendant(:if).any? do |if_node|
|
188
|
+
examples_in_branches?(if_node)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def examples_in_branches?(if_node)
|
193
|
+
if_node.branches.any? { |branch| examples?(branch) }
|
194
|
+
end
|
195
|
+
|
162
196
|
def custom_include?(method_name)
|
163
197
|
custom_include_methods.include?(method_name)
|
164
198
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Check for repeated include of shared examples.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# describe 'foo' do
|
12
|
+
# include_examples 'cool stuff'
|
13
|
+
# include_examples 'cool stuff'
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# describe 'foo' do
|
18
|
+
# it_behaves_like 'a cool', 'thing'
|
19
|
+
# it_behaves_like 'a cool', 'thing'
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# # bad
|
23
|
+
# context 'foo' do
|
24
|
+
# it_should_behave_like 'a duck'
|
25
|
+
# it_should_behave_like 'a duck'
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# # good
|
29
|
+
# describe 'foo' do
|
30
|
+
# include_examples 'cool stuff'
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# describe 'bar' do
|
34
|
+
# include_examples 'cool stuff'
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# # good
|
38
|
+
# describe 'foo' do
|
39
|
+
# it_behaves_like 'a cool', 'thing'
|
40
|
+
# it_behaves_like 'a cool', 'person'
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# # good
|
44
|
+
# context 'foo' do
|
45
|
+
# it_should_behave_like 'a duck'
|
46
|
+
# it_should_behave_like 'a goose'
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
class RepeatedIncludeExample < Base
|
50
|
+
MSG = 'Repeated include of shared_examples %<name>s ' \
|
51
|
+
'on line(s) %<repeat>s'
|
52
|
+
|
53
|
+
def_node_matcher :several_include_examples?, <<-PATTERN
|
54
|
+
(begin <#include_examples? #include_examples? ...>)
|
55
|
+
PATTERN
|
56
|
+
|
57
|
+
def_node_matcher :include_examples?, Includes::EXAMPLES.send_pattern
|
58
|
+
|
59
|
+
def_node_matcher :shared_examples_name, <<-PATTERN
|
60
|
+
(send _ #{Includes::EXAMPLES.node_pattern_union} $_ ...)
|
61
|
+
PATTERN
|
62
|
+
|
63
|
+
def on_begin(node)
|
64
|
+
return unless several_include_examples?(node)
|
65
|
+
|
66
|
+
repeated_include_examples(node).each do |item, repeats|
|
67
|
+
add_offense(item, message: message(item, repeats))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def repeated_include_examples(node)
|
74
|
+
node
|
75
|
+
.children
|
76
|
+
.select { |child| literal_include_examples?(child) }
|
77
|
+
.group_by { |child| signature_keys(child) }
|
78
|
+
.values
|
79
|
+
.reject(&:one?)
|
80
|
+
.flat_map { |items| add_repeated_lines(items) }
|
81
|
+
end
|
82
|
+
|
83
|
+
def literal_include_examples?(node)
|
84
|
+
include_examples?(node) &&
|
85
|
+
node.arguments.all?(&:recursive_literal_or_const?)
|
86
|
+
end
|
87
|
+
|
88
|
+
def add_repeated_lines(items)
|
89
|
+
repeated_lines = items.map(&:first_line)
|
90
|
+
items.map { |item| [item, repeated_lines - [item.first_line]] }
|
91
|
+
end
|
92
|
+
|
93
|
+
def signature_keys(item)
|
94
|
+
item.arguments
|
95
|
+
end
|
96
|
+
|
97
|
+
def message(item, repeats)
|
98
|
+
format(MSG, name: shared_examples_name(item).source, repeat: repeats)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Checks that message expectations do not have a configured response.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# expect(foo).to receive(:bar).with(42).and_return("hello world")
|
12
|
+
#
|
13
|
+
# # good (without spies)
|
14
|
+
# allow(foo).to receive(:bar).with(42).and_return("hello world")
|
15
|
+
# expect(foo).to receive(:bar).with(42)
|
16
|
+
#
|
17
|
+
class StubbedMock < Base
|
18
|
+
MSG = 'Prefer `%<replacement>s` over `%<method_name>s` when ' \
|
19
|
+
'configuring a response.'
|
20
|
+
|
21
|
+
# @!method message_expectation?(node)
|
22
|
+
# Match message expectation matcher
|
23
|
+
#
|
24
|
+
# @example source that matches
|
25
|
+
# receive(:foo)
|
26
|
+
#
|
27
|
+
# @example source that matches
|
28
|
+
# receive_message_chain(:foo, :bar)
|
29
|
+
#
|
30
|
+
# @example source that matches
|
31
|
+
# receive(:foo).with('bar')
|
32
|
+
#
|
33
|
+
# @param node [RuboCop::AST::Node]
|
34
|
+
# @return [Array<RuboCop::AST::Node>] matching nodes
|
35
|
+
def_node_matcher :message_expectation?, <<-PATTERN
|
36
|
+
{
|
37
|
+
(send nil? { :receive :receive_message_chain } ...) # receive(:foo)
|
38
|
+
(send (send nil? :receive ...) :with ...) # receive(:foo).with('bar')
|
39
|
+
}
|
40
|
+
PATTERN
|
41
|
+
|
42
|
+
def_node_matcher :configured_response?, <<~PATTERN
|
43
|
+
{ :and_return :and_raise :and_throw :and_yield
|
44
|
+
:and_call_original :and_wrap_original }
|
45
|
+
PATTERN
|
46
|
+
|
47
|
+
# @!method expectation(node)
|
48
|
+
# Match expectation
|
49
|
+
#
|
50
|
+
# @example source that matches
|
51
|
+
# is_expected.to be_in_the_bar
|
52
|
+
#
|
53
|
+
# @example source that matches
|
54
|
+
# expect(cocktail).to contain_exactly(:fresh_orange_juice, :campari)
|
55
|
+
#
|
56
|
+
# @example source that matches
|
57
|
+
# expect_any_instance_of(Officer).to be_alert
|
58
|
+
#
|
59
|
+
# @param node [RuboCop::AST::Node]
|
60
|
+
# @yield [RuboCop::AST::Node] expectation, method name, matcher
|
61
|
+
def_node_matcher :expectation, <<~PATTERN
|
62
|
+
(send
|
63
|
+
$(send nil? $#{Expectations::ALL.node_pattern_union} ...)
|
64
|
+
:to $_)
|
65
|
+
PATTERN
|
66
|
+
|
67
|
+
# @!method matcher_with_configured_response(node)
|
68
|
+
# Match matcher with a configured response
|
69
|
+
#
|
70
|
+
# @example source that matches
|
71
|
+
# receive(:foo).and_return('bar')
|
72
|
+
#
|
73
|
+
# @example source that matches
|
74
|
+
# receive(:lower).and_raise(SomeError)
|
75
|
+
#
|
76
|
+
# @example source that matches
|
77
|
+
# receive(:redirect).and_call_original
|
78
|
+
#
|
79
|
+
# @param node [RuboCop::AST::Node]
|
80
|
+
# @yield [RuboCop::AST::Node] matcher
|
81
|
+
def_node_matcher :matcher_with_configured_response, <<~PATTERN
|
82
|
+
(send #message_expectation? #configured_response? _)
|
83
|
+
PATTERN
|
84
|
+
|
85
|
+
# @!method matcher_with_return_block(node)
|
86
|
+
# Match matcher with a return block
|
87
|
+
#
|
88
|
+
# @example source that matches
|
89
|
+
# receive(:foo) { 'bar' }
|
90
|
+
#
|
91
|
+
# @param node [RuboCop::AST::Node]
|
92
|
+
# @yield [RuboCop::AST::Node] matcher
|
93
|
+
def_node_matcher :matcher_with_return_block, <<~PATTERN
|
94
|
+
(block #message_expectation? args _) # receive(:foo) { 'bar' }
|
95
|
+
PATTERN
|
96
|
+
|
97
|
+
# @!method matcher_with_hash(node)
|
98
|
+
# Match matcher with a configured response defined as a hash
|
99
|
+
#
|
100
|
+
# @example source that matches
|
101
|
+
# receive_messages(foo: 'bar', baz: 'qux')
|
102
|
+
#
|
103
|
+
# @example source that matches
|
104
|
+
# receive_message_chain(:foo, bar: 'baz')
|
105
|
+
#
|
106
|
+
# @param node [RuboCop::AST::Node]
|
107
|
+
# @yield [RuboCop::AST::Node] matcher
|
108
|
+
def_node_matcher :matcher_with_hash, <<~PATTERN
|
109
|
+
{
|
110
|
+
(send nil? :receive_messages hash) # receive_messages(foo: 'bar', baz: 'qux')
|
111
|
+
(send nil? :receive_message_chain ... hash) # receive_message_chain(:foo, bar: 'baz')
|
112
|
+
}
|
113
|
+
PATTERN
|
114
|
+
|
115
|
+
# @!method matcher_with_blockpass(node)
|
116
|
+
# Match matcher with a configured response in block-pass
|
117
|
+
#
|
118
|
+
# @example source that matches
|
119
|
+
# receive(:foo, &canned)
|
120
|
+
#
|
121
|
+
# @example source that matches
|
122
|
+
# receive_message_chain(:foo, :bar, &canned)
|
123
|
+
#
|
124
|
+
# @example source that matches
|
125
|
+
# receive(:foo).with('bar', &canned)
|
126
|
+
#
|
127
|
+
# @param node [RuboCop::AST::Node]
|
128
|
+
# @yield [RuboCop::AST::Node] matcher
|
129
|
+
def_node_matcher :matcher_with_blockpass, <<~PATTERN
|
130
|
+
{
|
131
|
+
(send nil? { :receive :receive_message_chain } ... block_pass) # receive(:foo, &canned)
|
132
|
+
(send (send nil? :receive ...) :with ... block_pass) # receive(:foo).with('foo', &canned)
|
133
|
+
}
|
134
|
+
PATTERN
|
135
|
+
|
136
|
+
def on_send(node)
|
137
|
+
expectation(node, &method(:on_expectation))
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
def on_expectation(expectation, method_name, matcher)
|
143
|
+
flag_expectation = lambda do
|
144
|
+
add_offense(expectation, message: msg(method_name))
|
145
|
+
end
|
146
|
+
|
147
|
+
matcher_with_configured_response(matcher, &flag_expectation)
|
148
|
+
matcher_with_return_block(matcher, &flag_expectation)
|
149
|
+
matcher_with_hash(matcher, &flag_expectation)
|
150
|
+
matcher_with_blockpass(matcher, &flag_expectation)
|
151
|
+
end
|
152
|
+
|
153
|
+
def msg(method_name)
|
154
|
+
format(MSG,
|
155
|
+
method_name: method_name,
|
156
|
+
replacement: replacement(method_name))
|
157
|
+
end
|
158
|
+
|
159
|
+
def replacement(method_name)
|
160
|
+
case method_name
|
161
|
+
when :expect
|
162
|
+
:allow
|
163
|
+
when :is_expected
|
164
|
+
'allow(subject)'
|
165
|
+
when :expect_any_instance_of
|
166
|
+
:allow_any_instance_of
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -43,10 +43,10 @@ module RuboCop
|
|
43
43
|
#
|
44
44
|
# @yield [Symbol] subject name
|
45
45
|
def_node_matcher :subject, <<-PATTERN
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
(block
|
47
|
+
(send nil?
|
48
|
+
{:subject (sym $_) | $:subject}
|
49
|
+
) args ...)
|
50
50
|
PATTERN
|
51
51
|
|
52
52
|
# @!method message_expectation?(node, method_name)
|
@@ -79,12 +79,14 @@ require_relative 'rspec/repeated_description'
|
|
79
79
|
require_relative 'rspec/repeated_example'
|
80
80
|
require_relative 'rspec/repeated_example_group_body'
|
81
81
|
require_relative 'rspec/repeated_example_group_description'
|
82
|
+
require_relative 'rspec/repeated_include_example'
|
82
83
|
require_relative 'rspec/return_from_stub'
|
83
84
|
require_relative 'rspec/scattered_let'
|
84
85
|
require_relative 'rspec/scattered_setup'
|
85
86
|
require_relative 'rspec/shared_context'
|
86
87
|
require_relative 'rspec/shared_examples'
|
87
88
|
require_relative 'rspec/single_argument_message_chain'
|
89
|
+
require_relative 'rspec/stubbed_mock'
|
88
90
|
require_relative 'rspec/subject_stub'
|
89
91
|
require_relative 'rspec/unspecified_exception'
|
90
92
|
require_relative 'rspec/variable_definition'
|
data/lib/rubocop/rspec/hook.rb
CHANGED
@@ -7,7 +7,8 @@ module RuboCop
|
|
7
7
|
# Set of method selectors
|
8
8
|
class SelectorSet
|
9
9
|
def initialize(selectors)
|
10
|
-
@selectors = selectors
|
10
|
+
@selectors = selectors.freeze
|
11
|
+
freeze
|
11
12
|
end
|
12
13
|
|
13
14
|
def ==(other)
|
@@ -50,6 +51,10 @@ module RuboCop
|
|
50
51
|
selectors.map(&:inspect).join(' ')
|
51
52
|
end
|
52
53
|
|
54
|
+
def to_a
|
55
|
+
selectors
|
56
|
+
end
|
57
|
+
|
53
58
|
protected
|
54
59
|
|
55
60
|
attr_reader :selectors
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.44.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Backus
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-10-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '0.87'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rubocop-ast
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.7.1
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.7.1
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: rack
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,12 +217,14 @@ files:
|
|
203
217
|
- lib/rubocop/cop/rspec/repeated_example.rb
|
204
218
|
- lib/rubocop/cop/rspec/repeated_example_group_body.rb
|
205
219
|
- lib/rubocop/cop/rspec/repeated_example_group_description.rb
|
220
|
+
- lib/rubocop/cop/rspec/repeated_include_example.rb
|
206
221
|
- lib/rubocop/cop/rspec/return_from_stub.rb
|
207
222
|
- lib/rubocop/cop/rspec/scattered_let.rb
|
208
223
|
- lib/rubocop/cop/rspec/scattered_setup.rb
|
209
224
|
- lib/rubocop/cop/rspec/shared_context.rb
|
210
225
|
- lib/rubocop/cop/rspec/shared_examples.rb
|
211
226
|
- lib/rubocop/cop/rspec/single_argument_message_chain.rb
|
227
|
+
- lib/rubocop/cop/rspec/stubbed_mock.rb
|
212
228
|
- lib/rubocop/cop/rspec/subject_stub.rb
|
213
229
|
- lib/rubocop/cop/rspec/unspecified_exception.rb
|
214
230
|
- lib/rubocop/cop/rspec/variable_definition.rb
|
@@ -243,7 +259,7 @@ licenses:
|
|
243
259
|
- MIT
|
244
260
|
metadata:
|
245
261
|
changelog_uri: https://github.com/rubocop-hq/rubocop-rspec/blob/master/CHANGELOG.md
|
246
|
-
documentation_uri: https://rubocop-rspec
|
262
|
+
documentation_uri: https://docs.rubocop.org/rubocop-rspec/
|
247
263
|
post_install_message:
|
248
264
|
rdoc_options: []
|
249
265
|
require_paths:
|