Improving failed change assert message

10 views
Skip to first unread message

Augusts Bautra

unread,
Oct 30, 2025, 6:36:09 AM (3 days ago) Oct 30
to rspec
Hello,

If a change assert fails we get a oneliner failure message like

expected `object.data` to have changed to { "key" => "value" }, but is now { "something" => "else" }

With a bulkier object (array of hashes, a large hash, it's common) the dividing part ", but is now" is hard to see.

Let's improve the readability of failures like this!

There are a number of ways to go about this, but one I've come up with is a three-line formatting - first describes the nature of the change failure (did not change/ changed to wrong value etc.), second shows expectation, and third shows the gotten value, aligned to the second row for easier diff, like so:

expected `object.data` to have changed, but the new value did not match expectation:
  expected: { "key" => "value" }
       was: { "something" => "else" } 

Is this something worth opening a PR for? Which github project should I look at?


Jon Rowe

unread,
Oct 30, 2025, 6:38:36 AM (3 days ago) Oct 30
to RSpec Google Group
We do this format for others changes so its certainly something to consider for larger diffs, the project is https://github.com/rspec/rspec with the matchers living within rspec-expectations and diffing tools in rspec-support.

Cheers
Jon
--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages