Yule
Yule

Reputation: 9754

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:

attribute.should =~ /regex/

Upvotes: 2

Views: 1723

Answers (2)

Will Ayd
Will Ayd

Reputation: 7164

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

Upvotes: 1

Dogbert
Dogbert

Reputation: 222118

You can use the CSS3 Substring matching attribute selectors for this case.

rendered.should have_selector 'a[href$=.pdf]'

Upvotes: 2

Related Questions