我是黄瓜的新手,我想就如何组织以下步骤定义寻求建议,
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 个定义与最后一个定义不明确。但是对于开始和结束日期,我必须以不同的方式处理它们。我所知道的是 cucumber 具有解决该问题的 --guess 选项。但这是最佳实践吗?