I make a small offering to the gods of my chain tonight with a Cucumber feature describing the ingredient index feature:
Feature: Ingredient index for recipesI mostly need these scenarios so that I can verify the full stack of Sinatra and CouchDB is working after the detailed implementation is driven by unit examples.
As a user curious about ingredients or recipes
I want to see a list of ingredients
So that I can see a sample of recipes in the cookbook using a particular ingredient
Scenario: A couple of recipes sharing an ingredient
Given a "Cookie" recipe with "butter and chocolate chips"
And a "Pancake" recipe with "flour and chocolate chips"
When I visit the ingredients page
Then I should see the "chocolate chips" ingredient
And "chocolate chips" recipes should include "Cookie" and "Pancake"
And I should see the "flour" ingredient
And "flour" recipes should include only "Pancake"
Scenario: Scores of recipes sharing an ingredient
Given 120 recipes with "butter"
When I visit the ingredients page
Then I should not see the "butter" ingredient
Additionally, I would like to exclude ingredients that appear in scores of recipes (the second scenario). In the past two legacy incarnation of the site, we excluded them simply because an ingredient with 100+ recipes tends to throw off the page layout. If need be, a separate page can be established to hold those recipes. This may also help me avoid potential performance issues in the CouchDB map-reduce as pointed out in the comments yesterday.
Although I lack time today, I can at least drive the imeplementation of the Sinatra action with these examples:
it "should respond OK" doThe simplest thing that can possibly work to ensure that the action responds OK, makes a
get "/ingredients"
last_response.should be_ok
end
it "should ask CouchDB for a list of ingredients" do
RestClient.
should_receive(:get).
with(%r{by_ingredients}).
and_return('{"rows": [] }')
get "/ingredients"
end
it "should be named \"Ingredient Index\"" do
get "/ingredients"
last_response.
should have_selector("title", :content => "EEE Cooks: Ingredient Index")
end
RestClient
call to CouchDB, and has a title
tag is:get '/ingredients' doThat's a fine stopping point for tonight. I will pick up tomorrow with the Haml template.
url = "#{@@db}/_design/recipes/_view/by_ingredients?group=true"
data = RestClient.get url
@ingredients = JSON.parse(data)['rows']
"<title>EEE Cooks: Ingredient Index</title>"
end
No comments:
Post a Comment