Wednesday, June 17, 2009

Marking Meal to Recipe Navigation as Complete

‹prev | My Chain | next›

Before moving on to "real" work, I run all of my tests only to find that I have several errors. There are many errors in the meal.haml_spec.rb specification:
NoMethodError in 'meal.haml should wikify the meal's description'
undefined method `[]' for nil:NilClass
./helpers.rb:18:in `recipe_category_link'
(haml):39:in `any?'
./helpers.rb:17:in `each'
./helpers.rb:17:in `any?'
./helpers.rb:17:in `recipe_category_link'
(haml):2:in `render'
/home/cstrom/.gem/ruby/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `render'
/home/cstrom/.gem/ruby/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `instance_eval'
/home/cstrom/.gem/ruby/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `render'
/home/cstrom/repos/eee-code/spec/spec_helper.rb:27:in `render'
All eleven errors are caused by the inclusion of the recipe_category_link helper last night. I am not able to stub out the method, so I seed some dummy data in the before(:each) block to eliminate the errors:
    assigns[:recipes] = []
This prevents the recipe_category_link from acting upon a nil @recipes array when building the category links:
%li= recipe_category_link(@recipes, 'Italian')
%li= recipe_category_link(@recipes, 'Asian')
Next up, it is back to the Cucumber scenario. Specifically, I need to mark a few scenario steps as complete in the navigation-from-the-homepage Cucumber scenario. Yesterday, I was able to verify that a user could navigate from the homepage to a recent meal. I also ensured that site-wide categories were displaying on the same meal page.

Now, I need to ensure that the user can navigate from the meal down to a recipe listed on the menu. Cucumber tells me that I can implement the missing steps with:
When /^I click on the recipe in the menu$/ do

Then /^I should see the recipe page$/ do
As mentioned, the scenario so far involves clicking on the most recently prepared meal, then clicking on the recipe on that meal's menu. The meals created for this scenario have titles: "Meal 0", "Meal 1", "Meal 2", etc. In turn, the recipes for each meal are named simply: "Recipe for Meal 0", "Recipe for Meal 1", "Recipe for Meal 2", etc. So, to click on the recipe for the first meal, I need to look for a link to "Recipe for Meal 0":
When /^I click on the recipe in the menu$/ do
click_link "Recipe for Meal 0"
Similarly, to verify that I am on the appropriate recipe page, I check the <h1> tag:
Then /^I should see the recipe page$/ do
response.should have_selector("h1",
:content => "Recipe for Meal 0")
The next step in the scenario, that the Italian category should be highlighted for this Italian recipe, was implemented last night. The step was written for the meal (the meal is Italian because it has an Italian recipe on the menu), but applies to category links on the recipe page just as it does on the meal page.

And just like that, I am done with 14 of the 21 steps in the scenario:

Before moving onto the next steps, I think there are some DRY violations in the category links that I need to address. Tomorrow.

No comments:

Post a Comment