Skip to content

Commit

Permalink
Deprecate the :sinatra mode
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
sr committed Jun 24, 2009
1 parent 051dfe1 commit a5a91b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
7 changes: 5 additions & 2 deletions lib/webrat/core/session.rb
Expand Up @@ -18,14 +18,17 @@ def self.session_class
RailsSession
when :merb
MerbSession
when :rack
RackSession
when :sinatra
warn("The :sinatra mode is deprecated. Please use :rack instead")
SinatraSession
when :selenium
SeleniumSession
when :sinatra
SinatraSession
when :mechanize
MechanizeSession
when :rack
RackSession
else
raise WebratError.new(<<-STR)
Unknown Webrat mode: #{Webrat.configuration.mode.inspect}
Expand Down
34 changes: 2 additions & 32 deletions lib/webrat/sinatra.rb
@@ -1,41 +1,11 @@
require "webrat/rack"
require "sinatra/test"

module Webrat
class SinatraSession
include Sinatra::Test

class SinatraSession < RackSession
def initialize(context)
app = context.respond_to?(:app) ? context.app : Sinatra::Application

@browser = Sinatra::TestHarness.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
super(Rack::Test::Session.new(app))
end

def response_code
@browser.response.status
end

private

def response
@browser.response
end
end
end

0 comments on commit a5a91b3

Please sign in to comment.