Tuesday, June 23, 2009

Not Much of a Scenario

With a little bit of cleanup behind, it's on to the next Cucumber scenario—exploring food categories from the homepage. The whole scenario:

Nice! Out of 12 steps in this scenario, 4 are already passing and 2 more are defined, but not yet reached.

The first undefined step in the scenario, clicking on the Italian category on the homepage, describes something missing on the homepage—category links. So, it is time for an RSpec example for the Haml template:

it "should link to the listing of Italian recipes" do render("/views/index.haml") response.should have_selector("a", :content => "Italian") end

I implement that with a call to the categories helper, which links to the Italian category, as well as the other major categories on the site.

That is sufficient to implement the next step, "When I click the Italian category". Hey, that seems vaguely familiar. Have I already done something similar? In fact, I have:

When /^I click on the Italian category$/ do click_link "Italian"end

Hmm… I do not particularly care for the "on" that is currently in there. I think that it reads better without it, so I remove it from the text of an earlier scenario and from the step definition. While I am re-working that step anyway, I note that I will soon need to verify that the user can click the "Breakfast" category. To get the step passing for both categories, I use a Regexp matcher:

When /^I click the (\w+) category$/ do |category| click_link categoryend

With that step passing, I am up to the "Then I should see 20 recipes" step. Again, this seems familiar. Looking through the old recipe search feature step definitions, I find:

Upon further inspection, I note that there were no matches on the Italian recipe category. The source of the trouble was the implementation of the "Given 50 Italian recipes" step. That step, as shown in the Cucumber output, was defined for the recipe search feature. It was defined without categories. The text after the number ("Italian") was used to build the recipe title, not to assign categories. Since that step made no use of the categories / tag_names, I am free to make use of it now:

After making similar adjustments for the next several steps, I am on the last step of this scenario—when I search for a category that only has 10 recipes (i.e. is less that the search page size), then I should see no more result pages. I define this step with the assumption that, in such a case, the "Next" link should be inactive:

Then /^I should see no more pages of results$/ do response.should have_selector(".inactive", :content => "Next »")end

And, just like that, I have another scenario complete:

There are still a few more scenarios in need of implementation, but I am getting very close to deploying.