Monday, May 18, 2009

Outside Meals in a Month

‹prev | My Chain | next›

With browsing meals by year done, I get started on browsing them by month tonight. The Cucumber scenario:
  Scenario: Browsing a meal in a given month

Given a "Even Fried, They Won't Eat It" meal enjoyed in May of 2009
And a "Salad. Mmmm." meal enjoyed in April of 2009
When I view the list of meals prepared in May of 2009
Then I should see the "Even Fried, They Won't Eat It" meal among the meals of this month
And I should not see the "Salad. Mmmm." meal among the meals of this month
And I should not see a link to June of 2009
When I follow the link to the list of meals in April of 2009
Then I should not see the "Even Fried, They Won't Eat It" meal among the meals of this month
And I should see the "Salad. Mmmm." meal among the meals of this month
And I should not see a link to February of 2009
And I should see a link to May of 2009
I can implement the first two step of this scenario with a variation of the meal creation step from the first meal scenario:
Given /^a "([^\"]*)" meal enjoyed in (.+)$/ do |title, date_str|
date = Date.parse(date_str)

permalink = "id-#{date.to_s}"

meal = {
:title => title,
:date => date.to_s,
:serves => 4,
:summary => "meal summary",
:description => "meal description",
:type => "Meal"
}

RestClient.put "#{@@db}/#{permalink}",
meal.to_json,
:content_type => 'application/json'
end
Past experience has taught me that, for the "visit" step, that I should both visit the link and verify that it the responds OK:
When /^I view the list of meals prepared in May of 2009$/ do
visit("/meals/2009/05")
response.status.should == 200
end
I like checking the status as a way of verifying this step. It should fail now (because the action being requested does not exist) and it should not fail in the future. It should fail now, but it doesn't:



Ah, it is passing because it is using the year action (matching the RegExp):
get %r{/meals/(\d+)} do |year|
...
end
To get this passing for real, I add a more specific Sinatra action:
get %r{/meals/(\d+)/(\d+)} do |year, month|
end
That's a good stopping point for tonight. I'll work my way inside to implement functionality tomorrow.

No comments:

Post a Comment