Closed pgoodwin closed 11 years ago
We have hasTextString
for this.
I am thinking of flipping the impls for a future version, though.
Whoa, that was fast. I looked for something like that. Not hard enough it seems. Thanks.
hasTextString
Doesn't seem to be on TextViewAssert
is there a snapshot release I can put in my pom.xml to get this?
On Thu, Mar 21, 2013 at 5:31 PM, Jake Wharton notifications@github.comwrote:
— Reply to this email directly or view it on GitHubhttps://github.com/square/fest-android/issues/49#issuecomment-15274937 .
It's in 1.0.3, the latest. On Mar 21, 2013 9:52 PM, "Phil Goodwin" notifications@github.com wrote:
is there a snapshot release I can put in my pom.xml to get this?
On Thu, Mar 21, 2013 at 5:31 PM, Jake Wharton notifications@github.comwrote:
— Reply to this email directly or view it on GitHub< https://github.com/square/fest-android/issues/49#issuecomment-15274937> .
— Reply to this email directly or view it on GitHubhttps://github.com/square/fest-android/issues/49#issuecomment-15281188 .
Sometimes fails with messages like: "Expected text but was "
This happens because the text is actually a CharSequence that doesn't compare nicely with String. In my case it was a SpannableStringBuilder. Maybe a nice way to fix this would be to check whether the 'text' parameter is actually a String and call toString() on actualText before doing the comparison:
public S hasText(CharSequence text) { isNotNull(); CharSequence actualText = actual.getText(); if (text instanceOf String) actualText = actualText.toString(); assertThat(actualText) // .overridingErrorMessage("Expected text <%s> but was <%s>.", text, actualText) // .isEqualTo(text); return myself; }
That way in the 1% case where someone really wants to ensure that a text field has some exact configuration of a SpannableStringBuilder as it's text they can still build one up and pass it in, while the rest of the time we'll get the String comparison we'd intuitively expect.