Positional Argument Deprecation Warning on http request with no keyword args

117 views
Skip to first unread message

Jack Royal-Gordon

unread,
Nov 25, 2020, 11:24:54 PM11/25/20
to rs...@googlegroups.com
Migrating from Rails 4.2 to Rails 5, so of course I got errors about positional arguments being replaced by keyword arguments on http requests in integration tests. I corrected all of those so that
get “/route”, param1: value, param2: value, …
will look like
get “/route”, params: {param1: value, … }
and that resolved most of them. 

But now I find I’ve got some where the source looks like
get edit_account_activation_path(@user.activation_token + 'xyzzy’)

I checked and "edit_account_activation_path(@user.activation_token + 'xyzzy’)” resolves to "/account_activations/lasdfhdlkjdslksdafjhkxyzzy/edit”.


Fortunately (or unfortunately, depending on how you feel about controller tests vs feature tests), I don’t have many feature tests so there aren’t too many of these. But I’m absolutely flummoxed about how to resolve this.

Phil Pirozhkov

unread,
Nov 26, 2020, 10:52:15 AM11/26/20
to Jack Royal-Gordon
Jack,

What is wrong with it exactly, what is the error you're getting?

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/66ED4E44-E526-4B1B-9694-17A8B55676A2%40pobox.com.

Jack Royal-Gordon

unread,
Nov 26, 2020, 4:14:33 PM11/26/20
to rs...@googlegroups.com
I’m sorry, I thought the error was clear. The exact message is:

     Failure/Error: get edit_account_activation_path(@user.activation_token)

     

     ActionController::UrlGenerationError:
       No route matches {:action=>"/account_activations/11291f1553b269c585e0a1b7e87fbe10/edit", :controller=>"account_activations"}
     # ./spec/controllers/account_activations_controller_spec.rb:11:in `block (3 levels) in <top (required)>'

Now here is the route (from “rake routes”):

          edit_account_activation GET    /account_activations/:id/edit(.:format)          account_activations#edit

and the controller is expecting the activation token as “id”.

Phil Pirozhkov

unread,
Nov 30, 2020, 11:46:00 AM11/30/20
to Jack Royal-Gordon
     Failure/Error: get edit_account_activation_path(@user.activation_token)

     

     ActionController::UrlGenerationError:
       No route matches {:action=>"/account_activations/11291f1553b269c585e0a1b7e87fbe10/edit", :controller=>"account_activations"}
     # ./spec/controllers/account_activations_controller_spec.rb:11:in `block (3 levels) in <top (required)>'

Jack Royal-Gordon

unread,
Nov 30, 2020, 12:43:22 PM11/30/20
to rs...@googlegroups.com
And that’s what I was doing with my tests in Rails 4. But there is an article about Rails 5 with the below captured excerpt that says that in Rails 5 controller tests should use URL helpers instead of actions, and that that was because controller tests now use ActionDispatch::IntegrationTest instead of ActionController::TestCase. The full article can be found at https://blog.bigbinary.com/2016/04/19/changes-to-test-controllers-in-rails-5.html.




--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.

pirj...@gmail.com

unread,
Nov 30, 2020, 1:53:04 PM11/30/20
to rspec
That doesn't seem to be entirely correct.

Rails 5 does https://github.com/rails/rails/blob/5-0-stable/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb#L4 generate a test that uses `ActionDispatch::IntegrationTest`, but it depends on what your test inherits from.
Do you inherit yours from `ActionDispatch::IntegrationTest` or `ActionController::TestCase`?

Jack Royal-Gordon

unread,
Nov 30, 2020, 3:48:49 PM11/30/20
to rs...@googlegroups.com
Good question. I’m using the “describe” syntax along with config.infer_spec_type_from_file_location!, so the RSpec DSL determines the class. From the backtrace, I can see that it’s coming from ActionDispatch::IntegrationTest.

I moved forward to RSpec 3.9 (from 3.1), and this problem has changed. Now, instead of complaining about positional arguments, I’m getting

undefined method `edit_account_activation' for #<RSpec::ExampleGroups::AccountActivationsController::GETEdit:0x00007fb0345841c0>

In other words, it’s not allowing URL helpers at all. So this resolves things for me (as far as controllers are concerned) — I’ll use the  get ‘action’, params: {…} syntax.

However, I’m seeing the same error in request specs now. That is, “get edit_account_activation(value)” gives the error

DEPRECATION WARNING: Using positional arguments in integration tests has been deprecated,  favor of keyword arguments, and will be removed in Rails 5.1.

I discovered that If I add an empty params hash to the request then the error goes away, (e.g. "get edit_account_activation_path(@user.activation_token), params: {}”).


This feels like I’ve found a work-around for an issue that should not exist. So I have a feeling that this will come back to bite me at some point in the future.


--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.

Phil Pirozhkov

unread,
Dec 1, 2020, 10:38:02 AM12/1/20
to Jack Royal-Gordon
Jack,

> So I have a feeling that this will come back to bite me at some point in the future.

Let's see. I wouldn't trust Rails 5.0 deprecations that much, if I recall it correctly, things kept changing back and forth until stabilized in 5.2.

Jack Royal-Gordon

unread,
Dec 1, 2020, 2:13:07 PM12/1/20
to rs...@googlegroups.com
Good to know. Thanks for the heads-up! I probably should be paying more attention t the discussions around new versions.

Reply all
Reply to author
Forward
0 new messages