Tuesday, March 24, 2009

Implementing Recipe Details, Part 1

‹prev | My Chain | next›

Having cleared out the first spec failures last night, I get started implementing the first scenario in the Recipe Details Cucumber story:
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 a recipe with several ingredients

Given a recipe for Buttermilk Chocolate Chip Pancakes
When I view the recipe
Then I should see an ingredient of "1 cup of all-purpose, unbleached flour"
And I should see an ingredient of "¼ teaspoons salt"
And I should see an ingredient of "chocolate chips (Nestle Tollhouse)"
Mostly following along with what I discovered in my Cucumber / Sinatra spike, I implement the Given and When steps as:
Given /^a recipe for Buttermilk Chocolate Chip Pancakes$/ do
@date = Date.new(2009, 03, 24)
@title = "Buttermilk Chocolate Chip Pancakes"
@permalink = @date.to_s + "-" + @title.downcase.gsub(/\W/, '-')

RestClient.put "#{@@db}/#{@permalink}",
{ :title => @title,
:date => @date }.to_json,
:content_type => 'application/json'
end

When /^I view the recipe$/ do
visit("/recipes/#{@permalink}")
end
The next pending step is reported as:
You can use these snippets to implement pending steps which have no step definition:

Then /^I should see an ingredient of "1 cup of all\-purpose, unbleached flour"$/ do
end
Implementing this as a simple response-should-contain:
Then /^I should see an ingredient of "(.+)"$/ do |ingredient|
response.should contain(ingredient)
end
When this is run, I get the following error:
    Then I should see an ingredient of "1 cup of all-purpose, unbleached flour"
expected the following element's content to include "1 cup of all-purpose, unbleached flour":
Not Found (Spec::Expectations::ExpectationNotMetError)
./features/step_definitions/recipe_details.rb:17:in `Then /^I should see an ingredient of "(.+)"$/'
features/recipe_details.feature:11:in `Then I should see an ingredient of "1 cup of all-purpose, unbleached flour"'
This simply means that the requested resource has not been defined in the Sinatra app. To get rid of the warning, define an empty resource:
get '/recipes/:permalink' do
end
Re-running the spec changes the error to:
    Then I should see an ingredient of "1 cup of all-purpose, unbleached flour"
expected the following element's content to include "1 cup of all-purpose, unbleached flour": (Spec::Expectations::ExpectationNotMetError)
./features/step_definitions/recipe_details.rb:17:in `Then /^I should see an ingredient of "(.+)"$/'
features/recipe_details.feature:11:in `Then I should see an ingredient of "1 cup of all-purpose, unbleached flour"'
We have gone from a Not Found error to an expectation not met error. Progress!

At this point, I need to move from the outside in by dropping down into RSpec. Tomorrow...

No comments:

Post a Comment