I start today with a note about yesterday's work: when URL encoding in Sinatra, use
Rack::Utils.escape
. It works and it will encode in the same way that Rack::Test
would expect things to be encoded. Maybe an obvious suggestion, but with the myriad of URL encoding options available in the Ruby world, it seemed one worth noting.I used
Rack::Utils.escape
in the meal feedback link:%divYesterday, I used the
%a{:href => "/feedback?url=#{Rack::Utils.escape(@url)}&subject=#{Rack::Utils.escape("[Meal] " + @meal['title'])}"} Send us feedback on this meal
subject
and url
query parameters in that link to pre-populate the feedback form. Today, I need to ensure that the url
parameter, when submitted by the feedback form to the "send us email" action does something. Specifically, it ought to include the URL in the email that we receive.Unfortunately, because the email body is only one attribute to the
Pony.mail
call, I have to specify the entire body of the email message. I can use RSpec's hash_including
so that I do not have to specify all of the Pony.mail
attributes, but I still need the entire message body:it "should include the URL (if supplied) in the email" doI get that and the previous non-URL example passing with this email action:
message = <<"_EOM"
From: from
Email: email
Message
URL: http://example.org/
_EOM
Pony.
should_receive(:mail).
with(hash_including(:body => message))
post "/email",
:name => "from",
:email => "email",
:subject => "Subject",
:message => "Message",
:url => "http://example.org/"
end
post '/email' doWith that, I am ready to work my way back out to the Cucumber scenario to mark it as complete:
message = <<"_EOM"
From: #{params[:name]}
Email: #{params[:email]}
#{params[:message]}
_EOM
message << "\nURL: #{params[:url]}\n" if params[:url]
Pony.mail(:to => "us _at_ eeecooks.com".gsub(/\s*_at_\s*/, '@'),
:subject => params[:subject],
:body => message)
haml :email
end
I implement the last step, that the form's subject should be pre-filled, with:
Then /^I should see a subject of "([^\"]*)"$/ do |subject|And now, I have the entire meal feedback scenario complete:
response.should have_selector("input",
:value => subject)
end
cstrom@jaynestown:~/repos/eee-code$ cucumber features -n \After driving-by-example a similar feedback link in the
-s "Give feedback to the authors on a yummy meal"
Sinatra::Test is deprecated; use Rack::Test instead.
Feature: Site
So that I may explore many wonderful recipes and see the meals in which they were served
As someone interested in cooking
I want to be able to easily explore this awesome site
Scenario: Give feedback to the authors on a yummy meal
Given a "Yummy" meal enjoyed on 2009-06-27
When I view the "Yummy" meal
And I click "Send us feedback on this meal"
Then I should see a feedback form
And I should see a subject of "[Meal] Yummy"
1 scenario
5 passed steps
recipe.haml
template, I can mark the recipe-feedback scenario as complete as well:cstrom@jaynestown:~/repos/eee-code$ cucumber features -n \Not bad—two scenarios done in one night. Up next: RSS Feeds.
> -s "Send compliments to the chef on a delicious recipe"
Sinatra::Test is deprecated; use Rack::Test instead.
Feature: Site
So that I may explore many wonderful recipes and see the meals in which they were served
As someone interested in cooking
I want to be able to easily explore this awesome site
Scenario: Send compliments to the chef on a delicious recipe
Given a recipe for Curried Shrimp
When I view the recipe
And I click "Send us feedback on this recipe"
Then I should see a feedback form
And I should see a subject of "[Recipe] Curried Shrimp"
1 scenario
5 passed steps
No comments:
Post a Comment