0
比方说,我有一些场景,如:是否可以从黄瓜的When步中调用给定步骤?
Feature: Creating Books
In order to have books to read
As a user
I want to create them
Background:
Given I am on the book creation page
Scenario: Creating a book
When I create the book "Moby Dick"
Then I should see "Book has been created."
和步骤定义:
Given /^I am on the ([\w\s]+)$/ do |page|
case page
when "book creation page"
visit new_book_path
else
visit page
end
end
Given /^there is a book "([\w\s]+)"$/ do |title|
steps %Q{
Given I am on the book creation page
}
fill_in 'Title', :with => 'Moby Dick'
click_button 'Create'
end
When /^I create the book "([\w\s]+)"$/ do |title|
steps %Q{
Given there is a book #{title}
}
end
运行黄瓜,我发现,“鉴于有一本书”被理解为“当”:
You can implement step definitions for undefined steps with these snippets:
When /^there is a book Moby Dick$/ do
pending # express the regexp above with the code you wish you had
end
我注意到calling steps from steps避免了言语的交叉部分。我是否希望做到这一点,而不是将'有书'复制到'有书时'?
这是它到底。 – troutwine 2012-03-01 04:14:21