How would I use assert select to test for the occurrence of the string
‘DUS’ in a ‘p’ tag about half way down my view?
I tried:
def test_should_display_airport_names_in_show
get :show, :id => flights(:dus_muc).id
assert_select ‘p’, ‘DUS’
end
but Rails is just finding the first ‘p’ tag (which isn’t the one I’m
looking for) and returning false.
Failure:
test_should_display_airport_names_in_show(FlightsControllerTest)
[/test/functional/flights_controller_test.rb:75]:
<“DUS”> expected but was
<“Nr:\n RA447”>.
is not true.
but Rails is just finding the first ‘p’ tag (which isn’t the one I’m
looking for) and returning false.
Failure:
test_should_display_airport_names_in_show(FlightsControllerTest)
[/test/functional/flights_controller_test.rb:75]:
<“DUS”> expected but was
<“Nr:\n RA447”>.
is not true.
The error is a little misleading. Your assert_select will return true
if any p tag contains (exactly) DUS. When it fails it just shows
the contents of the first which is not very helpful. Note that the
tag must contain exactly DUS. Any extra spaces or newlines or
whatever will cause it to fail. You can provide a regular expression
instead of a string to allow more complex checks.