Skip to content

Commit d1cf5eb

Browse files
committed
Ignore example groups with pending examples
Found hundreds of offences in real-world-rspec
1 parent 0d5e03d commit d1cf5eb

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Add `RSpec/RepeatedIncludeExample` cop. ([@biinari][])
77
* Fix `RSpec/FilePath` when checking a file with a shared example. ([@pirj][])
88
* Fix subject nesting detection in `RSpec/LeadingSubject`. ([@pirj][])
9+
* Fix false positives in `RSpec/EmptyExampleGroup`. ([@pirj][])
910

1011
## 1.43.1 (2020-08-17)
1112

docs/modules/ROOT/pages/cops_rspec.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,11 @@ describe Bacon do
739739
expect(bacon.chunky?).to be_truthy
740740
end
741741
end
742+
743+
# good
744+
describe Bacon do
745+
pending 'will add tests later'
746+
end
742747
----
743748

744749
==== configuration

lib/rubocop/cop/rspec/empty_example_group.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ module RSpec
3333
# end
3434
# end
3535
#
36+
# # good
37+
# describe Bacon do
38+
# pending 'will add tests later'
39+
# end
40+
#
3641
# @example configuration
3742
#
3843
# # .rubocop.yml
@@ -83,11 +88,14 @@ class EmptyExampleGroup < Base
8388
# it_behaves_like 'an animal'
8489
# it_behaves_like('a cat') { let(:food) { 'milk' } }
8590
# it_has_root_access
91+
# skip
92+
# it 'will be implemented later'
8693
#
8794
# @param node [RuboCop::AST::Node]
8895
# @return [Array<RuboCop::AST::Node>] matching nodes
8996
def_node_matcher :example_or_group_or_include?, <<~PATTERN
9097
{
98+
#{Examples::ALL.send_pattern}
9199
#{Examples::ALL.block_pattern}
92100
#{ExampleGroups::ALL.block_pattern}
93101
#{Includes::ALL.send_pattern}

spec/rubocop/cop/rspec/empty_example_group_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,36 @@
226226
RUBY
227227
end
228228
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
229261
end

0 commit comments

Comments
 (0)