2008-11-24 00:46:37 +00:00
|
|
|
require "webrat"
|
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 17:13:41 +00:00
|
|
|
class MerbSession < Session #:nodoc:
|
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,
|
2008-11-07 16:35:53 +00:00
|
|
|
:headers => headers,
|
|
|
|
:method => method)
|
2008-10-21 12:05:35 +00:00
|
|
|
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-25 00:59:27 +00:00
|
|
|
module Merb #:nodoc:
|
|
|
|
module Test #:nodoc:
|
2008-11-07 17:13:41 +00:00
|
|
|
module RequestHelper #:nodoc:
|
2008-11-03 03:11:20 +00:00
|
|
|
def request(uri, env = {})
|
2008-11-07 22:04:01 +00:00
|
|
|
@_webrat_session ||= Webrat::MerbSession.new
|
|
|
|
@_webrat_session.response = @_webrat_session.request(uri, env)
|
2008-11-03 03:11:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-07 17:13:41 +00:00
|
|
|
class Merb::Test::RspecStory #:nodoc:
|
2008-10-18 07:38:25 +00:00
|
|
|
def browser
|
2008-11-07 16:33:51 +00:00
|
|
|
@browser ||= Webrat::MerbSession.new
|
2008-04-16 16:12:31 +00:00
|
|
|
end
|
|
|
|
end
|