manju
manju

Reputation: 11

ArgumentError: unknown keyword: use_route after rails 5 upgrade

I searched about use_route for controller specs and came to know, this has been removed without any replacement. How should this type specs be replaced?

Upvotes: 0

Views: 1367

Answers (2)

swiknaba
swiknaba

Reputation: 83

A bit late to the party, but for our future googlers, have a look here: https://relishapp.com/rspec/rspec-rails/docs/routing-specs

Routing specs are marked by :type => :routing or if you have set config.infer_spec_type_from_file_location! by placing them in spec/routing. Simple apps with nothing but standard RESTful routes won't get much value from routing specs, but they can provide significant value when used to specify customized routes, like vanity links, slugs, etc.

expect(:get => "/articles/2012/11/when-to-use-routing-specs").to route_to(
  :controller => "articles",
  :month => "2012-11",
  :slug => "when-to-use-routing-specs"
)

So you can just do your usual post :index, params: {}, format: :json and check if your routing works, e.g. when you have some customizations like get "/controller_name/ENV.fetch('TOKEN')", to: 'controller_name#my_action' as describe in above link.

Or you do request-specs, they support post 'https://lvh.me/my/fancy/url', params: {}.to_json

Note the difference in how to define that you expect json formatted params.

Upvotes: 0

Ashish Jambhulkar
Ashish Jambhulkar

Reputation: 1504

Please take a look at this https://relishapp.com/rspec/rspec-rails/v/3-2/docs/controller-specs/engine-routes-for-controllers

DEPRECATION WARNING: Passing the use_route option in functional tests are deprecated. Support for this option in the process method (and the related get, head, post, patch, put and delete helpers) will be removed in the next version without replacement. Functional tests are essentially unit tests for controllers and they should not require knowledge to how the application's routes are configured. Instead, you should explicitly pass the appropiate params to the process method. Previously the engines guide also contained an incorrect example that recommended using this option to test an engine's controllers within the dummy application. That recommendation was incorrect and has since been corrected. Instead, you should override the @routes variable in the test case with Foo::Engine.routes. See the updated engines guide for details.

Upvotes: 3

Related Questions