Decouple from Rails so we can use Webrat with Sinatra

This commit is contained in:
Aslak Hellesøy 2008-10-16 15:50:11 +02:00
parent 89d56fb5da
commit 682f4d19f9
4 changed files with 20 additions and 4 deletions

View File

@ -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)

View File

@ -106,11 +106,13 @@ module Webrat
def form_action def form_action
@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

View File

@ -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

View File

@ -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