Sinatra integration tests for following redirects

This commit is contained in:
Josh Knowles 2009-01-04 22:34:47 -05:00
parent c3120833b0
commit 34ea3e64b8
4 changed files with 9 additions and 13 deletions

View File

@ -22,7 +22,6 @@ module Webrat
path, data, headers = *args
params = data.merge(:env => headers || {})
self.__send__("#{verb}_it", path, params)
request_page(response.location, :get, {}) while response.redirect?
end
end
end

View File

@ -10,6 +10,10 @@ end
get "/go" do
erb :go
end
get "/redirect" do
redirect "/"
end
post "/go" do
@user = params[:name]

View File

@ -16,4 +16,9 @@ class WebratTest < Test::Unit::TestCase
assert response_body.include?("Hello, World")
end
def test_follows_redirects
visit "/redirect"
assert response_body.include?("visit")
end
end

View File

@ -4,8 +4,6 @@ describe Webrat::SinatraSession, "API" do
before :each do
Webrat.configuration.mode = :sinatra
@sinatra_session = Webrat::SinatraSession.new
@response = mock("response", :redirect? => false)
@sinatra_session.stub!(:response => @response)
end
it "should delegate get to get_it" do
@ -27,14 +25,4 @@ describe Webrat::SinatraSession, "API" do
@sinatra_session.should_receive(:delete_it).with("url", { :env => "headers" })
@sinatra_session.delete("url", {}, "headers")
end
it "should use Session#request_page to handle redirects" do
@response.should_receive(:redirect?).twice.and_return(true, false)
@response.should_receive(:location).and_return("redirect url")
@sinatra_session.should_receive(:get_it).with("original url", { :env => "headers" })
@sinatra_session.should_receive(:request_page).with("redirect url", :get, {})
@sinatra_session.get("original url", {}, "headers")
end
end