Deprecate the :sinatra mode

* I took the conservative approach here: the sinatra code could
  be removed but that'd cause a regression. (using Sinatra::Application
  when `app` is not defined)

* I left the sinatra tests for now; they should be removed
  once we're fully confident with rack session ones.
This commit is contained in:
Simon Rozet 2009-06-25 00:21:24 +02:00
parent 051dfe188c
commit a5a91b32e9
2 changed files with 7 additions and 34 deletions

View File

@ -18,14 +18,17 @@ module Webrat
RailsSession RailsSession
when :merb when :merb
MerbSession MerbSession
when :rack
RackSession
when :sinatra
warn("The :sinatra mode is deprecated. Please use :rack instead")
SinatraSession
when :selenium when :selenium
SeleniumSession SeleniumSession
when :sinatra when :sinatra
SinatraSession SinatraSession
when :mechanize when :mechanize
MechanizeSession MechanizeSession
when :rack
RackSession
else else
raise WebratError.new(<<-STR) raise WebratError.new(<<-STR)
Unknown Webrat mode: #{Webrat.configuration.mode.inspect} Unknown Webrat mode: #{Webrat.configuration.mode.inspect}

View File

@ -1,41 +1,11 @@
require "webrat/rack" require "webrat/rack"
require "sinatra/test"
module Webrat module Webrat
class SinatraSession class SinatraSession < RackSession
include Sinatra::Test
def initialize(context) def initialize(context)
app = context.respond_to?(:app) ? context.app : Sinatra::Application app = context.respond_to?(:app) ? context.app : Sinatra::Application
@browser = Sinatra::TestHarness.new(app) super(Rack::Test::Session.new(app))
end
%w(get head post put delete).each do |verb|
class_eval <<-RUBY
def #{verb}(path, data, headers = {})
params = data.inject({}) do |data, (key,value)|
data[key] = Rack::Utils.unescape(value)
data
end
headers["HTTP_HOST"] = "www.example.com"
@browser.#{verb}(path, params, headers)
end
RUBY
end
def response_body
@browser.body
end
def response_code
@browser.response.status
end
private
def response
@browser.response
end end
end end
end end