On 7 December 2010 18:19, Jim Burgess <li...@ruby-forum.com> wrote: > Hi, > > 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. > > 1) Failure: > test_should_display_airport_names_in_show(FlightsControllerTest) > [/test/functional/flights_controller_test.rb:75]: > <"DUS"> expected but was > <"Nr:\n RA447">. > <false> 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. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.