ID записи огурца - PullRequest
       48

ID записи огурца

2 голосов
/ 17 марта 2010

Учитывая следующее в огурце:

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".

Как мне узнать этот идентификатор?

Спасибо!

Ответы [ 2 ]

3 голосов
/ 20 марта 2010

Вы могли бы написать это как:

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
2 голосов
/ 17 марта 2010

Выезд: 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"

Обратите внимание, как он называет созданный продукт этим продуктом . Пикл позаботится об этом за вас.

Удачи.

...