Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fix a false positive for `RSpec/ReceiveNever` cop when `allow(...).to receive(...).never`. ([@ydah])
- Fix detection of nameless doubles with methods in `RSpec/VerifiedDoubles`. ([@ushi-as])
- Improve an offense message for `RSpec/RepeatedExample` cop. ([@ydah])
- Improve `RSpec/MultipleExpectations` message to suggest using `aggregate_failures`. ([@svgr-slth])
- Let `RSpec/SpecFilePathFormat` leverage ActiveSupport inflections when configured. ([@corsonknowles], [@bquorning])

## 3.7.0 (2025-09-01)
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/rspec/multiple_expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ module RSpec
# end
#
class MultipleExpectations < Base
MSG = 'Example has too many expectations [%<total>d/%<max>d].'
MSG = 'Example has too many expectations [%<total>d/%<max>d]. ' \
'Consider using `aggregate_failures` if these expectations are logically related.'

ANYTHING = ->(_node) { true }
TRUE_NODE = lambda(&:true_type?)
Expand Down
20 changes: 10 additions & 10 deletions spec/rubocop/cop/rspec/multiple_expectations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
expect_offense(<<~RUBY)
describe Foo do
it 'uses expect twice' do
^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1]. Consider using `aggregate_failures` if these expectations are logically related.
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
Expand All @@ -34,7 +34,7 @@
expect_offense(<<~RUBY)
describe Foo do
it 'uses expect_any_instance_of twice' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1]. Consider using `aggregate_failures` if these expectations are logically related.
expect_any_instance_of(Foo).to receive(:bar)
expect_any_instance_of(Foo).to receive(:baz)
end
Expand All @@ -46,7 +46,7 @@
expect_offense(<<~RUBY)
describe Foo do
it 'uses expect_any_instance_of twice' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1]. Consider using `aggregate_failures` if these expectations are logically related.
is_expected.to receive(:bar)
is_expected.to receive(:baz)
end
Expand All @@ -58,7 +58,7 @@
expect_offense(<<~RUBY)
describe Foo do
it 'uses expect with block twice' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1]. Consider using `aggregate_failures` if these expectations are logically related.
expect { something }.to change(Foo.count)
expect { something }.to change(Bar.count)
end
Expand All @@ -83,7 +83,7 @@
expect_offense(<<~RUBY)
describe Foo do
it 'has multiple aggregate_failures calls' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1]. Consider using `aggregate_failures` if these expectations are logically related.
aggregate_failures do
end
aggregate_failures do
Expand Down Expand Up @@ -143,7 +143,7 @@
expect_offense(<<~RUBY)
describe Foo, aggregate_failures: true do
it 'uses expect twice', aggregate_failures: false do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1]. Consider using `aggregate_failures` if these expectations are logically related.
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
Expand All @@ -155,7 +155,7 @@
expect_offense(<<~RUBY)
describe Foo do
it 'uses expect twice', aggregate_failures: false do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1]. Consider using `aggregate_failures` if these expectations are logically related.
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
Expand All @@ -167,7 +167,7 @@
expect_offense(<<~RUBY)
describe Foo, aggregate_failures: false do
it 'uses expect twice' do
^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1]. Consider using `aggregate_failures` if these expectations are logically related.
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
Expand All @@ -179,7 +179,7 @@
expect_offense(<<~RUBY)
describe Foo do
it 'uses expect twice' do
^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1].
^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [2/1]. Consider using `aggregate_failures` if these expectations are logically related.
expect(foo).to eq(bar)
expect(baz).to eq(bar)
end
Expand Down Expand Up @@ -228,7 +228,7 @@
expect_offense(<<~RUBY)
describe Foo do
it 'uses expect three times' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [3/2].
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Example has too many expectations [3/2]. Consider using `aggregate_failures` if these expectations are logically related.
expect(foo).to eq(bar)
expect(baz).to eq(bar)
expect(qux).to eq(bar)
Expand Down