Saturday, August 1, 2009

So Many Yaks

‹prev | My Chain | next›

I enjoyed a nice break these past few days adding features to couch_design_docs, but it is time to get back to work on the main task at hand. Last I left off with my cookbook application, I had but a few pages to style.

Before I dive back into CSS though, it has been a while since last I ran all of my Cucumber scenarios. Hopefully, they all still run....

They do not. In fact I cannot even run single scenarios:
cstrom@jaynestown:~/repos/eee-code$ cucumber features/recipe_search.feature:53 -b
wrong number of arguments (0 for 1) (ArgumentError)
./features/support/../../eee.rb:24:in `before'
./features/support/../../eee.rb:24
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `polyglot_original_require'
/home/cstrom/.gem/ruby/1.8/gems/polyglot-0.2.5/lib/polyglot.rb:54:in `require'
./features/support/env.rb:5
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `polyglot_original_require'
/home/cstrom/.gem/ruby/1.8/gems/polyglot-0.2.5/lib/polyglot.rb:54:in `require'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.3.92/bin/../lib/cucumber/cli/main.rb:99:in `require_files'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.3.92/bin/../lib/cucumber/cli/main.rb:108:in `each_lib'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.3.92/bin/../lib/cucumber/cli/main.rb:106:in `each'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.3.92/bin/../lib/cucumber/cli/main.rb:106:in `each_lib'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.3.92/bin/../lib/cucumber/cli/main.rb:99:in `require_files'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.3.92/bin/../lib/cucumber/cli/main.rb:53:in `execute!'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.3.92/bin/../lib/cucumber/cli/main.rb:26:in `execute'
/home/cstrom/.gem/ruby/1.8/gems/cucumber-0.3.92/bin/cucumber:9
/home/cstrom/.gem/ruby/1.8/bin/cucumber:19:in `load'
/home/cstrom/.gem/ruby/1.8/bin/cucumber:19
Craaap. It has been a while since I last ran my Cucumber scenarios. Did I install a gem that is now conflicting?

I eventually track this down to a conflict between the before filter in my Sinatra application and a method of the same name in Cucumber::StepMother (great name by the way).

I give it a good try—a good long try—but eventually have to concede defeat for the day. Each change I make seems to get me inches closer when I have miles still to go. Maybe I'll use that work or maybe I'll toss it. Most likely the latter, so I stash it away:
cstrom@jaynestown:~/repos/eee-code$ git stash save \
"Trying to solve before filter conflict with Sinatra module namespace"
Saved working directory and index state "On master: Trying to solve before filter conflict with Sinatra module namespace"
HEAD is now at 660ad44 Whoops! Need to use one directory level up now that couch_design_docs handles more than design docs
For now, I resolve the problem the cheap way—with a conditional around the before block in the Sinatra application:
if ENV['RACK_ENV'] != 'test'
before do
content_type 'text/html', :charset => 'UTF-8'
end
end
Eeew. I do not see my first attempt staying in the stash for long. But, it works. I can now run a single scenario:
cstrom@jaynestown:~/repos/eee-code$ cucumber features/recipe_search.feature:53 -b
Sinatra::Test is deprecated; use Rack::Test instead.
Feature: Search for recipes

So that I can find one recipe among many
As a web user
I want to be able search recipes

Scenario: Paginating results # features/recipe_search.feature:53
Given 50 yummy recipes # features/step_definitions/recipe_search.rb:119
And a 1 second wait to allow the search index to be updated # features/step_definitions/recipe_search.rb:196
When I search for "yummy" # features/step_definitions/recipe_search.rb:200
Then I should see 20 results # features/step_definitions/recipe_search.rb:243
And I should see 3 pages of results # features/step_definitions/recipe_search.rb:247
And I should not be able to go to a previous page # features/step_definitions/recipe_search.rb:251
When I click page 3 # features/step_definitions/recipe_search.rb:217
Then I should see 10 results # features/step_definitions/recipe_search.rb:243
And I should not be able to go to a next page # features/step_definitions/recipe_search.rb:251
When I click the previous page # features/step_definitions/recipe_search.rb:221
Then I should see 20 results # features/step_definitions/recipe_search.rb:243
And I should be able to go to a previous page # features/step_definitions/recipe_search.rb:256
When I click the next page # features/step_definitions/recipe_search.rb:221
Then I should see 10 results # features/step_definitions/recipe_search.rb:243
When I visit page -1 # features/step_definitions/recipe_search.rb:225
Then I should see page 1 # features/step_definitions/recipe_search.rb:261
When I visit page "foo" # features/step_definitions/recipe_search.rb:225
Then I should see page 1 # features/step_definitions/recipe_search.rb:261
When I visit page 4 # features/step_definitions/recipe_search.rb:225
Then I should see page 1 # features/step_definitions/recipe_search.rb:261

1 scenario (1 passed)
20 steps (20 passed)
0m2.333s
Oh, thank heavens.

After ensuring that my RSpec examples still pass with that conditional, I can finally see if all of my Cucumber scenarios are still passing:
cstrom@jaynestown:~/repos/eee-code$ cucumber features
...

Failing Scenarios:
cucumber features/recipe_search.feature:111 # Scenario: Invalid search parameters
cucumber features/recipe_details.feature:15 # Scenario: Viewing a recipe with non-active prep time
cucumber features/browse_meals.feature:18 # Scenario: Browsing a meal in a given month

32 scenarios (3 failed, 7 undefined, 22 passed)
272 steps (3 failed, 33 skipped, 24 undefined, 212 passed)
Aw, nuts!

If nothing else, my earlier before vs. before yak shaving forced me to update all of my gems. I now have a new version of Cucumber installed that makes things a little easier to resolve. The format of the failing scenarios is such that I can copy & past to run the failing scenario in isolation:
cstrom@jaynestown:~/repos/eee-code$ cucumber features/recipe_search.feature:111
Sinatra::Test is deprecated; use Rack::Test instead.
Feature: Search for recipes

So that I can find one recipe among many
As a web user
I want to be able search recipes

Scenario: Invalid search parameters # features/recipe_search.feature:111
Given 5 "Yummy" recipes # features/step_definitions/recipe_search.rb:119
And a 0.5 second wait to allow the search index to be updated # features/step_definitions/recipe_search.rb:196
When I search for "" # features/step_definitions/recipe_search.rb:200
Then I should see no results # features/step_definitions/recipe_search.rb:316
And I should see an empty query string # features/step_definitions/recipe_search.rb:324
expected following output to contain a <input[@name=query][@value='']/> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>EEE Cooks</title>
<link href="/stylesheets/style.css" rel="stylesheet" type="text/css">
</head>
<html><body>
<div id="header">
<div id="eee-header-logo">
<a href="/">
<img alt="Home" src="/images/eee_corner.png"></a>
</div>
</div>
<ul id="eee-categories">
<li><a href="/recipes/search?q=category:italian">Italian</a></li>
<li><a href="/recipes/search?q=category:asian">Asian</a></li>
<li><a href="/recipes/search?q=category:latin">Latin</a></li>
<li><a href="/recipes/search?q=category:breakfast">Breakfast</a></li>
<li><a href="/recipes/search?q=category:chicken">Chicken</a></li>
<li><a href="/recipes/search?q=category:fish">Fish</a></li>
<li><a href="/recipes/search?q=category:meat">Meat</a></li>
<li><a href="/recipes/search?q=category:salad">Salad</a></li>
<li><a href="/recipes/search?q=category:vegetarian">Vegetarian</a></li>
<a>Recipes</a>
</ul>
<form action="/recipes/search" method="get">
<input maxlength="2048" name="q" size="31" type="text" value=""><input name="s" type="submit" value="Search">
</form>
<p class="no-results">
No results matched your search. Please refine your search
</p>
<div id="footer"></div>
</body></html>
</html>
(Spec::Expectations::ExpectationNotMetError)
features/recipe_search.feature:117:in `And I should see an empty query string'
When I search for an invalid lucene search term like "title:ingredient:egg" # features/step_definitions/recipe_search.rb:213
Then I should see no results # features/step_definitions/recipe_search.rb:316
And I should see an empty query string # features/step_definitions/recipe_search.rb:324

