checking attribute of a tag with a regex using rspec
I'm fairly new to Rspec so apologies if this is a really simple question:
I want to check that there is some link on the page that has a link to a pdf.
Essentially something along the lines of:
rendered.should have_selector :a[href=~/\.pdf/]
but I'm getting the error undefined variable or method href.
Is there someway to do:
attribu开发者_如何学Pythonte.should =~ /regex/
You can use the CSS3 Substring matching attribute selectors for this case.
rendered.should have_selector 'a[href$=.pdf]'
using has_selector should do a substring match for you, so you could always try doing something like this:
response.should have_selector("a", :href => ".pdf")
精彩评论