Unescape the values passed to the sinatra test helpers

This commit is contained in:
Nicolas Sanguinetti 2009-01-01 12:42:05 -02:00 committed by Josh Knowles
parent 34ea3e64b8
commit 4565a3cea6
3 changed files with 14 additions and 3 deletions

View File

@ -20,6 +20,7 @@ module Webrat
%w(get head post put delete).each do |verb|
define_method(verb) do |*args| # (path, data, headers = nil)
path, data, headers = *args
data = data.inject({}) {|data, (key,value)| data[key] = Rack::Utils.unescape(value); data }
params = data.merge(:env => headers || {})
self.__send__("#{verb}_it", path, params)
end

View File

@ -17,6 +17,7 @@ end
post "/go" do
@user = params[:name]
@email = params[:email]
erb :hello
end
@ -36,10 +37,17 @@ __END__
@@ go
<form method="post" action="/go">
<div>
<label for="name">Name</label>
<input type="text" name="name" id="name">
</div>
<div>
<label for="email">Email</label>
<input type="text" name="email" id="email">
</div>
<input type="submit" value="Submit" />
</form>
@@ hello
<p>Hello, <%= @user %></p>
<p>Your email is: <%= @email %></p>

View File

@ -12,9 +12,11 @@ class WebratTest < Test::Unit::TestCase
def test_submits_form
visit "/go"
fill_in "Name", :with => "World"
fill_in "Email", :with => "world@example.org"
click_button "Submit"
assert response_body.include?("Hello, World")
assert response_body.include?("Your email is: world@example.org")
end
def test_follows_redirects