2008-12-25 22:58:56 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
|
|
|
|
2008-12-29 08:05:04 +00:00
|
|
|
describe Webrat::SinatraSession, "API" do
|
2008-12-25 22:58:56 +00:00
|
|
|
before :each do
|
2008-12-29 00:35:42 +00:00
|
|
|
Webrat.configuration.mode = :sinatra
|
2008-12-25 22:58:56 +00:00
|
|
|
@sinatra_session = Webrat::SinatraSession.new
|
|
|
|
|
|
|
|
@response = mock(:response)
|
|
|
|
@response.stub!(:redirect?)
|
|
|
|
|
|
|
|
@sinatra_session.instance_variable_set("@response", @response)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should delegate get to get_it" do
|
|
|
|
@sinatra_session.should_receive(:get_it).with("url", { :env => "headers" })
|
|
|
|
@sinatra_session.get("url", {}, "headers")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should delegate post to post_it" do
|
|
|
|
@sinatra_session.should_receive(:post_it).with("url", { :env => "headers" })
|
|
|
|
@sinatra_session.post("url", {}, "headers")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should delegate put to put_it" do
|
|
|
|
@sinatra_session.should_receive(:put_it).with("url", { :env => "headers" })
|
|
|
|
@sinatra_session.put("url", {}, "headers")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should delegate delete to delete_it" do
|
|
|
|
@sinatra_session.should_receive(:delete_it).with("url", { :env => "headers" })
|
|
|
|
@sinatra_session.delete("url", {}, "headers")
|
|
|
|
end
|
2008-12-25 23:28:54 +00:00
|
|
|
|
2008-12-29 08:05:04 +00:00
|
|
|
it "should use Session#request_page to handle redirects" do
|
2008-12-25 23:28:54 +00:00
|
|
|
@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" })
|
2008-12-29 08:05:04 +00:00
|
|
|
@sinatra_session.should_receive(:request_page).with("redirect url", :get, {})
|
2008-12-25 23:28:54 +00:00
|
|
|
|
|
|
|
@sinatra_session.get("original url", {}, "headers")
|
|
|
|
end
|
2008-12-29 00:35:42 +00:00
|
|
|
end
|