Skip to content

Commit

Permalink
Correctly throwing exception if controller used is not the controller…
Browse files Browse the repository at this point in the history
… that should have been tested
  • Loading branch information
gus committed Jun 2, 2010
1 parent e5bc712 commit 4f2c4b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/riot/action_controller/http_methods.rb
Expand Up @@ -11,7 +11,13 @@ def get(uri, params={}, &block)
http_reset http_reset
@env = ::Rack::MockRequest.env_for(uri, {:params => params}) @env = ::Rack::MockRequest.env_for(uri, {:params => params})
@env['action_dispatch.show_exceptions'] = false @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 end


def post; raise Exception, "POST isn't ready yet"; end def post; raise Exception, "POST isn't ready yet"; end
Expand Down
2 changes: 1 addition & 1 deletion test/action_controller/get_request_test.rb
Expand Up @@ -7,7 +7,7 @@
end.raises(AbstractController::ActionNotFound, "The action 'blah' could not be found") end.raises(AbstractController::ActionNotFound, "The action 'blah' could not be found")


asserts("controller does not match the one under test") do 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") end.raises(RiotRails::ActionController::ControllerMismatch, "Expected rooms controller, not gremlins")


context "for a GET request" do context "for a GET request" do
Expand Down

0 comments on commit 4f2c4b3

Please sign in to comment.