ruby-on-rails - cucumber 记录 ID

标签 ruby-on-rails cucumber pickle capybara

在 Cucumber 中给出以下内容:

Given a car exists with title: "Toyota"
And I go to path "/cars"
And I follow "Toyota Page"
And I should be on path "/cars/CAR_ID"
Where CAR_ID is the ID of the car titled "Toyota".

我如何找出该 ID?

谢谢!

最佳答案

你可以这样写:

Given a car exists with title: "Toyota"
When I go to path "/cars"
And I follow "Toyota Page"
Then I should be on the page for the car: "Toyota"

最后一步的定义可以是:

Then /^I should be on the page for the car: "([^\"]*)"$/ do |car_title|
  car = Car.find_by_title(car_title)
  assert_equal "/cars/#{car.id}", URI.parse(current_url).path
end

关于ruby-on-rails - cucumber 记录 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2459315/

相关文章:

python - 为什么 Python 在不应该的时候给我 "an integer is required"?

ruby-on-rails - Rails accepts_nested_attributes计数验证

ruby-on-rails - 数据库中的切换属性

ruby-on-rails - Paranoia Gem - 加入已删除的项目

ruby - 我如何选择不运行 cucumber 功能

jquery - 确定 JQuery 效果是否仍在执行

autocomplete - @javascript cucumber 测试使用 selenium webdriver 通过,但在使用 poltergeist 时失败

Python - pickle.load() 采用一个位置参数(给定 2 个)

ruby-on-rails - rails 4 : Model Logic - Counting Items by a User

python - 使用 pickle 保存模型