黄瓜和铁路:测试是否存在随机记录

时间:2013-01-08 21:06:25

标签: ruby-on-rails testing rspec cucumber capybara

我有一个应用程序显示一些内容,然后选择一个随机记录并显示它

我该如何测试?

Then /^I Should see the associated "([^']*)" "([^']*)"$/ do |type, elements|
    elements.split(', ').each do |element|
        page.should have_content element
    end
end

显然失败了,因为它找不到每条记录。如何验证仅存在一条记录?

由于

1 个答案:

答案 0 :(得分:1)

使用以下内容:

Then /^I should see the associated "([^"]*)" "([^"]*)"$/ do |type, elements|
  found = false
  elements.split(', ').each do |element|
    found = true if page.has_content? element
  end
  found.should == true
end