Failing Scenarios:
cucumber features/recipe_search.feature:111 # Scenario: Invalid search parameters

1 scenario (1 failed)
8 steps (1 failed, 3 skipped, 4 passed)
Ah, the query parameter should be "q", not "query". That is an easy enough fix:
Then /^I should see an empty query string$/ do
response.should have_selector("input[@name=q][@value='']")
end
The next failing Cucumber scenario is similarly easy to get passing. Some added tags require some RegExps where a string had sufficed before. The last failing scenario uncovers an actual bug:
cstrom@jaynestown:~/repos/eee-code$ cucumber features/browse_meals.feature:18
Sinatra::Test is deprecated; use Rack::Test instead.
Feature: Browse Meals

So that I can find meals made on special occasions
As a person interested in exploring meals and how they drive certain recipes
I want to browse meals by date

Scenario: Browsing a meal in a given month # features/browse_meals.feature:18
Given a "Even Fried, They Won't Eat It" meal enjoyed in May 2009 # features/step_definitions/meal_details.rb:1
And a "Salad. Mmmm." meal enjoyed in April 2009 # features/step_definitions/meal_details.rb:1
And a "Almost French Onion Soup" meal enjoyed in September 2003 # features/step_definitions/meal_details.rb:1
When I view the list of meals prepared in May of 2009 # features/step_definitions/meal_details.rb:47
Then I should see the "Even Fried, They Won't Eat It" meal among the meals of this month # features/step_definitions/meal_details.rb:81
And I should not see the "Salad. Mmmm." meal among the meals of this month # features/step_definitions/meal_details.rb:85
And I should not see a link to June 2009 # features/step_definitions/meal_details.rb:97
When I follow the link to the list of meals in April 2009 # features/step_definitions/meal_details.rb:57
Could not find link with text or title or id "April 2009" (Webrat::NotFoundError)
features/browse_meals.feature:27:in `When I follow the link to the list of meals in April 2009'
Then I should not see the "Even Fried, They Won't Eat It" meal among the meals of this month # features/step_definitions/meal_details.rb:85
And I should see the "Salad. Mmmm." meal among the meals of this month # features/step_definitions/meal_details.rb:81
And I should see a link to May 2009 # features/step_definitions/meal_details.rb:93
And I should not see a link to February 2009 # features/step_definitions/meal_details.rb:97
When I follow the link to the list of meals in September 2003 # features/step_definitions/meal_details.rb:57
Then I should see the "Almost French Onion Soup" meal among the meals of this month # features/step_definitions/meal_details.rb:81
And I should see a link to April 2009 # features/step_definitions/meal_details.rb:93

Failing Scenarios:
cucumber features/browse_meals.feature:18 # Scenario: Browsing a meal in a given month

1 scenario (1 failed)
15 steps (1 failed, 7 skipped, 7 passed)
Looking at the actual meals-by-month web page (it's nice to be able to do that now), I see that the intra-month links are not actual links and have the wrong date:



That turns out to be another yak. I have had my fill of yaks for the day, so I will start with that one tomorrow.

No comments:

Post a Comment