After a day trip to Brooklyn that included no less than 8 hours of driving, my brain is not functioning much. Having deployed my latest feature to the beta site, it is time to start work on the next feature. Ordinarily, I would pick up the next incomplete Cucumber scenario. Today, I choose the easiest, the homepage mini-calendar.
For reference, the mini-calendar on the legacy homepage looks like:
The Cucumber feature description includes only a single scenario. That may be all that is necessary as the scenario includes the default page, going back to a month without any meals and then back to a month with meals. This is a simple calendar, and a single scenario seems (at least to my brain tonight) to be sufficient.
The Given steps have already been implemented:
To verify that the mini-calendar is visitable. I start by driving its implementation with the following RSpec example:
describe "GET /mini/" doThat fails:
it "should respond OK" do
get "/mini/"
last_response.should be_ok
end
end
cstrom@jaynestown:~/repos/eee-code$ spec ./spec/eee_spec.rbI make it pass with a new Sinatra action:
..........................................F
1)
'/mini GET /mini/ should respond OK' FAILED
expected ok? to return true, got false
./spec/eee_spec.rb:541:
get %r{/mini/.*} doVery quickly, I work my way back out to the Cucumber scenario to mark the "When I visit the mini-calendar" step as complete:
""
end
When /^I visit the mini\-calendar$/ doThe next step in the scenario is that the default mini-calendar page should be the month with the most recent meal. My "meals/count_by_month" reduced CouchDB view is the perfect tool to get this job done, so the mini action needs to grab it. In RSpec parlance:
visit("/mini/")
end
it "should retrieve the most recent month with a meal" doThe thing that I am testing here is that CouchDB is being queried for the
RestClient.
should_receive(:get).
with(/meals.+count_by_month.+descending=true/).
and_return('{"rows": [{"key":"2009-08","value":3}]}')
get "/mini/"
end
count_by_month
in descending order (i.e. with the most recent month first). The return value needs to be a CouchDB result. To implement that example:get %r{/mini/.*} doFinally to do something with that query, the following example requires that the month is displayed:
url = "#{@@db}/_design/meals/_view/count_by_month?group=true\&limit=1\&descending=true"
data = RestClient.get url
""
end
it "should display the month" doAnd to get that example to pass, I add a
get "/mini/"
last_response.
should have_selector("h1", :content => "2009-08")
end
h1
tag to the output:get %r{/mini/.*} doThat is a good stopping point for today. I will pick back up with this feature tomorrow, starting with moving that HTML into a Haml template.
url = "#{@@db}/_design/meals/_view/count_by_month?group=true\&limit=1\&descending=true"
data = RestClient.get url
@last_month = JSON.parse(data)['rows'].first['key']
"<h1>#{@last_month}</h1>"
end
No comments:
Post a Comment