File tree Expand file tree Collapse file tree 4 files changed +84
-0
lines changed Expand file tree Collapse file tree 4 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 6
6
* Add ` RSpec/RepeatedIncludeExample ` cop. ([ @biinari ] [ ] )
7
7
* Fix ` RSpec/FilePath ` when checking a file with a shared example. ([ @pirj ] [ ] )
8
8
* Fix subject nesting detection in ` RSpec/LeadingSubject ` . ([ @pirj ] [ ] )
9
+ * Fix false positives in ` RSpec/EmptyExampleGroup ` . ([ @pirj ] [ ] )
9
10
10
11
## 1.43.1 (2020-08-17)
11
12
Original file line number Diff line number Diff line change @@ -739,6 +739,11 @@ describe Bacon do
739
739
expect(bacon.chunky?).to be_truthy
740
740
end
741
741
end
742
+
743
+ # good
744
+ describe Bacon do
745
+ pending 'will add tests later'
746
+ end
742
747
----
743
748
744
749
==== configuration
Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ module RSpec
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 @@ class EmptyExampleGroup < Base
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,6 +160,9 @@ class EmptyExampleGroup < Base
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
167
add_offense ( node . send_node ) unless examples? ( body )
157
168
end
Original file line number Diff line number Diff line change 226
226
RUBY
227
227
end
228
228
end
229
+
230
+ it 'ignores example groups with pending examples' do
231
+ expect_no_offenses ( <<~RUBY )
232
+ describe Foo do
233
+ it 'will be implemented later'
234
+ end
235
+
236
+ describe Foo do
237
+ it 'will be implemented later', year: 2030
238
+ end
239
+
240
+ describe Foo do
241
+ pending
242
+ end
243
+
244
+ describe Foo do
245
+ pending 'too hard to specify'
246
+ end
247
+
248
+ describe Foo do
249
+ skip
250
+ end
251
+
252
+ describe Foo do
253
+ skip 'undefined behaviour'
254
+ end
255
+
256
+ xdescribe Foo
257
+
258
+ describe Foo
259
+ RUBY
260
+ end
261
+
262
+ it 'ignores example groups defined inside methods' do
263
+ expect_no_offenses ( <<~RUBY )
264
+ RSpec.describe Foo do
265
+ def self.with_yaml_loaded(&block)
266
+ context 'with YAML loaded' do
267
+ module_exec(&block)
268
+ end
269
+ end
270
+
271
+ class << self
272
+ def without_yaml_loaded(&block)
273
+ context 'without YAML loaded' do
274
+ module_exec(&block)
275
+ end
276
+ end
277
+ end
278
+
279
+ with_yaml_loaded do
280
+ it_behaves_like 'normal YAML serialization'
281
+ end
282
+ end
283
+ RUBY
284
+ end
285
+
286
+ it 'ignores example groups inside examples' do
287
+ expect_no_offenses ( <<~RUBY )
288
+ RSpec.describe 'rspec-core' do
289
+ it 'runs an example group' do
290
+ group = RSpec.describe { }
291
+ group.run
292
+ end
293
+ end
294
+ RUBY
295
+ end
229
296
end
You can’t perform that action at this time.
0 commit comments