Merge commit '1bfe7634f8bb93472f4f53715d43916a8ff1569f'

This commit is contained in:
Bryan Helmkamp 2009-01-20 00:26:36 -05:00
commit d60f524df1
2 changed files with 14 additions and 12 deletions

View File

@ -1,6 +1,6 @@
require 'webrat/rack' require 'webrat/rack'
require 'sinatra' require 'sinatra'
require 'sinatra/test/methods' require 'sinatra/test'
class Sinatra::Application class Sinatra::Application
# Override this to prevent Sinatra from barfing on the options passed from RSpec # Override this to prevent Sinatra from barfing on the options passed from RSpec
@ -11,18 +11,20 @@ end
disable :run disable :run
disable :reload disable :reload
require 'ruby-debug'
module Webrat module Webrat
class SinatraSession < RackSession #:nodoc: class SinatraSession < RackSession #:nodoc:
include Sinatra::Test::Methods include Sinatra::Test
attr_reader :request, :response attr_reader :request, :response
%w(get head post put delete).each do |verb| %w(get head post put delete).each do |verb|
alias_method "orig_#{verb}", verb
define_method(verb) do |*args| # (path, data, headers = nil) define_method(verb) do |*args| # (path, data, headers = nil)
path, data, headers = *args path, data, headers = *args
data = data.inject({}) {|data, (key,value)| data[key] = Rack::Utils.unescape(value); data } data = data.inject({}) {|data, (key,value)| data[key] = Rack::Utils.unescape(value); data }
params = data.merge(:env => headers || {}) params = data.merge(:env => headers || {})
self.__send__("#{verb}_it", path, params) self.__send__("orig_#{verb}", path, params)
end end
end end
end end

View File

@ -6,23 +6,23 @@ describe Webrat::SinatraSession, "API" do
@sinatra_session = Webrat::SinatraSession.new @sinatra_session = Webrat::SinatraSession.new
end end
it "should delegate get to get_it" do it "should delegate get to sinatras get" do
@sinatra_session.should_receive(:get_it).with("url", { :env => "headers" }) @sinatra_session.should_receive(:orig_get).with("url", { :env => "headers" })
@sinatra_session.get("url", {}, "headers") @sinatra_session.get("url", {}, "headers")
end end
it "should delegate post to post_it" do it "should delegate post to sinatras post" do
@sinatra_session.should_receive(:post_it).with("url", { :env => "headers" }) @sinatra_session.should_receive(:orig_post).with("url", { :env => "headers" })
@sinatra_session.post("url", {}, "headers") @sinatra_session.post("url", {}, "headers")
end end
it "should delegate put to put_it" do it "should delegate put to sinatras put" do
@sinatra_session.should_receive(:put_it).with("url", { :env => "headers" }) @sinatra_session.should_receive(:orig_put).with("url", { :env => "headers" })
@sinatra_session.put("url", {}, "headers") @sinatra_session.put("url", {}, "headers")
end end
it "should delegate delete to delete_it" do it "should delegate delete to sinatras delete" do
@sinatra_session.should_receive(:delete_it).with("url", { :env => "headers" }) @sinatra_session.should_receive(:orig_delete).with("url", { :env => "headers" })
@sinatra_session.delete("url", {}, "headers") @sinatra_session.delete("url", {}, "headers")
end end
end end