Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
code review feedback: invert expected_to_diff to actual_to_diff
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlHeitmann committed Jun 27, 2024
1 parent 938096c commit 7046659
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/rspec/support/differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,16 @@ def diff_as_string(actual, expected)

if defined?(RSpec::Mocks::ArgumentMatchers::AnyArgMatcher)
def diff_hashes_as_object(actual, expected)
expected_to_diff =
expected.reduce({}) do |hash, (key, value)|
if RSpec::Mocks::ArgumentMatchers::AnyArgMatcher === value
hash[key] = actual[key]
else
actual_to_diff =
actual.reduce({}) do |hash, (key, value)|
if RSpec::Mocks::ArgumentMatchers::AnyArgMatcher === expected[key]
hash[key] = expected[key]
else
hash[key] = actual[key]
end
hash
end

diff_as_object(actual, expected_to_diff)
diff_as_object(actual_to_diff, expected)
end
else
def diff_hashes_as_object(actual, expected)
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/support/differ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def inspect; "<BrokenObject>"; end
expected_diff = dedent(<<-'EOD')
|
|@@ -1,4 +1,4 @@
| :anything_key => "bcdd0399-1cfe-4de1-a481-ca6b17d41ed8",
| :anything_key => anything,
| :fixed => "fixed",
|-:trigger => "wrong",
|+:trigger => "trigger",
Expand Down

0 comments on commit 7046659

Please sign in to comment.