rubocop-rspec 1.10.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/config/default.yml +8 -0
- data/lib/rubocop-rspec.rb +1 -0
- data/lib/rubocop/cop/rspec/around_block.rb +78 -0
- data/lib/rubocop/cop/rspec/be_eql.rb +0 -2
- data/lib/rubocop/cop/rspec/described_class.rb +50 -10
- data/lib/rubocop/cop/rspec/repeated_example.rb +11 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- data/spec/rubocop/cop/rspec/around_block_spec.rb +30 -0
- data/spec/rubocop/cop/rspec/described_class_spec.rb +195 -107
- data/spec/rubocop/cop/rspec/repeated_example_spec.rb +9 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fda044631502561746af13188e9d7217ef83f8fb
|
4
|
+
data.tar.gz: d021f893b44704291ff69433019a9798b50fe82e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d804e069e562fa9af39669b2f39b6d8fa81e1ce4778bba2dfbf999dd1afc583475e1bd3d296e1ce79cf40bf04ad42d09468d9b4b0eb6dd10fced565e7e970b3
|
7
|
+
data.tar.gz: 8d14f57b6eb8437b68a7f92acea42a687a7515e1793da6d11485e3c97140571b6741697fad84e6763be1f31fad1d897b88e8dd5131d0286e92fe05cd4c77717a
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## Master (unreleased)
|
4
4
|
|
5
|
+
## 1.11.0 (2017-02-16)
|
6
|
+
|
7
|
+
* Add `AroundBlock` cop. ([@Darhazer][])
|
8
|
+
* Add `EnforcedStyle` configuration for `RSpec/DescribedClass` cop. ([@Darhazer][])
|
9
|
+
* Fix false positive for `RSpec/RepeatedExample` cop. ([@redross][])
|
10
|
+
|
5
11
|
## 1.10.0 (2017-01-15)
|
6
12
|
|
7
13
|
* Fix false negative for `RSpec/MessageSpies` cop. ([@onk][])
|
@@ -172,3 +178,5 @@
|
|
172
178
|
[@jeffreyc]: https://github.com/jeffreyc
|
173
179
|
[@clupprich]: https://github.com/clupprich
|
174
180
|
[@onk]: https://github.com/onk
|
181
|
+
[@Darhazer]: https://github.com/Darhazer
|
182
|
+
[@redross]: https://github.com/redross
|
data/config/default.yml
CHANGED
@@ -9,6 +9,10 @@ RSpec/AnyInstance:
|
|
9
9
|
Description: Check that instances are not being stubbed globally.
|
10
10
|
Enabled: true
|
11
11
|
|
12
|
+
RSpec/AroundBlock:
|
13
|
+
Description: Checks that around blocks actually run the test.
|
14
|
+
Enabled: true
|
15
|
+
|
12
16
|
RSpec/BeEql:
|
13
17
|
Description: Check for expectations where `be(...)` can replace `eql(...)`.
|
14
18
|
Enabled: true
|
@@ -21,6 +25,10 @@ RSpec/DescribedClass:
|
|
21
25
|
Description: Checks that tests use `described_class`.
|
22
26
|
SkipBlocks: false
|
23
27
|
Enabled: true
|
28
|
+
EnforcedStyle: described_class
|
29
|
+
SupportedStyles:
|
30
|
+
- described_class
|
31
|
+
- explicit
|
24
32
|
|
25
33
|
RSpec/DescribeMethod:
|
26
34
|
Description: Checks that the second argument to `describe` specifies a method.
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -21,6 +21,7 @@ RuboCop::RSpec::Inject.defaults!
|
|
21
21
|
|
22
22
|
# cops
|
23
23
|
require 'rubocop/cop/rspec/any_instance'
|
24
|
+
require 'rubocop/cop/rspec/around_block'
|
24
25
|
require 'rubocop/cop/rspec/be_eql'
|
25
26
|
require 'rubocop/cop/rspec/describe_class'
|
26
27
|
require 'rubocop/cop/rspec/describe_method'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Cop
|
3
|
+
module RSpec
|
4
|
+
# Checks that around blocks actually run the test.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# # bad
|
8
|
+
# around do
|
9
|
+
# some_method
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# around do |test|
|
13
|
+
# some_method
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# around do |test|
|
18
|
+
# some_method
|
19
|
+
# test.call
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# around do |test|
|
23
|
+
# some_method
|
24
|
+
# test.run
|
25
|
+
# end
|
26
|
+
class AroundBlock < Cop
|
27
|
+
MSG_NO_ARG = 'Test object should be passed to around block'.freeze
|
28
|
+
MSG_UNUSED_ARG = 'You should call `%<arg>s.call` ' \
|
29
|
+
'or `%<arg>s.run`'.freeze
|
30
|
+
|
31
|
+
def_node_matcher :scoped_hook, <<-PATTERN
|
32
|
+
(block (send nil :around (sym {:each :example})) $(args ...) ...)
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def_node_matcher :unscoped_hook, <<-PATTERN
|
36
|
+
(block (send nil :around) $(args ...) ...)
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def_node_search :find_arg_usage, '(lvar $_)'
|
40
|
+
|
41
|
+
def on_block(node)
|
42
|
+
hook(node) do |parameters|
|
43
|
+
missing_parameters(parameters) do
|
44
|
+
add_offense(node, :expression, MSG_NO_ARG)
|
45
|
+
return
|
46
|
+
end
|
47
|
+
|
48
|
+
unused_parameters(parameters) do |param, name|
|
49
|
+
add_offense(param, :expression, format(MSG_UNUSED_ARG, arg: name))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def missing_parameters(node)
|
57
|
+
yield if node.children[0].nil?
|
58
|
+
end
|
59
|
+
|
60
|
+
def unused_parameters(node)
|
61
|
+
first_arg = node.children[0]
|
62
|
+
param, _methods, _args = *first_arg
|
63
|
+
start = node.parent
|
64
|
+
|
65
|
+
find_arg_usage(start) do |name|
|
66
|
+
return if param == name
|
67
|
+
end
|
68
|
+
|
69
|
+
yield first_arg, param
|
70
|
+
end
|
71
|
+
|
72
|
+
def hook(node, &block)
|
73
|
+
scoped_hook(node, &block) || unscoped_hook(node, &block)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -6,10 +6,11 @@ module RuboCop
|
|
6
6
|
# Checks that tests use `described_class`.
|
7
7
|
#
|
8
8
|
# If the first argument of describe is a class, the class is exposed to
|
9
|
-
# each example via described_class
|
10
|
-
# repeating the class.
|
9
|
+
# each example via described_class.
|
11
10
|
#
|
12
|
-
#
|
11
|
+
# This cop can be configured using the `EnforcedStyle` option
|
12
|
+
#
|
13
|
+
# @example `EnforcedStyle: described_class`
|
13
14
|
# # bad
|
14
15
|
# describe MyClass do
|
15
16
|
# subject { MyClass.do_something }
|
@@ -19,11 +20,24 @@ module RuboCop
|
|
19
20
|
# describe MyClass do
|
20
21
|
# subject { described_class.do_something }
|
21
22
|
# end
|
23
|
+
#
|
24
|
+
# @example `EnforcedStyle: explicit`
|
25
|
+
# # bad
|
26
|
+
# describe MyClass do
|
27
|
+
# subject { described_class.do_something }
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# describe MyClass do
|
32
|
+
# subject { MyClass.do_something }
|
33
|
+
# end
|
34
|
+
#
|
22
35
|
class DescribedClass < Cop
|
23
36
|
include RuboCop::RSpec::TopLevelDescribe
|
37
|
+
include RuboCop::Cop::ConfigurableEnforcedStyle
|
24
38
|
|
25
39
|
DESCRIBED_CLASS = 'described_class'.freeze
|
26
|
-
MSG =
|
40
|
+
MSG = 'Use `%s` instead of `%s`'.freeze
|
27
41
|
|
28
42
|
def_node_matcher :common_instance_exec_closure?, <<-PATTERN
|
29
43
|
(block (send (const nil {:Class :Module}) :new ...) ...)
|
@@ -38,27 +52,44 @@ module RuboCop
|
|
38
52
|
describe, described_class, body = described_constant(node)
|
39
53
|
return unless top_level_describe?(describe)
|
40
54
|
|
41
|
-
|
42
|
-
|
55
|
+
# in case we explicit style is used, this cop needs to remember what's
|
56
|
+
# being described, so to replace described_class with the constant
|
57
|
+
@described_class = described_class
|
58
|
+
|
59
|
+
find_usage(body) do |match|
|
60
|
+
add_offense(match, :expression, message(match.const_name))
|
43
61
|
end
|
44
62
|
end
|
45
63
|
|
46
64
|
def autocorrect(node)
|
65
|
+
replacement = if style == :described_class
|
66
|
+
DESCRIBED_CLASS
|
67
|
+
else
|
68
|
+
@described_class.const_name
|
69
|
+
end
|
47
70
|
lambda do |corrector|
|
48
|
-
corrector.replace(node.loc.expression,
|
71
|
+
corrector.replace(node.loc.expression, replacement)
|
49
72
|
end
|
50
73
|
end
|
51
74
|
|
52
75
|
private
|
53
76
|
|
54
|
-
def
|
55
|
-
yield(node) if
|
77
|
+
def find_usage(node, &block)
|
78
|
+
yield(node) if offensive?(node)
|
56
79
|
|
57
80
|
return unless node.is_a?(Parser::AST::Node)
|
58
81
|
return if scope_change?(node) || node.const_type?
|
59
82
|
|
60
83
|
node.children.each do |child|
|
61
|
-
|
84
|
+
find_usage(child, &block)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def message(offense)
|
89
|
+
if style == :described_class
|
90
|
+
format(MSG, DESCRIBED_CLASS, offense)
|
91
|
+
else
|
92
|
+
format(MSG, @described_class.const_name, DESCRIBED_CLASS)
|
62
93
|
end
|
63
94
|
end
|
64
95
|
|
@@ -75,6 +106,15 @@ module RuboCop
|
|
75
106
|
def skip_blocks?
|
76
107
|
cop_config['SkipBlocks'].equal?(true)
|
77
108
|
end
|
109
|
+
|
110
|
+
def offensive?(node)
|
111
|
+
if style == :described_class
|
112
|
+
node.eql?(@described_class)
|
113
|
+
else
|
114
|
+
_receiver, method_name, *_args = *node
|
115
|
+
method_name == :described_class
|
116
|
+
end
|
117
|
+
end
|
78
118
|
end
|
79
119
|
end
|
80
120
|
end
|
@@ -29,12 +29,22 @@ module RuboCop
|
|
29
29
|
def repeated_examples(node)
|
30
30
|
RuboCop::RSpec::ExampleGroup.new(node)
|
31
31
|
.examples
|
32
|
-
.group_by { |example|
|
32
|
+
.group_by { |example| example_signature(example) }
|
33
33
|
.values
|
34
34
|
.reject(&:one?)
|
35
35
|
.flatten
|
36
36
|
.map(&:to_node)
|
37
37
|
end
|
38
|
+
|
39
|
+
def example_signature(example)
|
40
|
+
key_parts = [example.metadata, example.implementation]
|
41
|
+
|
42
|
+
if example.definition.method_name == :its
|
43
|
+
key_parts << example.definition.method_args
|
44
|
+
end
|
45
|
+
|
46
|
+
key_parts
|
47
|
+
end
|
38
48
|
end
|
39
49
|
end
|
40
50
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
describe RuboCop::Cop::RSpec::AroundBlock do
|
2
|
+
subject(:cop) { described_class.new }
|
3
|
+
|
4
|
+
it 'finds `around` block without block arguments' do
|
5
|
+
expect_violation(<<-RUBY)
|
6
|
+
around do
|
7
|
+
^^^^^^^^^ Test object should be passed to around block
|
8
|
+
do_something
|
9
|
+
end
|
10
|
+
RUBY
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'finds `around` block with unused argument' do
|
14
|
+
expect_violation(<<-RUBY)
|
15
|
+
around do |test|
|
16
|
+
^^^^ You should call `test.call` or `test.run`
|
17
|
+
do_something
|
18
|
+
end
|
19
|
+
RUBY
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'checks the first argument of the block' do
|
23
|
+
expect_violation(<<-RUBY)
|
24
|
+
around do |test, unused|
|
25
|
+
^^^^ You should call `test.call` or `test.run`
|
26
|
+
unused.run
|
27
|
+
end
|
28
|
+
RUBY
|
29
|
+
end
|
30
|
+
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
describe RuboCop::Cop::RSpec::DescribedClass, :config do
|
2
2
|
subject(:cop) { described_class.new(config) }
|
3
3
|
|
4
|
+
let(:cop_config) do
|
5
|
+
{ 'EnforcedStyle' => enforced_style }
|
6
|
+
end
|
7
|
+
|
4
8
|
shared_examples 'SkipBlocks enabled' do
|
5
9
|
it 'does not flag violations within non-rspec blocks' do
|
6
10
|
expect_violation(<<-RUBY)
|
@@ -69,141 +73,225 @@ describe RuboCop::Cop::RSpec::DescribedClass, :config do
|
|
69
73
|
include_examples 'SkipBlocks disabled'
|
70
74
|
end
|
71
75
|
|
72
|
-
|
73
|
-
|
74
|
-
describe MyClass do
|
75
|
-
include MyClass
|
76
|
-
^^^^^^^ Use `described_class` instead of `MyClass`
|
76
|
+
context 'when EnforcedStyle is :described_class' do
|
77
|
+
let(:enforced_style) { :described_class }
|
77
78
|
|
78
|
-
|
79
|
+
it 'checks for the use of the described class' do
|
80
|
+
expect_violation(<<-RUBY)
|
81
|
+
describe MyClass do
|
82
|
+
include MyClass
|
79
83
|
^^^^^^^ Use `described_class` instead of `MyClass`
|
80
84
|
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
RUBY
|
85
|
-
end
|
85
|
+
subject { MyClass.do_something }
|
86
|
+
^^^^^^^ Use `described_class` instead of `MyClass`
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
RUBY
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'ignores describe that do not reference to a class' do
|
96
|
-
expect_no_violations(<<-RUBY)
|
97
|
-
describe "MyClass" do
|
98
|
-
subject { "MyClass" }
|
99
|
-
end
|
100
|
-
RUBY
|
101
|
-
end
|
88
|
+
before { MyClass.do_something }
|
89
|
+
^^^^^^^ Use `described_class` instead of `MyClass`
|
90
|
+
end
|
91
|
+
RUBY
|
92
|
+
end
|
102
93
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
94
|
+
it 'ignores described class as string' do
|
95
|
+
expect_no_violations(<<-RUBY)
|
96
|
+
describe MyClass do
|
97
|
+
subject { "MyClass" }
|
98
|
+
end
|
99
|
+
RUBY
|
100
|
+
end
|
108
101
|
|
109
|
-
|
110
|
-
|
102
|
+
it 'ignores describe that do not reference to a class' do
|
103
|
+
expect_no_violations(<<-RUBY)
|
104
|
+
describe "MyClass" do
|
105
|
+
subject { "MyClass" }
|
111
106
|
end
|
107
|
+
RUBY
|
108
|
+
end
|
112
109
|
|
113
|
-
|
114
|
-
|
110
|
+
it 'ignores class if the scope is changing' do
|
111
|
+
expect_no_violations(<<-RUBY)
|
112
|
+
describe MyClass do
|
113
|
+
Class.new { foo = MyClass }
|
114
|
+
Module.new { bar = MyClass }
|
115
|
+
|
116
|
+
def method
|
117
|
+
include MyClass
|
118
|
+
end
|
119
|
+
|
120
|
+
class OtherClass
|
121
|
+
include MyClass
|
122
|
+
end
|
123
|
+
|
124
|
+
module MyModle
|
125
|
+
include MyClass
|
126
|
+
end
|
115
127
|
end
|
128
|
+
RUBY
|
129
|
+
end
|
116
130
|
|
117
|
-
|
118
|
-
|
131
|
+
it 'only takes class from top level describes' do
|
132
|
+
expect_violation(<<-RUBY)
|
133
|
+
describe MyClass do
|
134
|
+
describe MyClass::Foo do
|
135
|
+
subject { MyClass::Foo }
|
136
|
+
|
137
|
+
let(:foo) { MyClass }
|
138
|
+
^^^^^^^ Use `described_class` instead of `MyClass`
|
139
|
+
end
|
119
140
|
end
|
120
|
-
|
121
|
-
|
122
|
-
end
|
141
|
+
RUBY
|
142
|
+
end
|
123
143
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
144
|
+
it 'ignores subclasses' do
|
145
|
+
expect_no_violations(<<-RUBY)
|
146
|
+
describe MyClass do
|
147
|
+
subject { MyClass::SubClass }
|
148
|
+
end
|
149
|
+
RUBY
|
150
|
+
end
|
129
151
|
|
152
|
+
it 'ignores if namespace is not matching' do
|
153
|
+
expect_no_violations(<<-RUBY)
|
154
|
+
describe MyNamespace::MyClass do
|
155
|
+
subject { ::MyClass }
|
130
156
|
let(:foo) { MyClass }
|
131
|
-
^^^^^^^ Use `described_class` instead of `MyClass`
|
132
157
|
end
|
133
|
-
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'ignores subclasses' do
|
138
|
-
expect_no_violations(<<-RUBY)
|
139
|
-
describe MyClass do
|
140
|
-
subject { MyClass::SubClass }
|
141
|
-
end
|
142
|
-
RUBY
|
143
|
-
end
|
158
|
+
RUBY
|
159
|
+
end
|
144
160
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
161
|
+
it 'checks for the use of described class with namespace' do
|
162
|
+
expect_violation(<<-RUBY)
|
163
|
+
describe MyNamespace::MyClass do
|
164
|
+
subject { MyNamespace::MyClass }
|
165
|
+
^^^^^^^^^^^^^^^^^^^^ Use `described_class` instead of `MyNamespace::MyClass`
|
166
|
+
end
|
167
|
+
RUBY
|
168
|
+
end
|
153
169
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
170
|
+
it 'does not flag violations within a class scope change' do
|
171
|
+
expect_no_violations(<<-RUBY)
|
172
|
+
describe MyNamespace::MyClass do
|
173
|
+
before do
|
174
|
+
class Foo
|
175
|
+
thing = MyNamespace::MyClass.new
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
RUBY
|
180
|
+
end
|
162
181
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
thing = MyNamespace::MyClass.new
|
182
|
+
it 'does not flag violations within a hook scope change' do
|
183
|
+
expect_no_violations(<<-RUBY)
|
184
|
+
describe do
|
185
|
+
before do
|
186
|
+
MyNamespace::MyClass.new
|
169
187
|
end
|
170
188
|
end
|
171
|
-
|
172
|
-
|
173
|
-
|
189
|
+
RUBY
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'checks for the use of described class with module' do
|
193
|
+
skip
|
174
194
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
195
|
+
expect_violation(<<-RUBY)
|
196
|
+
module MyNamespace
|
197
|
+
describe MyClass do
|
198
|
+
subject { MyNamespace::MyClass }
|
199
|
+
^^^^^^^^^^^^^^^^^^^^ Use `described_class` instead of `MyNamespace::MyClass`
|
200
|
+
end
|
180
201
|
end
|
181
|
-
|
182
|
-
|
202
|
+
RUBY
|
203
|
+
end
|
204
|
+
|
205
|
+
include_examples 'autocorrect',
|
206
|
+
'describe(Foo) { include Foo }',
|
207
|
+
'describe(Foo) { include described_class }'
|
208
|
+
|
209
|
+
include_examples 'autocorrect',
|
210
|
+
'describe(Foo) { subject { Foo.do_action } }',
|
211
|
+
'describe(Foo) { subject { described_class.do_action } }'
|
212
|
+
|
213
|
+
include_examples 'autocorrect',
|
214
|
+
'describe(Foo) { before { Foo.do_action } }',
|
215
|
+
'describe(Foo) { before { described_class.do_action } }'
|
183
216
|
end
|
184
217
|
|
185
|
-
|
186
|
-
|
218
|
+
context 'when EnforcedStyle is :explicit' do
|
219
|
+
let(:enforced_style) { :explicit }
|
187
220
|
|
188
|
-
|
189
|
-
|
221
|
+
it 'checks for the use of the described_class' do
|
222
|
+
expect_violation(<<-RUBY)
|
190
223
|
describe MyClass do
|
191
|
-
|
192
|
-
|
224
|
+
include described_class
|
225
|
+
^^^^^^^^^^^^^^^ Use `MyClass` instead of `described_class`
|
226
|
+
|
227
|
+
subject { described_class.do_something }
|
228
|
+
^^^^^^^^^^^^^^^ Use `MyClass` instead of `described_class`
|
229
|
+
|
230
|
+
before { described_class.do_something }
|
231
|
+
^^^^^^^^^^^^^^^ Use `MyClass` instead of `described_class`
|
193
232
|
end
|
194
|
-
|
195
|
-
|
196
|
-
end
|
233
|
+
RUBY
|
234
|
+
end
|
197
235
|
|
198
|
-
|
199
|
-
|
200
|
-
|
236
|
+
it 'ignores described_class as string' do
|
237
|
+
expect_no_violations(<<-RUBY)
|
238
|
+
describe MyClass do
|
239
|
+
subject { "described_class" }
|
240
|
+
end
|
241
|
+
RUBY
|
242
|
+
end
|
201
243
|
|
202
|
-
|
203
|
-
|
204
|
-
|
244
|
+
it 'ignores describe that do not reference to a class' do
|
245
|
+
expect_no_violations(<<-RUBY)
|
246
|
+
describe "MyClass" do
|
247
|
+
subject { described_class }
|
248
|
+
end
|
249
|
+
RUBY
|
250
|
+
end
|
205
251
|
|
206
|
-
|
207
|
-
|
208
|
-
|
252
|
+
it 'does not flag violations within a class scope change' do
|
253
|
+
expect_no_violations(<<-RUBY)
|
254
|
+
describe MyNamespace::MyClass do
|
255
|
+
before do
|
256
|
+
class Foo
|
257
|
+
thing = described_class.new
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
RUBY
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'does not flag violations within a hook scope change' do
|
265
|
+
expect_no_violations(<<-RUBY)
|
266
|
+
describe do
|
267
|
+
before do
|
268
|
+
described_class.new
|
269
|
+
end
|
270
|
+
end
|
271
|
+
RUBY
|
272
|
+
end
|
273
|
+
|
274
|
+
include_examples 'autocorrect',
|
275
|
+
'describe(Foo) { include described_class }',
|
276
|
+
'describe(Foo) { include Foo }'
|
277
|
+
|
278
|
+
include_examples 'autocorrect',
|
279
|
+
'describe(Foo) { subject { described_class.do_action } }',
|
280
|
+
'describe(Foo) { subject { Foo.do_action } }'
|
281
|
+
|
282
|
+
include_examples 'autocorrect',
|
283
|
+
'describe(Foo) { before { described_class.do_action } }',
|
284
|
+
'describe(Foo) { before { Foo.do_action } }'
|
285
|
+
|
286
|
+
original = <<-RUBY
|
287
|
+
describe(Foo) { include described_class }
|
288
|
+
describe(Bar) { include described_class }
|
289
|
+
RUBY
|
290
|
+
corrected = <<-RUBY
|
291
|
+
describe(Foo) { include Foo }
|
292
|
+
describe(Bar) { include Bar }
|
293
|
+
RUBY
|
294
|
+
|
295
|
+
include_examples 'autocorrect', original, corrected
|
296
|
+
end
|
209
297
|
end
|
@@ -47,6 +47,15 @@ describe RuboCop::Cop::RSpec::RepeatedExample do
|
|
47
47
|
RUBY
|
48
48
|
end
|
49
49
|
|
50
|
+
it 'does not flag examples when different its arguments are used' do
|
51
|
+
expect_no_violations(<<-RUBY)
|
52
|
+
describe 'doing x' do
|
53
|
+
its(:x) { is_expected.to be_present }
|
54
|
+
its(:y) { is_expected.to be_present }
|
55
|
+
end
|
56
|
+
RUBY
|
57
|
+
end
|
58
|
+
|
50
59
|
it 'does not flag repeated examples in different scopes' do
|
51
60
|
expect_no_violations(<<-RUBY)
|
52
61
|
describe 'doing x' do
|
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.11.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: 2017-
|
13
|
+
date: 2017-02-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- config/default.yml
|
146
146
|
- lib/rubocop-rspec.rb
|
147
147
|
- lib/rubocop/cop/rspec/any_instance.rb
|
148
|
+
- lib/rubocop/cop/rspec/around_block.rb
|
148
149
|
- lib/rubocop/cop/rspec/be_eql.rb
|
149
150
|
- lib/rubocop/cop/rspec/cop.rb
|
150
151
|
- lib/rubocop/cop/rspec/describe_class.rb
|
@@ -196,6 +197,7 @@ files:
|
|
196
197
|
- spec/project/default_config_spec.rb
|
197
198
|
- spec/project/project_requires_spec.rb
|
198
199
|
- spec/rubocop/cop/rspec/any_instance_spec.rb
|
200
|
+
- spec/rubocop/cop/rspec/around_block_spec.rb
|
199
201
|
- spec/rubocop/cop/rspec/be_eql_spec.rb
|
200
202
|
- spec/rubocop/cop/rspec/cop_spec.rb
|
201
203
|
- spec/rubocop/cop/rspec/describe_class_spec.rb
|
@@ -269,6 +271,7 @@ test_files:
|
|
269
271
|
- spec/project/default_config_spec.rb
|
270
272
|
- spec/project/project_requires_spec.rb
|
271
273
|
- spec/rubocop/cop/rspec/any_instance_spec.rb
|
274
|
+
- spec/rubocop/cop/rspec/around_block_spec.rb
|
272
275
|
- spec/rubocop/cop/rspec/be_eql_spec.rb
|
273
276
|
- spec/rubocop/cop/rspec/cop_spec.rb
|
274
277
|
- spec/rubocop/cop/rspec/describe_class_spec.rb
|