2008-10-25 16:59:21 +00:00
|
|
|
require "webrat/core"
|
2008-10-21 15:29:06 +00:00
|
|
|
|
2008-11-04 01:11:26 +00:00
|
|
|
require "cgi"
|
|
|
|
gem "extlib"
|
|
|
|
require "extlib"
|
|
|
|
require "merb-core"
|
|
|
|
|
|
|
|
HashWithIndifferentAccess = Mash
|
|
|
|
|
2008-10-06 03:05:01 +00:00
|
|
|
module Webrat
|
2008-11-07 16:33:51 +00:00
|
|
|
class MerbSession < Session
|
2008-11-03 03:11:20 +00:00
|
|
|
include Merb::Test::MakeRequest
|
2008-10-18 07:38:25 +00:00
|
|
|
|
2008-11-03 03:11:20 +00:00
|
|
|
attr_accessor :response
|
2008-10-18 07:38:25 +00:00
|
|
|
|
|
|
|
def get(url, data, headers = nil)
|
2008-10-21 12:05:35 +00:00
|
|
|
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
|
2008-04-16 16:12:31 +00:00
|
|
|
end
|
2008-10-21 12:24:35 +00:00
|
|
|
|
|
|
|
def response_code
|
|
|
|
@response.status
|
|
|
|
end
|
2008-10-25 16:59:21 +00:00
|
|
|
|
2008-10-21 12:05:35 +00:00
|
|
|
def do_request(url, data, headers, method)
|
2008-11-03 03:11:20 +00:00
|
|
|
@response = request(url,
|
|
|
|
:params => (data && data.any?) ? data : nil,
|
|
|
|
:headers => headers, :method => method)
|
|
|
|
self.get(@response.headers['Location'], nil, @response.headers) if @response.status == 302
|
|
|
|
end
|
|
|
|
|
|
|
|
def follow_redirect
|
2008-10-21 12:05:35 +00:00
|
|
|
self.get(@response.headers['Location'], nil, @response.headers) if @response.status == 302
|
|
|
|
end
|
2008-10-21 12:19:50 +00:00
|
|
|
|
2008-10-06 03:05:01 +00:00
|
|
|
end
|
2008-04-16 09:54:37 +00:00
|
|
|
end
|
|
|
|
|
2008-11-03 03:11:20 +00:00
|
|
|
module Merb
|
|
|
|
module Test
|
|
|
|
module RequestHelper
|
|
|
|
def request(uri, env = {})
|
2008-11-07 16:33:51 +00:00
|
|
|
@session ||= Webrat::MerbSession.new
|
2008-11-03 03:11:20 +00:00
|
|
|
@session.response = @session.request(uri, env)
|
|
|
|
end
|
|
|
|
|
|
|
|
def follow_redirect
|
|
|
|
@session.follow_redirect
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-18 07:38:25 +00:00
|
|
|
class Merb::Test::RspecStory
|
|
|
|
def browser
|
2008-11-07 16:33:51 +00:00
|
|
|
@browser ||= Webrat::MerbSession.new
|
2008-04-16 16:12:31 +00:00
|
|
|
end
|
|
|
|
end
|
2008-10-21 12:24:35 +00:00
|
|
|
|