开发者

checking attribute of a tag with a regex using rspec

开发者 https://www.devze.com 2023-02-27 05:57 出处:网络
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.

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")
0

精彩评论

暂无评论...
验证码 换一张
取 消