Implemented Merb's magic exception handling in tests. This could be more robust.

This commit is contained in:
Gwyn Morfey 2008-04-23 14:33:05 +01:00
parent 580a301984
commit 2855b4382f

View File

@ -42,9 +42,21 @@ class Merb::Test::RspecStory
def request_via_redirect(method,path,parameters={},headers={})
method = parameters["_method"] if !parameters["_method"].blank?
mycookies = defined?(@controller) ? @controller.cookies : nil #will be nil if no requests yet
begin
@controller=self.send(method, path, parameters, headers) do |new_controller|
new_controller.cookies = mycookies
end
rescue => exception
raise unless exception.kind_of?(Merb::ControllerExceptions::Base)
#Now we want to go one level below 'post' to build the request ourselves, then send it to the controller
exception_klass = exception.class
klass = ::Exceptions rescue Merb::Controller
request = fake_request
request.params[:exception] = exception
request.params[:action] = exception_klass.name
@controller=dispatch_request(request, klass, exception_klass.name)
end
follow_redirect! while redirect?
status
end