Closed janpieper closed 6 years ago
How about this?
expect(Map.take(map, ["foo"])).to eq(%{"foo" => "bar"})
Hi @janpieper ! You can pass tuple to the 'have' matcher.
expect(map).to have({:foo, "bar"})
expect(map).to have({"foo", "bar"})
I've added these examples to Readme too. Thank you!
Yeah, that looks great! Thank you!
Problem
Using the
have
matcher for maps with atom keys is great:But what to do when the map has string keys?
"Solutions"?
match_pattern
Works great, but
match_pattern
is not meant to be used for such a case and in casemap
does not contain this pattern, the error message contains the whole map and gets unreadable.have_key
+have_value
Nice idea, but can cause false positives when
bar
is not the value offoo
.have_key
+eq
Great alternative and works fine, but feels like a bit too much code for such a simple check.
eq
Yay, works fine, but gets ugly when you have a big map or dynamic values you do not know.
Question
Is there a good way to to check whether a map with string keys has a key-value-pair? Or do we need a new matcher for this case (e.g.
have_key_value_pair
orhave_key_with_value
, or ...)?