Implemented Merb's magic exception handling in tests. This could be more robust.
This commit is contained in:
parent
580a301984
commit
2855b4382f
@ -42,9 +42,21 @@ class Merb::Test::RspecStory
|
|||||||
def request_via_redirect(method,path,parameters={},headers={})
|
def request_via_redirect(method,path,parameters={},headers={})
|
||||||
method = parameters["_method"] if !parameters["_method"].blank?
|
method = parameters["_method"] if !parameters["_method"].blank?
|
||||||
mycookies = defined?(@controller) ? @controller.cookies : nil #will be nil if no requests yet
|
mycookies = defined?(@controller) ? @controller.cookies : nil #will be nil if no requests yet
|
||||||
|
begin
|
||||||
@controller=self.send(method, path, parameters, headers) do |new_controller|
|
@controller=self.send(method, path, parameters, headers) do |new_controller|
|
||||||
new_controller.cookies = mycookies
|
new_controller.cookies = mycookies
|
||||||
end
|
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?
|
follow_redirect! while redirect?
|
||||||
status
|
status
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user