alexandernst alexandernst - 22 days ago 9
Ruby Question

Rspec not matching my route

I have

post '/foo/bar', to: 'api/v1/things#bar'
in my
routes.rb
.

Running
rails routes
returns

foo_bar POST /foo/bar(.:format) api/v1/things#bar


I'm trying to test it with
post '/foo/bar'
, but I get

No route matches {:action=>"/foo/bar", :controller=>"api/v1/things"}


I know the problem is something silly, but I'm unable to see it. Any ideas?

Answer

Routing is not a thing when you run controller specs.

Use:

post 'bar'

Very likely there is describe API::V1:Things do around this test, this tells RSpec which controller to use.