Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec 2 - name of class inside of tag

I have next html code:

<ul class="nav">
    <li class="active">
      <a href="/users/page">Page</a>
    </li>
    ...
</ul>

I want to make sure that i have li tag with class "active" and inside of that text.

So, i tried that:

response.should have_selector( "li", :class => "active" ,:content => "Page")

And it doesn't work, i get such 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?

like image 771
ExiRe Avatar asked Mar 07 '12 20:03

ExiRe


2 Answers

I think you can add the class to the css selector. Something like:

response.body.should have_selector( "li.active", :content => 'Page')
like image 125
THEM Avatar answered Oct 11 '22 11:10

THEM


I solved it:

response.body.should have_selector( "li.active") do
   have_selector('a', :content => 'Pages')
end
like image 31
ExiRe Avatar answered Oct 11 '22 10:10

ExiRe