-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toContain matcher for Map #42
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like both matcher style and output!
Two comments I think need to be addressed (formatters + negative test case). The other are minor.
message += failingValues.map(p => s"${p._1} -> ${p._2} but found ${p._1} -> ${p._3}").mkString("\n ") | ||
expect.fail(message) | ||
|
||
private def describeActualWithContext(actual: Map[K, V]): String = "Map(...)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not much context here... ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope =)
What is a good context for a Map? Map(of 23 entries)
,Map[K, V]
or to print a few keys (similar to Seq, and using the same cutoff
)?
"when negated": | ||
"error is described properly also for multiple elements" in: | ||
runExpectation( | ||
expect(Map("one" -> 1, "two" -> 2)).not.toContainAllOf("one" -> 1, "two" -> 2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to have a test for the negation of toContainAllOf
where:
- Actual is one->1, two->2
- Expected is one->1, three->3
In the positive case, this should be a failure, since actual doesn't contain three->3. Thus the negative case should be a success, I think. Does it work like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disagree. To not contain all of, should fail if >0 pairs are present in the Map.
Still, adding such a test case would be good, just with a slightly different result than what you propose ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, new year, new thoughts =)
I revisited this and I agree with your view and will add the following tests:
"when partially matching":
"error is described properly" in:
runExpectation(
expect(Map("one" -> 1, "two" -> 2)).toContainAllOf("one" -> 1, "three" -> 3),
"""Expected Map(...) to contain:
| "three" -> 3""".stripMargin)
"and negating":
"should pass since Map is not missing both pairs" in:
expect(Map("one" -> 1, "two" -> 2)).not.toContainAllOf("one" -> 1, "three" -> 3)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a9a5f01
See PR #42 for additional rationale
Initial work to support
.toContain
and.toContainAllOf
for Map.@provegard, what do you think of the matcher style, and the output?
Still needed (although in separate PR's):
Support for mutable MapPart of #36