2

鉴于 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?

谢谢!

4

2 回答 2

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
于 2010-03-20T04:52:49.610 回答
2

Check out: http://railscasts.com/episodes/186-pickle-with-cucumber

In particular look at the pickle example where he creates a product:

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"

Note how he refers to the created product as that product. Pickle will take care of that for you.

Good luck.

于 2010-03-17T13:08:21.893 回答