Test that a string of text is (not) linked in Webrat or Capybara

Updated . Posted . Visible to the public.

The step definition below allows you to write:

Then I should see a link labeled "Foo"
But I should not see a link labeled "Bar"

Webrat

Then /^I should( not)? see a link labeled "([^"]*)"$/ do |negate, label|
  expectation = negate ? :should_not : :should
  response.send(expectation, have_selector("a", :content => label))
end

Capybara

Then /^I should( not)? see a link labeled "([^"]*)"$/ do |negate, label|
  expectation = negate ? :should_not : :should
  page.send(expectation, have_css('a', :text => label))
end
Henning Koch
Last edit
Keywords
cucumber
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2011-07-07 14:00)