Rspec 2 - class name inside the tag
I have the following html code:
<ul class="nav"> <li class="active"> <a href="/users/page">Page</a> </li> ... </ul>
I want to make sure that I have a li tag with the class "active" and inside this text.
So I tried:
response.should have_selector( "li", :class => "active" ,:content => "Page")
And this does not work, I get this error:
Failure/Error: response.should have_selector( "li", :class => "active" ,:content => "Page") expected following output to contain a <li class='active'>Page</li> tag:
How can I solve my problem?
+6
3 answers
We had similar problems with testing Watir, in that: class matcher - exact match of strings; not like a CSS class selector at all.
Our solution was to switch to the xpath selector, for example:
response.should have_selector("li", :xpath => 'contains(@class, "active")')
Disclaimer: I was not able to verify the above code; I am just showing how we used 'contains' against the @class attribute to match partial class lines.
0