Skip to content

Commit 455e336

Browse files
committed
Document aggregate_failures behavior in MultipleExpectations cop
Rspec/MultipleExpectations supports :aggregate_failures by simply ignoring any blocks enclosed in them. The only issue is that they don't really appear in any of the docs so the behavior is mostly hidden. This update merely adds two inline examples to RSpec/MultipleExpectations to allow for greater discoverability.
1 parent b6516ba commit 455e336

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Add new `RSpec/Capybara/SpecificMatcher` cop. ([@ydah][])
88
* Fixed false offense detection in `FactoryBot/CreateList` when a n.times block is including method calls in the factory create arguments. ([@ngouy][])
99
* Fix error in `RSpec/RSpec/FactoryBot/CreateList` cop for empty block. ([@tejasbubane][])
10+
* Update `RSpec/MultipleExpectations` cop documentation with examples of aggregate_failures use. ([@edgibbs][])
1011

1112
## 2.11.1 (2022-05-18)
1213

@@ -702,3 +703,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
702703
[@luke-hill]: https://github.com/luke-hill
703704
[@johnny-miyake]: https://github.com/johnny-miyake
704705
[@ngouy]: https://github.com/ngouy
706+
[@edgibbs]: https://github.com/edgibbs

docs/modules/ROOT/pages/cops_rspec.adoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,32 @@ describe UserCreator do
28372837
end
28382838
----
28392839

2840+
==== `aggregate_failures: true` (default)
2841+
2842+
[source,ruby]
2843+
----
2844+
# good - the cop ignores when RSpec aggregates failures
2845+
describe UserCreator do
2846+
it 'builds a user', :aggregate_failures do
2847+
expect(user.name).to eq("John")
2848+
expect(user.age).to eq(22)
2849+
end
2850+
end
2851+
----
2852+
2853+
==== `aggregate_failures: false`
2854+
2855+
[source,ruby]
2856+
----
2857+
# Detected as an offense
2858+
describe UserCreator do
2859+
it 'builds a user', aggregate_failures: false do
2860+
expect(user.name).to eq("John")
2861+
expect(user.age).to eq(22)
2862+
end
2863+
end
2864+
----
2865+
28402866
==== configuration
28412867

28422868
[source,ruby]

lib/rubocop/cop/rspec/multiple_expectations.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ module RSpec
3131
# end
3232
# end
3333
#
34+
# @example `aggregate_failures: true` (default)
35+
#
36+
# # good - the cop ignores when RSpec aggregates failures
37+
# describe UserCreator do
38+
# it 'builds a user', :aggregate_failures do
39+
# expect(user.name).to eq("John")
40+
# expect(user.age).to eq(22)
41+
# end
42+
# end
43+
#
44+
# @example `aggregate_failures: false`
45+
#
46+
# # Detected as an offense
47+
# describe UserCreator do
48+
# it 'builds a user', aggregate_failures: false do
49+
# expect(user.name).to eq("John")
50+
# expect(user.age).to eq(22)
51+
# end
52+
# end
53+
#
3454
# @example configuration
3555
#
3656
# # .rubocop.yml

0 commit comments

Comments
 (0)