冗余和重复的产生,考虑如下场景
Feature: movies should appear in alphabetical order, not added order
Scenario: view movie list after adding 2 movies (imperative and non-DRY)
Given I am on the RottenPotatoes home page
When I follow "Add new movie"
Then I should be on the Create New Movie page
When I fill in "Title" with "Zorro"
And I select "PG" from "Rating"
And I press "Save Changes"
Then I should be on the RottenPotatoes home page
When I follow "Add new movie"
Then I should be on the Create New Movie page
When I fill in "Title" with "Apocalypse Now"
And I select "R" from "Rating"
And I press "Save Changes"
Then I should be on the RottenPotatoes home page
Then I should see "Apocalypse Now" before "Zorro" on the RottenPotatoes home page sorted by title
这个写法无疑又太多的重复,对比如下描述
Feature: movies should appear in alphabetical order, not added order
Scenario: view movie list after adding movie (declarative and DRY)
Given I have added "Zorro" with rating "PG-13"
And I have added "Apocalypse Now" with rating "R"
Then I should see "Apocalypse Now" before "Zorro" on the RottenPotatoes home page sorted by title
这种描述就很简洁。所以只需添加features/step_definitions/declarative_steps.rb
Given /I have added "(.*)" with rating "(.*)"/ do |title, rating|
steps %Q{
Given I am on the Create New Movie page
When I fill in "Title" with "#{title}"
And I select "#{rating}" from "Rating"
And I press "Save Changes"
}
end
Then /I should see "(.*)" before "(.*)" on (.*)/ do |string1, string2, path|
step "I am on #{path}"
regexp = /#{string1}.*#{string2}/m # /m means match across newlines
page.body.should =~ regexp
end