webrat/lib/webrat/merb.rb

75 lines
1.5 KiB
Ruby
Raw Normal View History

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
module Webrat
class MerbSession < Session
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,
: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
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 = {})
@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
class Merb::Test::RspecStory
def browser
@browser ||= Webrat::MerbSession.new
end
end
2008-10-21 12:24:35 +00:00