Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (32 sloc) 2.16 KB
---
have_tag: |-
response.should have_tag("li")
response.should have_tag("li", :text => "I'm a list item")
response.should have_tag("li.my_class", :text => "I'm a list item")
response.should have_tag("li#my_element_id", :text => "I'm a list item")
response.should have_tag("li#my_element_id.my_class", :text => "I'm a list item")
response.should have_tag("img[alt=My accessible text]")
response.should have_tag("img[alt~=readable accessible usable]") # Match any of these words
response.should have_tag("img[alt^=My]") # Match attribute beginning with "My"
response.should have_tag("img[alt$=text]") # Match attribute ending with "text"
response.should have_tag("img[alt*=essibl]") # Match "essibl" anywhere in attribute
response.should have_tag("img[alt]") # Match any img element with alt attribute
response.should have_tag("li:nth-child(2)", :text => "I'm element 2")
response.should have_tag("li:nth-last-child(2)", :text => "I'm element 4")
response.should have_tag("ul:first-child", :text => "I'm element 1")
response.should have_tag("ul:last-child", :text => "I'm element 5")
response.should have_tag("p:nth-of-type(2)", :text => "I'm going to describe the list below")
response.should have_tag("li:nth-last-of-type(2)", :text => "I'm list 2")
response.should have_tag("p:first-of-type", :text => "I've got some paragraph text")
response.should have_tag("p:last-of-type", :text => "I'm going to describe the list below")
response.should have_tag("li:nth-of-type(3n+1).highlight", :count => 3)
response.should have_tag("li:nth-of-type(3n+1).highlight", :maximum => 4)
response.should have_tag("li:nth-of-type(3n+1).highlight", :minimum => 1)
response.should have_tag("li:nth-of-type(3n+1).highlight", 1..4)
response.should have_tag "form[action=/sessions]" do
with_tag "input[type=text][name=username]"
with_tag "input[type=password][name=password]"
end
This uses the examples from http://rubypond.com/articles/2008/03/31/using-rspec-have_tag/
Make sure there is a certain link on the site:
response.should have_tag("a[href=?]", "http://somewebsite.com/interesting")