我是新來的黃瓜,我想詢問我如何可以組織以下步驟定義一個建議,手柄黃瓜曖昧步驟
Feature: Manage events
In order to Manage events
Organizer
wants to create new events
Background:
Given I am logged in as organizer
Scenario: Publish new event
Given I am on the new event page
When I fill in "Title" with "Rails event"
And I fill in "Start at" with "2012-5-4"
And I fill in "End at" with "2012-5-5"
And I fill in "Description" with "Bla bla"
And I check "Published"
And I press "Create Event"
Then I should see "Rails event"
下面是創建歧義步驟定義,
When /^I fill in "Start at" with "(.*?)-(.*?)-(.*?)"$/ do |year, month, day|
enter_date(:event_start_at, year, month, day)
end
When /^I fill in "End at" with "(.*?)-(.*?)-(.*?)"$/ do |year, month, day|
enter_date(:event_end_at, year, month, day)
end
When /^I fill in "(.*?)" with "(.*?)"$/ do |name, value|
fill_in name, :with => value
end
private
def enter_date(id, year, month, day)
select year, :with => "#{id}_1i"
select month, :with => "#{id}_2i"
select day, :with => "#{id}_3i"
end
會發生什麼情況是前2個定義與最後一個定義不一致。但是對於開始和結束日期,我必須以不同的方式處理它們。 我知道的是,黃瓜有解決這個問題的--guess選項。但這是最佳做法嗎?