Ruby Forum RSpec > Matching Rails response to visible text

Posted by Sean DeNigris (Guest)
on 25.02.2010 21:11
(Received via mailing list)
Hi,

I did a bit of experimenting/Googling for what seems like a common
operation, but didn't like what I found (mostly hand-rolled
regexes)...

I want to verify response text, but don't care about the structure.
The text happens to be in a table, but appears to the user as pure
text.

E.g. table with columns first_name = "Jim" and last_name = "Johnson"
looks to the reader like "Jim Johnson"
I want to say something like response.should include_text("Jim
Johnson"), but the html tags throw the match off.

Any suggestions?

Sean
Posted by Sean DeNigris (Guest)
on 25.02.2010 21:30
(Received via mailing list)
Never mind, found it in the webrat specs 10 seconds after I posted...
guess it's time for a break, lol...

response.should contain 'Jim Johnson'

- Sean
Posted by David Chelimsky (Guest)
on 25.02.2010 21:31
(Received via mailing list)
On Thu, Feb 25, 2010 at 1:57 PM, Sean DeNigris <sean@clipperadams.com> 
wrote:
> E.g. table with columns first_name = "Jim" and last_name = "Johnson"
> looks to the reader like "Jim Johnson"
> I want to say something like response.should include_text("Jim
> Johnson"), but the html tags throw the match off.
>
> Any suggestions?

Use the webrat contain matcher:

response.body.should contain("Jim Johnson")