jocarreira / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

Add rich diffing support for error output #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Extract all error description logic into a "describeMismatch" method then
let each matcher handle how it reports failure to user.

Provide a basic implementation (like the one in MatcherAssert) in
BaseMatcher but then allow extension for the more complex matchers (XPath,
Collections, Any, All) etc.

I suggest inheriting IndentedDescription from JMock 2 to allow nice nested
descriptions. I'd also like to tweak the error output a but. A rich error
report might look something like the following (I'm using hasXPath here as
an example here)

XPath expression did not return a result

Got          : <document blah>
Expectation  : has XPath "/document/title" that equals "mary had a little lamb"
But          : xpath expression did not return a result

XPath result didn't match expectation:

Got          : <document blah>
Expectation  : has XPath "/document/title" that equals "mary had a little lamb"
But          : xpath result did not match expecation ->

    Got         : "Mary had a little lambourghini"
    Expecation  : equals "Mary had a little lamb"
    But         : string differed at character 23 "...tle lamb***ourghini"

I've embellished a bit with the string diffing but it's very possible.

I'm happy to start cutting the code for this in a couple of weeks.

Original issue reported on code.google.com by neild...@gmail.com on 15 Dec 2006 at 12:14

GoogleCodeExporter commented 8 years ago

Original comment by joe.wal...@gmail.com on 22 Dec 2006 at 9:13

GoogleCodeExporter commented 8 years ago
I have added describeMismatch(Object item, Description description) to Matcher, 
added
a default implementation in BaseMatcher and a type safe version to 
TypeSafeMatcher.

It might be worth checking this in a reviewing it quickly before adding
describeMismatches all over the shop

Original comment by neild...@gmail.com on 1 Jun 2007 at 1:48

GoogleCodeExporter commented 8 years ago
Introduced and merged into HEAD

Original comment by smgfree...@gmail.com on 9 Oct 2008 at 10:34

GoogleCodeExporter commented 8 years ago
Awesome!

Original comment by nat.pr...@gmail.com on 9 Oct 2008 at 10:59