diff --git a/lib/webrat/sinatra.rb b/lib/webrat/sinatra.rb index e71bba5..ea74b52 100644 --- a/lib/webrat/sinatra.rb +++ b/lib/webrat/sinatra.rb @@ -1,6 +1,6 @@ require 'webrat/rack' require 'sinatra' -require 'sinatra/test/methods' +require 'sinatra/test' class Sinatra::Application # Override this to prevent Sinatra from barfing on the options passed from RSpec @@ -11,18 +11,20 @@ end disable :run disable :reload +require 'ruby-debug' module Webrat class SinatraSession < RackSession #:nodoc: - include Sinatra::Test::Methods + include Sinatra::Test attr_reader :request, :response %w(get head post put delete).each do |verb| + alias_method "orig_#{verb}", 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) + self.__send__("orig_#{verb}", path, params) end end end diff --git a/spec/private/sinatra/sinatra_session_spec.rb b/spec/private/sinatra/sinatra_session_spec.rb index 3fdfaad..0643f79 100644 --- a/spec/private/sinatra/sinatra_session_spec.rb +++ b/spec/private/sinatra/sinatra_session_spec.rb @@ -6,23 +6,23 @@ describe Webrat::SinatraSession, "API" do @sinatra_session = Webrat::SinatraSession.new end - it "should delegate get to get_it" do - @sinatra_session.should_receive(:get_it).with("url", { :env => "headers" }) + it "should delegate get to sinatras get" do + @sinatra_session.should_receive(:orig_get).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" }) + it "should delegate post to sinatras post" do + @sinatra_session.should_receive(:orig_post).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" }) + it "should delegate put to sinatras put" do + @sinatra_session.should_receive(:orig_put).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" }) + it "should delegate delete to sinatras delete" do + @sinatra_session.should_receive(:orig_delete).with("url", { :env => "headers" }) @sinatra_session.delete("url", {}, "headers") end -end \ No newline at end of file +end