webrat/lib/webrat/merb.rb

50 lines
1.1 KiB
Ruby

Dir[File.join(File.dirname(__FILE__), "merb", "*.rb")].sort.each do |file|
require File.expand_path(file)
end
module Webrat
class Session
include Merb::Test::RequestHelper
attr_reader :response
def get(url, data, headers = nil)
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
def response_code
@response.status
end
protected
def do_request(url, data, headers, method)
@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
end
end
class Merb::Test::RspecStory
def browser
@browser ||= Webrat::Session.new
end
end