With couchdb-lucene returning data along with results, I get my red-green-refactor on tonight to finish implementing the first Recipe Search scenario.
My initial effort on this ended with the search action responding with a simple string. To get full output, a template is needed. The spec doc that I end up implementing is:
cstrom@jaynestown:~/repos/eee-code$ spec ./spec/views/search.haml_spec.rb -cfsCheck the commit if you are interested in the details of the individual specs. The Haml template that implements these 5 examples is still relatively simple at this point:
search.haml
- should display the recipe's title
- should display a second recipe
- should display zebra strips
- should link the title to the recipe
- should display the recipe's date
Finished in 0.031609 seconds
5 examples, 0 failures
%tableFinally, working my way back out to the scenario I perform some accidental refactoring. The scenario that I need to implement is:
%tr
%th= "Name"
%th= "Date"
- @results['rows'].each_with_index do |result, i|
%tr{:class => "row#{i % 2}"}
%td
%a{:href => "/recipes/#{result['_id']}"}= result['title']
%td= result['date']
Scenario: Matching a word in the ingredient list in full recipe searchThe accidental refactoring took place in the first Then's definition. The original implementation was:
Given a "pancake" recipe with "chocolate chips" in it
And a "french toast" recipe with "eggs" in it
And a 1 second wait to allow the search index to be updated
When I search for "chocolate"
Then I should see the "pancake" recipe in the search results
And I should not see the "french toast" recipe in the search results
Then /^I should see the "pancake" recipe in the search results$/ doThe accidental refactoring took place when I misread the last Then statement to be in the same format as the first (I missed the addition of the word "not"). To work with both forms, the block-with-argument step definition works:
response.should have_selector("a", :href => "/recipes/#{@pancake_permalink}")
end
Then /^I should see the "(.+)" recipe in the search results$/ do |title|Chagrined to see that the final step was still not implemented, I correct my omission, but leave the refactored definition in place. This is not a simple violation of YAGNI, because I am going to need it. Upcoming scenarios can use the generalized format. Still, I must be more careful before refactoring.
response.should have_selector("a",
:href => "/recipes/id-#{title}",
:content => title)
end
(commit)
No comments:
Post a Comment