Saturday, May 30, 2009

Meal Menu Items

‹prev | My Chain | next›

I left off yesterday with a failing Cucumber step, making it easy to remember where to pick up today:
cstrom@jaynestown:~/repos/eee-code$ cucumber features -n \
> -s "Browsing a meal on a specific date"
Feature: Browse Meals

So that I can find meals made on special occasions
As a person interested in finding meals
I want to browse meals by date

Scenario: Browsing a meal on a specific date
Given a "Focaccia!" meal enjoyed on March 3, 2009
And a "Focaccia" recipe from March 3, 2009
When I view the "Focaccia!" meal
Then I should see the "Focaccia!" title
And I should see a link to the "Focaccia" recipe in the menu
expected following output to contain a <a>the "Focaccia" recipe in the menu</a> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
<h1>
Focaccia!
</h1>
<div id="summary">
<p>meal summary</p>
</div>
<div id="description">
<p>meal description</p>
</div>
</body></html>
(Spec::Expectations::ExpectationNotMetError)
features/browse_meals.feature:42:in `And I should see a link to the "Focaccia" recipe in the menu'
...
Before I get recipes in the meal's menu, I need to get the menu itself presented via the Haml template. In order to describe how the Haml template will display the menu, I add a single menu item to the sample meal in the before(:each) block in the RSpec specification:

before(:each) do
@title = "Meal Title"
@summary = "Meal Summary"
@description = "Meal Description"
assigns[:meal] = @meal = {
'title' => @title,
'summary' => @summary,
'description' => @description,
'menu' => ["Peanut Butter and Jelly Sandwich"]
}
end
I would like to display the menu after the summary, in CSS3 terms: "#summary + #menu". The example that I would like to have pass is:
  it "should include the menu after the summary" do
render("/views/meal.haml")
response.should have_selector("#summary + ul#menu li",
:content => "Peanut Butter and Jelly Sandwich")
end
I can get that example to pass with some more minimalistic Haml:
#summary
= wiki @meal['summary']

%ul#menu
- @meal['menu'].each do |menu_item|
%li= menu_item
To get the recipes in the menu items, I need only call the wiki helper, which applies the recipe_link helper to [recipe:...] wiki text. I am not going to test that the Haml template properly pulls the recipe into the menu—too much composition in a unit test for my taste. I will leave that to the Cucumber scenario. To drive the Haml template, I will use an example of simple Textile wikifying:
  it "should wikify the menu items" do
assigns[:meal]['menu'] << "foo *bar* baz"
render("/views/meal.haml")
response.should have_selector("ul#menu li strong",
:content => "bar")
end
A simple invocation of the wiki helper makes that example pass:
%ul#menu
- @meal['menu'].each do |menu_item|
%li= wiki(menu_item)
Back in Cucumber, I realize that I need to create the recipe before I create the meal (so that the meal can include the recipe in its menu). With some quick rearranging of the scenario text, I am able to verify that recipe links in meal menu items do, indeed, work as expected:



(commit)

Tomorrow, it looks like I will be working through the breadcrumbs on the meal page.

No comments:

Post a Comment