Skip to content

Instantly share code, notes, and snippets.

@KarlHeitmann
Last active May 10, 2024 03:25
Show Gist options
  • Save KarlHeitmann/460639ccf4de0ec249f1d34b300ebe56 to your computer and use it in GitHub Desktop.
Save KarlHeitmann/460639ccf4de0ec249f1d34b300ebe56 to your computer and use it in GitHub Desktop.
RSpec::Support spec AFTER changes
# spec results AFTER 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:
# NOTE: notice how the value associated to :anything_key _morphs_ into the value of actual[:anything_key], the value morphed because it is a `anything` fuzzy matcher. It does not add _noise_ to the diff, compared to the example here: https://gist.github.com/KarlHeitmann/e8fd6506eec82513656e2ea484301171
=begin
@@ -1,4 +1,4 @@
: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 => "dummy",
:fixed => "fixed",
-:nested => {:anything_key=>"bcdd0399-1cfe-4de1-a481-ca6b17d41ed8", :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 => "dummy",
:fixed => "fixed",
-:nested => {:nested_anything_key=>"9930ddcb-1cfe-4de1-a481-ca6b17d41ed8", :subnested=>{:name=>"foo", :subnested_anything_key=>"bcdd0399-1cfe-4de1-a481-ca6b17d41ed8", :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