Скажем, у меня есть какой-то сценарий, например:
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
Я заметил, что вызов шагов из шагов позволяет избежать перекрестных части речи. Возможно ли то, что я хочу сделать, без дублирования «Если есть книга» на «Когда есть книга»?