Да кажем, че имам някакъв сценарий като:
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
Забелязвам, че извикване на стъпки от стъпки избягва кръстосано части на речта. Възможно ли е това, което искам да направя, без да дублирам „При положение, че има книга“ на „Когато има книга“?