ruby-on-rails - cucumber 和 rails : testing for the presence of a random record

标签 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

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

谢谢

最佳答案

使用以下内容:

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

关于ruby-on-rails - cucumber 和 rails : testing for the presence of a random record,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14224025/

相关文章:

javascript - 是否可以使用 Protractor 运行 IE11 仿真?

testing - 我如何测试 grail 的 Controller 的渲染方法?

ruby-on-rails - 如何在heroku上使用sqlite gem(不是DB)?

ruby-on-rails - 工厂女孩创建对象但在数据库中找不到对象

html - Zurb Foundation 4 列未调整大小

json - 如何在 Play 框架 v2.x 中不使用 withJsonBody 为 FakeRequest 发送 json 字符串主体?

ruby-on-rails-4 - PG::ConnectionBad:将 rails 从 4.2 升级到 5.2 后连接关闭

python - 是否有技术原因无法用 Python 重写像 RSpec 这样的 Ruby DSL?

ruby - 在 headless (headless) Chrome 中调试

ruby-on-rails - Cancan 2.0 - 限制对字段的权限