Browse files

Correctly throwing exception if controller used is not the controller…

… that should have been tested
  • Loading branch information...
1 parent e5bc712 commit 4f2c4b391b580060a83c75bdf3b2e863d68493c4 @gus gus committed Jun 2, 2010
Showing with 8 additions and 2 deletions.
  1. +7 −1 lib/riot/action_controller/http_methods.rb
  2. +1 −1 test/action_controller/get_request_test.rb
View
8 lib/riot/action_controller/http_methods.rb
@@ -11,7 +11,13 @@ def get(uri, params={}, &block)
http_reset
@env = ::Rack::MockRequest.env_for(uri, {:params => params})
@env['action_dispatch.show_exceptions'] = false
- @app.call(@env)
+ returning(@app.call(@env)) do |call_response|
+ c = @env["action_controller.instance"]
+ unless c.class.controller_name == topic.controller_name
+ msg = "Expected #{topic.controller_name} controller, not #{c.class.controller_name}"
+ raise ControllerMismatch, msg
+ end
+ end
end
def post; raise Exception, "POST isn't ready yet"; end
View
2 test/action_controller/get_request_test.rb
@@ -7,7 +7,7 @@
end.raises(AbstractController::ActionNotFound, "The action 'blah' could not be found")
asserts("controller does not match the one under test") do
- get "/gremlins/2"
+ get "/gremlins"
end.raises(RiotRails::ActionController::ControllerMismatch, "Expected rooms controller, not gremlins")
context "for a GET request" do

0 comments on commit 4f2c4b3

Please sign in to comment.