Skip to content

Instantly share code, notes, and snippets.

@KarlHeitmann
Last active May 10, 2024 03:25
Show Gist options
  • Save KarlHeitmann/e8fd6506eec82513656e2ea484301171 to your computer and use it in GitHub Desktop.
Save KarlHeitmann/e8fd6506eec82513656e2ea484301171 to your computer and use it in GitHub Desktop.
RSpec::Support spec BEFORE changes
# spec results BEFORE changes in PR 596: https://github.com/rspec/rspec-support/pull/596
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)
puts diff
# OUTPUT:
=begin
-:anything_key => anything,
+:anything_key => "bcdd0399-1cfe-4de1-a481-ca6b17d41ed8",
:fixed => "fixed",
-:trigger => "wrong",
+:trigger => "trigger",
=end
end
context "with nested hash" do
it "outputs only key value pair that triggered diff, anything_key should absorb actual value" do
actual = {
:an_key => "dummy",
:fixed => "fixed",
:nested => {
:anything_key => "bcdd0399-1cfe-4de1-a481-ca6b17d41ed8",
:name => "foo",
:trigger => "trigger"
}
}
expected = {
:an_key => anything,
:fixed => "fixed",
:nested => {
:anything_key => anything,
:name => "foo",
:trigger => "wrong"
}
}
diff = differ.diff(actual, expected)
puts diff
# OUTPUT:
=begin
@@ -1,4 +1,4 @@
-:an_key => anything,
+:an_key => "dummy",
:fixed => "fixed",
-:nested => {:anything_key=>anything, :name=>"foo", :trigger=>"wrong"},
+:nested => {:anything_key=>"bcdd0399-1cfe-4de1-a481-ca6b17d41ed8", :name=>"foo", :trigger=>"trigger"},
=end
end
end
context "with nested hash and subnested hash" do
it "outputs only key value pair that triggered diff, anything_key should absorb actual value" do
actual = {
:an_key => "dummy", :fixed => "fixed",
:nested => {
:subnested => {
:name => "foo",
:trigger => "trigger",
:subnested_anything_key => "bcdd0399-1cfe-4de1-a481-ca6b17d41ed8"
},
:nested_anything_key => "9930ddcb-1cfe-4de1-a481-ca6b17d41ed8"
}
}
expected = {
:an_key => anything, :fixed => "fixed",
:nested => {
:subnested => {
:name => "foo",
:trigger => "wrong",
:subnested_anything_key => anything
},
:nested_anything_key => anything
}
}
diff = differ.diff(actual, expected)
puts diff
# OUTPUT:
=begin
@@ -1,4 +1,4 @@
-:an_key => anything,
+:an_key => "dummy",
:fixed => "fixed",
-:nested => {:nested_anything_key=>anything, :subnested=>{:name=>"foo", :subnested_anything_key=>anything, :trigger=>"wrong"}},
+:nested => {:nested_anything_key=>"9930ddcb-1cfe-4de1-a481-ca6b17d41ed8", :subnested=>{:name=>"foo", :subnested_anything_key=>"bcdd0399-1cfe-4de1-a481-ca6b17d41ed8", :trigger=>"trigger"}},
=end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment