liangzai-cool / hamcrest

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

SubstringMatcher should cast objects to string before passing to TypeSafeMatcher #162

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If you want to enforce that a value is an actual string, use stringValue(). 
When you have an object you probably want to test the result of __toString() 
without having to cast it yourself. This should be automatic.

The problem is that you get bogus failure messages saying that two equal 
strings are not equal because _isSafeType() returns false but 
describeMismatch() doesn't take that into account.

It looks like the fix could be applied to _isSafeType() by returning true for 
objects when the desired type is string, perhaps only when they have a 
__toString() method.

Original issue reported on code.google.com by dharkn...@gmail.com on 27 Sep 2011 at 7:38

GoogleCodeExporter commented 9 years ago
Doesn't hasToString() suffice for casting objects to string? Should this 
instead be fixed to fail for all objects?

Original comment by dharkn...@gmail.com on 3 Feb 2012 at 1:13