Skip to content

Conversation

@nzlaura
Copy link
Contributor

@nzlaura nzlaura commented Oct 30, 2025

This PR adding support for correcting response assertions alongside other minitest assertions.

I have used Struct for the actual param for this assertion, because the "actual" is the test-local @response property, and the way the minitests are initialised require actual to be passed as a param.


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

@nzlaura
Copy link
Contributor Author

nzlaura commented Oct 30, 2025

@G-Rath

Copy link
Contributor

@G-Rath G-Rath left a comment

Choose a reason for hiding this comment

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

looks good to me!

Comment on lines 330 to 331
response = Struct.new(:source).new('response')
new(expected, response, failure_message.first)
Copy link
Contributor

Choose a reason for hiding this comment

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

note: we're using Struct here because the "actual" for this assertion is the test-local @response property - I think this is a good solution especially as BasicAssertion immediately calls source and stores that value rather than holding any further reference to the actual parameter, though I wouldn't be surprised if there is a Rubocop helper for these situations that we could use instead

Copy link
Contributor

Choose a reason for hiding this comment

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

That’s clever 😅 Maybe it’s a sign that we should pass the actual source values for actual and expected instead of the Node instances. But let’s do that in a later PR.

Could I get you to extract the response struct into a constant, so we don’t define it over and over?

end
end

context 'with response assertions' do

This comment was marked as resolved.

@nzlaura nzlaura force-pushed the fix/add-assert-response branch from d558a4d to aed0581 Compare November 2, 2025 23:16
@nzlaura nzlaura marked this pull request as ready for review November 2, 2025 23:17
@nzlaura nzlaura requested a review from a team as a code owner November 2, 2025 23:17
Copy link
Contributor

@bquorning bquorning left a comment

Choose a reason for hiding this comment

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

Hi @nzlaura and thank you for the pull request 🙏🏼

I added a comment on the code, and have two more requests:

  1. It looks like you are using Ruby 3.3 or older, which results in the diff on docs/modules/ROOT/pages/cops_rspecrails.adoc (foo => barfoo=>bar). CI runs Ruby 3.4, which is why it currently fails. (Yes, pPerhaps we should add a .ruby-version file to the repo.)
  2. Could you squash your commits, please? I think all (currently) 6 commits are part of the same “unit of work” and are best described & reviewed together.

Comment on lines 330 to 331
response = Struct.new(:source).new('response')
new(expected, response, failure_message.first)
Copy link
Contributor

Choose a reason for hiding this comment

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

That’s clever 😅 Maybe it’s a sign that we should pass the actual source values for actual and expected instead of the Node instances. But let’s do that in a later PR.

Could I get you to extract the response struct into a constant, so we don’t define it over and over?

@nzlaura nzlaura force-pushed the fix/add-assert-response branch from aed0581 to fc0cfc1 Compare November 3, 2025 20:47
@nzlaura
Copy link
Contributor Author

nzlaura commented Nov 3, 2025

Thanks for the quick review @bquorning 😄

I've shifted the response struct into a constant, changed to using Ruby 3.4 locally and re run the rake generate_cops_documentation command, and squashed all of the commits!

Copy link
Contributor

@bquorning bquorning left a comment

Choose a reason for hiding this comment

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

Looks good, thank you for the PR.

@ydah Would you want to take a look as well?

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!

@ydah ydah merged commit 62d77f8 into rubocop:master Nov 3, 2025
27 checks passed
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.

4 participants