Read more

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

Henning Koch
July 07, 2011Software engineer at makandra GmbH

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
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot
Posted by Henning Koch to makandra dev (2011-07-07 16:00)