Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

route throws TypeError instead of Minitest::Assertion #1489

Open
josemigallas opened this issue Feb 16, 2022 · 1 comment
Open

route throws TypeError instead of Minitest::Assertion #1489

josemigallas opened this issue Feb 16, 2022 · 1 comment

Comments

@josemigallas
Copy link

I'm upgrading shoulda-matchers to 4.5.1 and the following test:

should route(:get, '/stats/api/applications/42/usage').to(id: '42')

returns the following output:

Error:
Stats::Api::ApplicationsControllerTest#test_: Stats::Api::ApplicationsController should route GET /stats/api/applications/42/usage to/from {:id=>"42", :action=>"usage", :format=>:json}. :
TypeError: class or module required for rescue clause

After some debugging it seems that route_recognized? is throwing the assertion error but not rescuing properly:

From: /Users/jgallaso/projects/3scale/porta/vendor/bundle/ruby/2.6.0/gems/shoulda-matchers-4.5.1/lib/shoulda/matchers/action_controller/route_matcher.rb:193 Shoulda::Matchers::ActionController::RouteMatcher#route_recognized?:

    191: def route_recognized?
    192:   binding.pry
 => 193:   context.send(
    194:     :assert_routing,
    195:     { method: method, path: path },
    196:     params,
    197:   )
    198:   true
    199: rescue ::ActionController::RoutingError => e
    200:   @failure_message = e.message
    201:   false
    202: rescue Shoulda::Matchers.assertion_exception_class => e
    203:   @failure_message = e.message
    204:   false
    205: end

[3] pry(#<Shoulda::Matchers::ActionController::RouteMatcher>)> context.send(
[3] pry(#<Shoulda::Matchers::ActionController::RouteMatcher>)* :assert_routing, { method: method, path:path }, params)   
Minitest::Assertion: The recognized options <{"controller"=>"stats/api/applications", "action"=>"usage", "application_id"=>"42", "format"=>"json"}> did not match <{"id"=>"42", "controller"=>"stats/api/applications"}>, difference:.
--- expected
+++ actual
@@ -1 +1 @@
-{"id"=>"42", "controller"=>"stats/api/applications"}
+{"controller"=>"stats/api/applications", "action"=>"usage", "application_id"=>"42" }

Is this something already known? If so, I would gladly submit a PR to fix it.

@mcmire
Copy link
Collaborator

mcmire commented Feb 16, 2022

Most people use shoulda-matchers with RSpec these days, so if there's an issue with Minitest then it's possible that there's a bug that we haven't patched yet. Feel free to submit a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants