Temporary shim to support Merb's require statement for Webrat
This commit is contained in:
parent
fdb94f399c
commit
00d0d7b438
@ -71,8 +71,16 @@ module Webrat
|
||||
# :rails, :selenium, :rack, :sinatra, :mechanize, :merb
|
||||
def mode=(mode)
|
||||
@mode = mode
|
||||
|
||||
# This is a temporary hack to support backwards compatibility
|
||||
# with Merb 1.0.8 until it's updated to use the new Webrat.configure
|
||||
# syntax
|
||||
if @mode.to_s == "merb"
|
||||
require("webrat/merb_session")
|
||||
else
|
||||
require("webrat/#{mode}")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,65 +1,9 @@
|
||||
require "webrat"
|
||||
|
||||
require "cgi"
|
||||
gem "extlib"
|
||||
require "extlib"
|
||||
require "merb-core"
|
||||
# This is a temporary hack to support backwards compatibility
|
||||
# with Merb 1.0.8 until it's updated to use the new Webrat.configure
|
||||
# syntax
|
||||
|
||||
HashWithIndifferentAccess = Mash
|
||||
|
||||
module Webrat
|
||||
class MerbSession < Session #:nodoc:
|
||||
include Merb::Test::MakeRequest
|
||||
|
||||
attr_accessor :response
|
||||
|
||||
def get(url, data, headers = nil)
|
||||
do_request(url, data, headers, "GET")
|
||||
end
|
||||
|
||||
def post(url, data, headers = nil)
|
||||
do_request(url, data, headers, "POST")
|
||||
end
|
||||
|
||||
def put(url, data, headers = nil)
|
||||
do_request(url, data, headers, "PUT")
|
||||
end
|
||||
|
||||
def delete(url, data, headers = nil)
|
||||
do_request(url, data, headers, "DELETE")
|
||||
end
|
||||
|
||||
def response_body
|
||||
@response.body.to_s
|
||||
end
|
||||
|
||||
def response_code
|
||||
@response.status
|
||||
end
|
||||
|
||||
def do_request(url, data, headers, method)
|
||||
@response = request(url,
|
||||
:params => (data && data.any?) ? data : nil,
|
||||
:headers => headers,
|
||||
:method => method)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
module Merb #:nodoc:
|
||||
module Test #:nodoc:
|
||||
module RequestHelper #:nodoc:
|
||||
def request(uri, env = {})
|
||||
@_webrat_session ||= Webrat::MerbSession.new
|
||||
@_webrat_session.response = @_webrat_session.request(uri, env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Merb::Test::RspecStory #:nodoc:
|
||||
def browser
|
||||
@browser ||= Webrat::MerbSession.new
|
||||
end
|
||||
Webrat.configure do |config|
|
||||
config.mode = :merb
|
||||
end
|
65
lib/webrat/merb_session.rb
Normal file
65
lib/webrat/merb_session.rb
Normal file
@ -0,0 +1,65 @@
|
||||
require "webrat"
|
||||
|
||||
require "cgi"
|
||||
gem "extlib"
|
||||
require "extlib"
|
||||
require "merb-core"
|
||||
|
||||
HashWithIndifferentAccess = Mash
|
||||
|
||||
module Webrat
|
||||
class MerbSession < Session #:nodoc:
|
||||
include Merb::Test::MakeRequest
|
||||
|
||||
attr_accessor :response
|
||||
|
||||
def get(url, data, headers = nil)
|
||||
do_request(url, data, headers, "GET")
|
||||
end
|
||||
|
||||
def post(url, data, headers = nil)
|
||||
do_request(url, data, headers, "POST")
|
||||
end
|
||||
|
||||
def put(url, data, headers = nil)
|
||||
do_request(url, data, headers, "PUT")
|
||||
end
|
||||
|
||||
def delete(url, data, headers = nil)
|
||||
do_request(url, data, headers, "DELETE")
|
||||
end
|
||||
|
||||
def response_body
|
||||
@response.body.to_s
|
||||
end
|
||||
|
||||
def response_code
|
||||
@response.status
|
||||
end
|
||||
|
||||
def do_request(url, data, headers, method)
|
||||
@response = request(url,
|
||||
:params => (data && data.any?) ? data : nil,
|
||||
:headers => headers,
|
||||
:method => method)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
module Merb #:nodoc:
|
||||
module Test #:nodoc:
|
||||
module RequestHelper #:nodoc:
|
||||
def request(uri, env = {})
|
||||
@_webrat_session ||= Webrat::MerbSession.new
|
||||
@_webrat_session.response = @_webrat_session.request(uri, env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Merb::Test::RspecStory #:nodoc:
|
||||
def browser
|
||||
@browser ||= Webrat::MerbSession.new
|
||||
end
|
||||
end
|
@ -52,7 +52,6 @@ describe Webrat::Configuration do
|
||||
:selenium,
|
||||
:rack,
|
||||
:sinatra,
|
||||
:merb,
|
||||
:mechanize].each do |mode|
|
||||
it "should require correct lib when in #{mode} mode" do
|
||||
config = Webrat::Configuration.new
|
||||
@ -61,6 +60,12 @@ describe Webrat::Configuration do
|
||||
end
|
||||
end
|
||||
|
||||
it "should require merb_session when in merb mode" do
|
||||
config = Webrat::Configuration.new
|
||||
config.should_receive(:require).with("webrat/merb_session")
|
||||
config.mode = :merb
|
||||
end
|
||||
|
||||
describe "Selenium" do
|
||||
before :each do
|
||||
@config = Webrat::Configuration.new
|
||||
|
Loading…
Reference in New Issue
Block a user