Armando
Armando

Reputation: 622

Capybara find all links on page and check url

I want to check that all links on a page contain a certain element. This is the current web_step I have but it is not working. Any ideas?

Then /^all links above footer should countain "([^"]+)"$/ do |parameter|
  al = page.all('a')
  al.each do |i|
    i.include?(parameter).should be_true
  end
end

Upvotes: 2

Views: 4771

Answers (2)

Jon M
Jon M

Reputation: 11705

You probably need to assert against a particular attribute of each a element - if you're checking that the 'src' attribute contains 'parameter' then:

i[:href].include?(parameter).should be_true

Or, to make better use of the rspec matchers (and get better failure messages):

i[:href].should include parameter

Upvotes: 1

monfresh
monfresh

Reputation: 8056

[:src] no longer appears to work. Use [:href] instead.

Upvotes: 1

Related Questions