Decouple from Rails so we can use Webrat with Sinatra
This commit is contained in:
parent
89d56fb5da
commit
682f4d19f9
@ -3,7 +3,6 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
require "rubygems"
|
require "rubygems"
|
||||||
require "active_support"
|
|
||||||
|
|
||||||
require File.dirname(__FILE__) + "/webrat/core"
|
require File.dirname(__FILE__) + "/webrat/core"
|
||||||
require File.dirname(__FILE__) + "/webrat/rails" if defined?(RAILS_ENV)
|
require File.dirname(__FILE__) + "/webrat/rails" if defined?(RAILS_ENV)
|
||||||
|
@ -107,10 +107,12 @@ module Webrat
|
|||||||
@element["action"].blank? ? @session.current_url : @element["action"]
|
@element["action"].blank? ? @session.current_url : @element["action"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
HASH = [Hash, HashWithIndifferentAccess] rescue [Hash]
|
||||||
|
|
||||||
def merge(all_params, new_param)
|
def merge(all_params, new_param)
|
||||||
new_param.each do |key, value|
|
new_param.each do |key, value|
|
||||||
case all_params[key]
|
case all_params[key]
|
||||||
when Hash, HashWithIndifferentAccess
|
when *HASH
|
||||||
merge_hash_values(all_params[key], value)
|
merge_hash_values(all_params[key], value)
|
||||||
when Array
|
when Array
|
||||||
all_params[key] += value
|
all_params[key] += value
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
require 'webrat'
|
require 'webrat'
|
||||||
|
|
||||||
|
class CGIMethods
|
||||||
|
def self.parse_query_parameters(params)
|
||||||
|
hash = {}
|
||||||
|
params.split('&').each do |p|
|
||||||
|
pair = p.split('=')
|
||||||
|
hash[pair[0]] = pair[1]
|
||||||
|
end
|
||||||
|
hash
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class RackSession < Session
|
class RackSession < Session
|
||||||
def response_body
|
def response_body
|
||||||
|
@ -6,8 +6,12 @@ module Webrat
|
|||||||
class SinatraSession < RackSession
|
class SinatraSession < RackSession
|
||||||
include Sinatra::Test::Methods
|
include Sinatra::Test::Methods
|
||||||
|
|
||||||
def get(*args)
|
def get(url, data, headers = nil)
|
||||||
get_it(*args)
|
get_it(url, data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def post(url, data, headers = nil)
|
||||||
|
post_it(url, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user