Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
2 changed files
with
7 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |