Skip to content

Conversation

@svgr-slth
Copy link

Summary

This PR improves the RSpec/MultipleExpectations cop error message to proactively suggest using aggregate_failures as an alternative to splitting specs.

Before:
Example has too many expectations [2/1].

After:
Example has too many expectations [2/1]. Consider using `aggregate_failures` if these expectations are logically related.

Motivation

Developers often encounter this cop and default to splitting specs without realizing aggregate_failures is available. This enhancement educates users at the point of encounter, improving both developer experience and test suite quality.

Changes

Updated error message in RSpec::MultipleExpectations cop
Updated all test cases to expect the new message format

Fixes #2131

@svgr-slth svgr-slth requested a review from a team as a code owner November 12, 2025 11:06
Copy link
Member

@ydah ydah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work. But I believe this change is not appropriate, as the offense message does not apply when aggregate_failures: false is used.

@svgr-slth
Copy link
Author

svgr-slth commented Nov 12, 2025

No problem, i get that. Would adapting the message conditionally make you reconsider?

EDIT: Just made a small commit to show the message conditionally, I leave weather it's worth or not to your appreciation.

Best !

@svgr-slth svgr-slth requested a review from ydah November 13, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggest usage of aggregate_failures directly in RSpec/MultipleExpectation error message

2 participants