How to check if text appears on page in rails functional test?
Without specifying a tag:
assert_match "this is the test line", response.body
I think you're just looking for:
assert_select "p", "this is the test line"
See the docs for more info about assert_select
.
Note that the line above depends on the text being wrapped in a <p>
tag, and being a literal match. If it's in another tag, you'll need to specify the correct selector. If you'd like to match on a Regex, that is also supported, via:
assert_select "p", /test line/
Note that this will not be very performant, as it will scan through all <p>
's in your document. Consider a more tightly specified selector, like a class or ID on the element you're targeting.