webrat/lib/webrat/merb.rb

66 lines
1.3 KiB
Ruby
Raw Normal View History

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
module Webrat
class MerbSession < Session #:nodoc:
2008-11-03 03:11:20 +00:00
include Merb::Test::MakeRequest
2008-11-03 03:11:20 +00:00
attr_accessor :response
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
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
end
2008-04-16 09:54:37 +00:00
end
2008-11-25 00:59:27 +00:00
module Merb #:nodoc:
module Test #:nodoc:
module RequestHelper #:nodoc:
2008-11-03 03:11:20 +00:00
def request(uri, env = {})
@_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
class Merb::Test::RspecStory #:nodoc:
def browser
@browser ||= Webrat::MerbSession.new
end
end