Open stoivo opened 1 month ago
I did a little bit of digging and I think we might have to patch https://github.com/rspec/rspec-expectations/blob/main/lib/rspec/expectations/handler.rb#L32-L42 too. I think this is the closed point where we have access to which matcher we have used.
I put a puts caller[0..10]
in RSpec::Support::Differ.diff
to see callstack
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/matchers/expecteds_for_multiple_diffs.rb:70:in `block in diffs'
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/matchers/expecteds_for_multiple_diffs.rb:69:in `map'
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/matchers/expecteds_for_multiple_diffs.rb:69:in `diffs'
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/matchers/expecteds_for_multiple_diffs.rb:48:in `message_with_diff'
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/fail_with.rb:33:in `fail_with'
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/handler.rb:38:in `handle_failure'
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/handler.rb:56:in `block in handle_matcher'
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/handler.rb:27:in `with_matcher'
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/expectation_target.rb:65:in `to'
/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/expectation_target.rb:101:in `to'
Improve diff when using match RSpec matcher
Given the following test
We get the following output
If we add
"cre" => "2",
to the expectation it passesSame thing for BigDecimal
Same thing for Comparing against class
Proposal It would be nice if we could hide
new value: "created_at" (/\d+/ -> "2024")
from the diff since it is actually matching. Current diffing logic don't take which matcher into accountOther notes If we figure out how we can get which matcher was i use we might want to make some changed to how we represent include diff?
include matcher also uses this diff which isn't good