Open dmolesUC opened 2 years ago
FWIW, the ridiculous workaround I've come up with as a temporary hack to debug failing tests is this:
context 'as string map values' do
it 'is equal' do
d1s = d1.map(&:inspect)
d2s = d2.map(&:inspect)
expect(d1s.map { |v| { v: v } }).to eq(d2s.map { |v| { v: v } })
end
end
Which produces the at-least-somewhat-readable array diff:
[{:v=>"ModuleWithALongName::ClassWithALongName<value: 0>"},
+ {:v=>"ModuleWithALongName::ClassWithALongName<value: 1>"},
{:v=>"ModuleWithALongName::ClassWithALongName<value: 2>"},
- {:v=>"ModuleWithALongName::ClassWithALongName<value: 2>"},
{:v=>"ModuleWithALongName::ClassWithALongName<value: 3>"},
- {:v=>"ModuleWithALongName::ClassWithALongName<value: 8>"}]
+ {:v=>"ModuleWithALongName::ClassWithALongName<value: 4>"}]
Can you dig why it was done initially? I found "Extract diffing code from expectations to support" commit, and it leads to a different repo.
@pirj See this commit in rspec-expectations (also linked above). Note that the code was in fail_with.rb at that time.
Ah, sorry, I've missed this. The original reasoning of not showing such diffs:
-that
+this
doesn't really apply to string arrays.
Would you like to submit a PR?
@pirj Done.
Subject of the issue
When comparing two arrays of objects, Differ provides a useful report on which expected objects are missing and which unexpected objects are present. When comparing two arrays of strings, however, the array diff is omitted and only the truncated
inspect
diff is present.Looking at the source code, it appears this was sort of intentional; but on the other hand it looks as though the original change back in 2010 was only intended to make sure the multiline differ wasn't applied to single-line strings. Ignoring all single-line string arrays just seems to have been a side effect.
Your environment
Steps to reproduce
Run the following (failing) spec:
Expected behavior
Failure messages for both tests should show the array diff.
Actual behavior
Only the failure message for
as objects
shows the array diff.