Skip to content

Commit

Permalink
Add code review feedback, this feat works only ruby version > 1.8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlHeitmann committed May 25, 2024
1 parent b993756 commit 4c22e70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/rspec/support/differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def diff(actual, expected)
diff = diff_as_string(coerce_to_string(actual), coerce_to_string(expected))
end
elsif no_procs_and_no_numbers?(actual, expected)
if Hash === expected && hash_with_anything?(expected)
if (RUBY_VERSION.to_f > 1.8) && hash_with_anything?(expected)
diff = diff_as_object_with_anything(actual, expected)
else
diff = diff_as_object(actual, expected)
Expand Down Expand Up @@ -85,7 +85,7 @@ def initialize(opts={})
private

def hash_with_anything?(arg)
safely_flatten(arg).any? { |a| RSpec::Mocks::ArgumentMatchers::AnyArgMatcher === a }
Hash === arg && safely_flatten(arg).any? { |a| RSpec::Mocks::ArgumentMatchers::AnyArgMatcher === a }
end

def no_procs_and_no_numbers?(*args)
Expand Down
33 changes: 18 additions & 15 deletions spec/rspec/support/differ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,21 +556,24 @@ def inspect; "<BrokenObject>"; end
end
end

describe "fuzzy matcher anything" do
it "outputs only key value pair that triggered diff, anything_key should absorb actual value" do
actual = { :fixed => "fixed", :trigger => "trigger", :anything_key => "bcdd0399-1cfe-4de1-a481-ca6b17d41ed8" }
expected = { :fixed => "fixed", :trigger => "wrong", :anything_key => anything }
diff = differ.diff(actual, expected)
expected_diff = dedent(<<-'EOD')
|
|@@ -1,4 +1,4 @@
| :anything_key => "bcdd0399-1cfe-4de1-a481-ca6b17d41ed8",
| :fixed => "fixed",
|-:trigger => "wrong",
|+:trigger => "trigger",
|
EOD
expect(diff).to be_diffed_as(expected_diff)
unless RUBY_VERSION == '1.8.7'
describe "fuzzy matcher anything" do
it "outputs only key value pair that triggered diff, anything_key should absorb actual value" do
actual = { :fixed => "fixed", :trigger => "trigger", :anything_key => "bcdd0399-1cfe-4de1-a481-ca6b17d41ed8" }
expected = { :fixed => "fixed", :trigger => "wrong", :anything_key => anything }
diff = differ.diff(actual, expected)
expected_diff = dedent(<<-'EOD')
|
|@@ -1,4 +1,4 @@
| :anything_key => "bcdd0399-1cfe-4de1-a481-ca6b17d41ed8",
| :fixed => "fixed",
|-:trigger => "wrong",
|+:trigger => "trigger",
|
EOD
# puts diff
expect(diff).to be_diffed_as(expected_diff)
end
end
end
end
Expand Down

0 comments on commit 4c22e70

Please sign in to comment.