text: Today, I continue working my way through the navigation from the home page Cucumber scenario. So far, I have been able to verify that meals are listed on the homepage and that the user can click through the meals onto recipe pages. Next in the scenario is verifying that the user can click on some category links before returning to the home page.
  To verify the ability of the user to click on the Italian category on the recipe page, I ought to be able to do something as simple as:
  When /^I click on the Italian category$/ doI ought to be able to do something like that, but...
  click_link "Italian"
  end
  cucumber -n features \Hunh. I just spent yesterday DRYing up the category links. Did I mess something up? To answer that question, I'll use Webrat's
  -s "Quickly scanning meals and recipes accessible from the home page"
  ...
  When I click on the recipe in the menu
  Then I should see the recipe page
  And the Italian category should be highlighted
  When I click on the Italian category
  Could not find link with text or title or id "Italian" (Webrat::NotFoundError)
  features/site.feature:23:in `When I click on the Italian category'
  ...
  save_and_open_pagehelper method to dump a copy of the page to the browser. After adding this to the Cucumber step:
  When /^I click on the Italian category$/ doI find this in the browser:
  save_and_open_page()
  click_link "Italian"
  end
  Hmmm... the categories, including Italian, are there, but they do not look like normal hyperlinks. Viewing the source, I see:
  <ul id="eee-categories">Ah, no
  <li><a class="active">Italian</a></li>
  <li><a>Asian</a></li>
  ...
  hrefattribute. It would seem that Webrat does not view
  <a>tags without
  hrefattributes as links any more than Firefox does. Ah well, looks as though I have a little more work to do in the code before I can mark this step as complete.
  When I click on a category link, such as "Italian", the user should be taken to the list of recipes that fall into that category. Fortunately, I already have a couchdb-lucene search results page that holds this information. To link the categories at the top of the pages to those search results, I start with this RSpec example:
  it "should link to the category search results" doTo get that example to pass, I add
  recipe_category_link({}, "Italian").
  should have_selector("a",
  :href => "/recipes/search?q=tag_names:italian")
  end
  hrefattributes to the
  recipe_category_linkhelper:
  def recipe_category_link(recipe, category)With that implemented, I work my way back to the Cucumber scenario to find the click-the-category-link step is now passing:
  recipes = recipe.is_a?(Array) ? recipe : [recipe]
  href = "/recipes/search?q=tag_names:#{category.downcase}"
  if recipes.any? { |r|
  r['tag_names'] &&
  r['tag_names'].include?(category.downcase)
  }
  %Q|<a class="active" href="#{href}">#{category}</a>|
  else
  %Q|<a href="#{href}">#{category}</a>|
  end
  end
  The next step in the scenario verifies that the five Italian recipes created early in the scenario are displayed on the category results page. Something like this ought to suffice:
  Then /^I should see 5 Italian recipes$/ doThat scenario step failed at first because I had not been indexing the categories in couchdb-lucene. After addressing that deficiency, I am up to 16 of 21 steps passing:
  # 5 result rows + 1 header row
  response.should have_selector("tr",
  :count => 6)
  end
  Hopefully tomorrow, I can finish up the navigation from the home page scenario.