From 2855b4382f7e6db9da68b7998b739567714a68ee Mon Sep 17 00:00:00 2001 From: Gwyn Morfey Date: Wed, 23 Apr 2008 14:33:05 +0100 Subject: [PATCH] Implemented Merb's magic exception handling in tests. This could be more robust. --- lib/boot_merb.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/boot_merb.rb b/lib/boot_merb.rb index e6f6e64..f02c28d 100644 --- a/lib/boot_merb.rb +++ b/lib/boot_merb.rb @@ -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 - @controller=self.send(method, path, parameters, headers) do |new_controller| - new_controller.cookies = mycookies + 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