Thursday, April 9, 2009

Finishing Recipe Details

‹prev | My Chain | next›

Working my way back out to the features, I hit a snag. The main application spec exercises the new wiki helper method with nil input. The result is an error. I need to describe how the helper should work in such a situation:
  it "should return an empty string if called with nil" do
wiki(nil).should == ""
end
Making this example pass is a simple matter of using an empty string if nil is supplied to the wiki helper:
    def wiki(original)
text = (original || '').dup
text.gsub!(/\b(\d+)F/, "\\1° F")
text.gsub!(/\[kid:(\w+)\]/m) { |kid| kid_nicknames[$1] }
text.gsub!(/\[recipe:(\S+)\]/m) { |r| recipe_link($1) }
RedCloth.new(text).to_html
end
(commit)

Back Out to the Feature

Running the feature that started this helper effort reveals that I need to check off two more steps in the scenario:
cstrom@jaynestown:~/repos/eee-code$ cucumber features/recipe_details.feature \
-n -s "Viewing summary and recipe instructions"
Feature: Recipe Details

So that I can accurately reproduce a recipe at home
As a web user
I want to be able to easily recognize important details
Scenario: Viewing summary and recipe instructions
Given a recipe for Curried Shrimp
When I view the recipe
Then I should a nice summary of the dish
And I should see detailed, easy-to-read instructions


1 scenario
2 steps passed
2 steps pending (2 with no step definition)

You can use these snippets to implement pending steps which have no step definition:

Then /^I should a nice summary of the dish$/ do
end

Then /^I should see detailed, easy\-to\-read instructions$/ do
end
Those pending steps can be implemented with matchers similar to:
Then /^I should a nice summary of the dish$/ do
response.should have_selector("p", :content => "This dish is yummy") do |p|
p.should have_selector("strong", :content => "yummy")
end
end

Then /^I should see detailed, easy\-to\-read instructions$/ do
response.should have_selector("p", :content => "While the shrimp are defrosting, we chop the vegetables.")
end
(commit)

No comments:

Post a Comment