Restructuring files
This commit is contained in:
parent
828b7d4c2c
commit
ce9235f0fa
|
@ -10,9 +10,12 @@ module Webrat
|
|||
end
|
||||
end
|
||||
|
||||
# require "webrat/merb/param_parser"
|
||||
# require "webrat/merb/url_encoded_pair_parser"
|
||||
require "webrat/core"
|
||||
|
||||
require "webrat/rails" if defined?(RAILS_ENV)
|
||||
require "webrat/merb" if defined?(Merb)
|
||||
# TODO: This is probably not a good idea.
|
||||
# Probably better for webrat users to require "webrat/rails" etc. directly
|
||||
if defined?(RAILS_ENV)
|
||||
require "webrat/rails"
|
||||
elsif defined?(Merb)
|
||||
require "webrat/merb"
|
||||
end
|
||||
|
|
|
@ -1,3 +1,28 @@
|
|||
require "mechanize"
|
||||
require "webrat/mechanize/mechanize_session"
|
||||
|
||||
module Webrat
|
||||
class MechanizeSession < Session
|
||||
|
||||
def initialize(mechanize = WWW::Mechanize.new)
|
||||
super()
|
||||
@mechanize = mechanize
|
||||
end
|
||||
|
||||
def get(url, data)
|
||||
@mechanize_page = @mechanize.get(url, data)
|
||||
end
|
||||
|
||||
def post(url, data)
|
||||
@mechanize_page = @mechanize.post(url, data)
|
||||
end
|
||||
|
||||
def response_body
|
||||
@mechanize_page.content
|
||||
end
|
||||
|
||||
def response_code
|
||||
@mechanize_page.code.to_i
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
module Webrat
|
||||
class MechanizeSession < Session
|
||||
|
||||
def initialize(mechanize = WWW::Mechanize.new)
|
||||
super()
|
||||
@mechanize = mechanize
|
||||
end
|
||||
|
||||
def get(url, data)
|
||||
@mechanize_page = @mechanize.get(url, data)
|
||||
end
|
||||
|
||||
def post(url, data)
|
||||
@mechanize_page = @mechanize.post(url, data)
|
||||
end
|
||||
|
||||
def response_body
|
||||
@mechanize_page.content
|
||||
end
|
||||
|
||||
def response_code
|
||||
@mechanize_page.code.to_i
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,4 +1,101 @@
|
|||
require "webrat/core"
|
||||
require "webrat/rails/redirect_actions"
|
||||
require "webrat/rails/rails_session"
|
||||
require "webrat/rails/session"
|
||||
require "webrat"
|
||||
|
||||
module Webrat
|
||||
class RailsSession < Session
|
||||
|
||||
def initialize(integration_session)
|
||||
super()
|
||||
@integration_session = integration_session
|
||||
end
|
||||
|
||||
def doc_root
|
||||
File.expand_path(File.join(RAILS_ROOT, 'public'))
|
||||
end
|
||||
|
||||
def saved_page_dir
|
||||
File.expand_path(File.join(RAILS_ROOT, "tmp"))
|
||||
end
|
||||
|
||||
def get(url, data, headers = nil)
|
||||
update_protocol(url)
|
||||
@integration_session.get_via_redirect(remove_protocol(url), data, headers)
|
||||
end
|
||||
|
||||
def post(url, data, headers = nil)
|
||||
update_protocol(url)
|
||||
@integration_session.post_via_redirect(remove_protocol(url), data, headers)
|
||||
end
|
||||
|
||||
def put(url, data, headers = nil)
|
||||
update_protocol(url)
|
||||
@integration_session.put_via_redirect(remove_protocol(url), data, headers)
|
||||
end
|
||||
|
||||
def delete(url, data, headers = nil)
|
||||
update_protocol(url)
|
||||
@integration_session.delete_via_redirect(remove_protocol(url), data, headers)
|
||||
end
|
||||
|
||||
def response_body
|
||||
response.body
|
||||
end
|
||||
|
||||
def response_code
|
||||
response.code.to_i
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def remove_protocol(href)
|
||||
if href =~ %r{^https?://www.example.com(/.*)}
|
||||
$LAST_MATCH_INFO.captures.first
|
||||
else
|
||||
href
|
||||
end
|
||||
end
|
||||
|
||||
def update_protocol(href)
|
||||
if href =~ /^https:/
|
||||
@integration_session.https!(true)
|
||||
elsif href =~ /^http:/
|
||||
@integration_session.https!(false)
|
||||
end
|
||||
end
|
||||
|
||||
def response
|
||||
@integration_session.response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
module ActionController
|
||||
module Integration
|
||||
class Session
|
||||
|
||||
unless instance_methods.include?("put_via_redirect")
|
||||
require "webrat/rails/redirect_actions"
|
||||
include Webrat::RedirectActions
|
||||
end
|
||||
|
||||
def respond_to?(name)
|
||||
super || webrat_session.respond_to?(name)
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
if webrat_session.respond_to?(name)
|
||||
webrat_session.send(name, *args, &block)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def webrat_session
|
||||
@webrat_session ||= Webrat::RailsSession.new(self)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,68 +0,0 @@
|
|||
module Webrat
|
||||
class RailsSession < Session
|
||||
|
||||
def initialize(integration_session)
|
||||
super()
|
||||
@integration_session = integration_session
|
||||
end
|
||||
|
||||
def doc_root
|
||||
File.expand_path(File.join(RAILS_ROOT, 'public'))
|
||||
end
|
||||
|
||||
def saved_page_dir
|
||||
File.expand_path(File.join(RAILS_ROOT, "tmp"))
|
||||
end
|
||||
|
||||
def get(url, data, headers = nil)
|
||||
update_protocol(url)
|
||||
@integration_session.get_via_redirect(remove_protocol(url), data, headers)
|
||||
end
|
||||
|
||||
def post(url, data, headers = nil)
|
||||
update_protocol(url)
|
||||
@integration_session.post_via_redirect(remove_protocol(url), data, headers)
|
||||
end
|
||||
|
||||
def put(url, data, headers = nil)
|
||||
update_protocol(url)
|
||||
@integration_session.put_via_redirect(remove_protocol(url), data, headers)
|
||||
end
|
||||
|
||||
def delete(url, data, headers = nil)
|
||||
update_protocol(url)
|
||||
@integration_session.delete_via_redirect(remove_protocol(url), data, headers)
|
||||
end
|
||||
|
||||
def response_body
|
||||
response.body
|
||||
end
|
||||
|
||||
def response_code
|
||||
response.code.to_i
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def remove_protocol(href)
|
||||
if href =~ %r{^https?://www.example.com(/.*)}
|
||||
$LAST_MATCH_INFO.captures.first
|
||||
else
|
||||
href
|
||||
end
|
||||
end
|
||||
|
||||
def update_protocol(href)
|
||||
if href =~ /^https:/
|
||||
@integration_session.https!(true)
|
||||
elsif href =~ /^http:/
|
||||
@integration_session.https!(false)
|
||||
end
|
||||
end
|
||||
|
||||
def response
|
||||
@integration_session.response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,29 +0,0 @@
|
|||
module ActionController
|
||||
module Integration
|
||||
class Session
|
||||
|
||||
unless instance_methods.include?("put_via_redirect")
|
||||
include Webrat::RedirectActions
|
||||
end
|
||||
|
||||
def respond_to?(name)
|
||||
super || webrat_session.respond_to?(name)
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
if webrat_session.respond_to?(name)
|
||||
webrat_session.send(name, *args, &block)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def webrat_session
|
||||
@webrat_session ||= Webrat::RailsSession.new(self)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
require 'webrat/rack/rack_session'
|
||||
require 'webrat/rack'
|
||||
require 'sinatra'
|
||||
require 'sinatra/test/methods'
|
||||
|
Loading…
Reference in New Issue