Friday, August 21, 2009

And Back (Outside) Again

‹prev | My Chain | next›

With the beta site up and running reasonably well, it is time to get start the process of moving past beta. So, it is back to my Cucumber scenarios to see where I am at:
cstrom@jaynestown:~/repos/eee-code$ cucumber features -i 
...
32 scenarios (7 undefined, 25 passed)
272 steps (22 skipped, 24 undefined, 226 passed)
0m33.393s
To ease my way back into the swing of things, I start with those undefined scenarios that are close to done (or maybe already done). First up is:



Yup, I implemented that in the beginning of this month. It is nice to have this on my checklist of things to do—just in case I had not gotten to it. Since I have done it, it is time to mark it as done:
Then /^I should see the search field for refining my search$/ do
response.should have_selector("input[@name=q][@value='#{@keyword}']")
end
To get that @keyword instance variable, I have to squirrel it away in the search step:
When /^I search for "(.*)"$/ do |keyword|
@keyword = keyword
@query = "/recipes/search?q=#{keyword}"
visit(@query)
end
Just like that, I have a scenario done:
cstrom@jaynestown:~/repos/eee-code$ cucumber features/recipe_search.feature:7
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: Matching a word in the ingredient list in full recipe search # features/recipe_search.feature:7
Given a "pancake" recipe with "chocolate chips" in it # features/step_definitions/recipe_search.rb:1
And a "french toast" recipe with "eggs" in it # features/step_definitions/recipe_search.rb:23
And a 0.5 second wait to allow the search index to be updated # features/step_definitions/recipe_search.rb:197
When I search for "chocolate" # features/step_definitions/recipe_search.rb:201
Then I should see the "pancake" recipe in the search results # features/step_definitions/recipe_search.rb:235
And I should not see the "french toast" recipe in the search results # features/step_definitions/recipe_search.rb:241
And I should see the search field for refining my search # features/step_definitions/recipe_search.rb:330

1 scenario (1 passed)
7 steps (7 passed)
0m1.064s
Of the six remaining steps, 5 describe new features. One describes an already existing scenario:



Nice! That looks to be some good step re-use. Everything after the missing step is already defined, not as a recipe search step definition, but in the meal scenario. Even better, I implemented the actual feature while spelunking through the code a while back. Hopefully, all I need to do it implement the one missing Cucumber step to verify that implementation:
When /^I view the "([^\"]*)" recipe$/ do |title|
visit("/recipes/#{@recipe_permalink}")
end
Running the scenario, however, I find:
cstrom@jaynestown:~/repos/eee-code$ cucumber features/recipe_details.feature:42
Sinatra::Test is deprecated; use Rack::Test instead.
Feature: Recipe Details

So that I can accurately reproduce a recipe at home
As a web user
I want to be able to easily recognize important details

Scenario: Navigating to other recipes # features/recipe_details.feature:42
Given a "Spaghetti" recipe from May 30, 2009 # features/step_definitions/recipe_details.rb:137
And a "Pizza" recipe from June 1, 2009 # features/step_definitions/recipe_details.rb:137
And a "Peanut Butter and Jelly" recipe from June 11, 2009 # features/step_definitions/recipe_details.rb:137
When I view the "Peanut Butter and Jelly" recipe # features/step_definitions/recipe_details.rb:157
Then I should see the "Peanut Butter and Jelly" title # features/step_definitions/meal_details.rb:70
When I click "Pizza" # features/step_definitions/meal_details.rb:65
Could not find link with text or title or id "Pizza" (Webrat::NotFoundError)
features/recipe_details.feature:49:in `When I click "Pizza"'
Then I should see the "Pizza" title # features/step_definitions/meal_details.rb:70
When I click "Spaghetti" # features/step_definitions/meal_details.rb:65
Then I should see the "Spaghetti" title # features/step_definitions/meal_details.rb:70
When I click "Pizza" # features/step_definitions/meal_details.rb:65
Then I should see the "Pizza" title # features/step_definitions/meal_details.rb:70
When I click "Peanut Butter and Jelly" # features/step_definitions/meal_details.rb:65
Then I should see the "Peanut Butter and Jelly" title # features/step_definitions/meal_details.rb:70

Failing Scenarios:
cucumber features/recipe_details.feature:42 # Scenario: Navigating to other recipes

1 scenario (1 failed)
13 steps (1 failed, 7 skipped, 5 passed)
0m0.592s
Dang.

I am at a loss to explain this one, so I have to resort to inserting a save_and_open_page before the failure:
When /^I click "([^\"]*)"$/ do |text|
save_and_open_page()
click_link text
end
Viewing the page, I find:



Hunh. I thought the explanation for the missing link might have been that I was on the wrong page somehow. That is the right page. There are even the angle quotes indicative of navigation. But no links.

Still, knowing where the error occurred helps me to track it down quickly. In this case, I had neglected to add :type => "Recipe" to recipe documents. Without it, couchdb-lucene is configured to ignore that document. So I add it to the step that creates the document:
Given /^a "([^\"]*)" recipe from (.+)$/ do |title, date_str|
date = Date.parse(date_str)
@recipe_permalink = date.to_s + "-" + title.downcase.gsub(/\W/, '-')

recipe = {
:title => title,
:date => date,
:summary => "#{title} summary",
:instructions => "#{title} instructions",
:type => "Recipe"
}

RestClient.put "#{@@db}/#{@recipe_permalink}",
recipe.to_json,
:content_type => 'application/json'
end
With that, the whole scenario goes green:
cstrom@jaynestown:~/repos/eee-code$ cucumber features/recipe_details.feature:42
Sinatra::Test is deprecated; use Rack::Test instead.
Feature: Recipe Details

So that I can accurately reproduce a recipe at home
As a web user
I want to be able to easily recognize important details

Scenario: Navigating to other recipes # features/recipe_details.feature:42
Given a "Spaghetti" recipe from May 30, 2009 # features/step_definitions/recipe_details.rb:137
And a "Pizza" recipe from June 1, 2009 # features/step_definitions/recipe_details.rb:137
And a "Peanut Butter and Jelly" recipe from June 11, 2009 # features/step_definitions/recipe_details.rb:137
When I view the "Peanut Butter and Jelly" recipe # features/step_definitions/recipe_details.rb:158
Then I should see the "Peanut Butter and Jelly" title # features/step_definitions/meal_details.rb:70
When I click "Pizza" # features/step_definitions/meal_details.rb:65
Then I should see the "Pizza" title # features/step_definitions/meal_details.rb:70
When I click "Spaghetti" # features/step_definitions/meal_details.rb:65
Then I should see the "Spaghetti" title # features/step_definitions/meal_details.rb:70
When I click "Pizza" # features/step_definitions/meal_details.rb:65
Then I should see the "Pizza" title # features/step_definitions/meal_details.rb:70
When I click "Peanut Butter and Jelly" # features/step_definitions/meal_details.rb:65
Then I should see the "Peanut Butter and Jelly" title # features/step_definitions/meal_details.rb:70

1 scenario (1 passed)
13 steps (13 passed)
0m0.733s
I now stand at:
cstrom@jaynestown:~/repos/eee-code$ cucumber features -i
...
2 scenarios (5 undefined, 27 passed)
272 steps (13 skipped, 22 undefined, 237 passed)
0m33.394s
The remaining 5 scenarios are new features that will help to push me out of beta. I will start on them tomorrow. As for tonight, I was able to check off two more scenarios as complete—without having to delve into code. I appreciate those kind of stats.

(commit)

No comments:

Post a Comment