Today, I continue work on the navigation-from-the-homepage Cucumber scenario. Yesterday, I was able to include meal summaries on the homepage. The next two steps in the scenario are additional "thens" (post-conditions) verifying that a meal thumbnail and menu items are also included on the homepage.
Nothing new needs to be added to the Sinatra application to include either of these pieces of information. This means that work today begins with the Haml specification to drive the new data presentation.
The example of how I'd like the thumbnail to display:
it "should include a thumbnail image of the meal" doI already have an
render("/views/index.haml")
response.should have_selector("img",
:src => "/images/2009-05-15/image1.jpg",
:width => "200",
:height => "150")
end
image_link
helper, so I can make this example pass with a simple call to that helper:= image_link meal, :width => 200, :height => 150Next, I need two examples describing the presentation of each meal's menu items on the homepage. They should be wikified and comma separated:
it "should include a comma separated list of menu items" doThe entire
assigns[:meals][0]["menu"] << "chips"
assigns[:meals][0]["menu"] << "salsa"
render("/views/index.haml")
response.should have_selector(".menu-items",
:content => "chips, salsa")
end
it "should wikify menu items" do
assigns[:meals][0]["menu"] << "_really_ hot salsa"
render("/views/index.haml")
response.should have_selector(".menu-items em",
:content => "really")
end
index.haml
template that implements this:.mealsWith that, I am done with my inside/code work for today. Working my was back out to the Cucumber scenario, I need to include an image attachment if I expect to include it in the homepage:
%h1 Meals
- @meals.each do |meal|
= image_link meal, :width => 200, :height => 150
%h2= meal["title"]
= wiki(meal["summary"])
.menu-items= wiki(meal["menu"].join(", "))
Given /^(\d+) yummy meals$/ do |count|The content is the base64 encoded content of good old 1x1 spacer.gif. It does not matter much what the content is for the purposes of the Cucumber scenario—just that the filename ends with "jpg" (implementation detail of the
start_date = Date.new(2009, 6, 11)
@meal_ids = (0...count.to_i).inject([]) do |memo, i|
date = start_date - (i * 10)
meal = {
:title => "Meal #{i}",
:date => date.to_s,
:serves => 4,
:summary => "meal summary",
:description => "meal description",
:type => "Meal",
:menu => [],
:_attachments => { "meal#{i}.jpg" => {
:data => "R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAEBMgA7",
:content_type => "image/gif"}
}
}
RestClient.put "#{@@db}/#{date.to_s}",
meal.to_json,
:content_type => 'application/json'
memo + [date.to_s]
end
end
image_link
helper). With images attached to each meal, I can verify this Cucumber step with:Then /^the prominently displayed meals should include a thumbnail image$/ doThat's a good stopping point for tonight. Tomorrow, I will mark off the meals-should-include-recipe-titles step as complete. I already have enough code to implement that step, but have a kink or two that needs working out before I consider it really done.
response.should have_selector("img", :count => 10)
end
No comments:
Post a Comment