鉴于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?
谢谢!
答案 0 :(得分:3)
你可以这样写:
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
答案 1 :(得分:2)
退房:http://railscasts.com/episodes/186-pickle-with-cucumber
特别要看一下他创造产品的泡菜示例:
Scenario: Show product
Given a product exists with name: "Milk", price: "2.99"
When I go to the show page for that product
Then I should see "Milk" within "h1"
And I should see "$2.99"
请注意他如何将创建的产品称为该产品。 Pickle将为您照顾。
祝你好运。