Rspec 3.6, Rails 5 error: Wrong number of arguments (given 2, expected 1) for request `post`

I just started a new project in Rails 5 (my first, although I have several projects in Rails 4.x.), and I have problems with the controller settings.

describe RequestsController, :type => :controller do it "receives new request" do post :accept_request, my_params end end 

It returns an error:

  Failure/Error: post :accept_request, my_params ArgumentError: wrong number of arguments (given 2, expected 1) 

I understand that there has been a shift in the preferred controller testing strategy with Rails 5, as indicated in Everyday Rails , in particular, switching controller tests in the request specification, but not a word about the changes in this basic controller testing method.

+5
source share
1 answer

Rails 5 seems to be expecting keyword arguments instead of hash arguments, which is a change from previous versions. In addition, the first argument is a URL, not an action. Try

 post some_url, params: some_hash 
+17
source

Source: https://habr.com/ru/post/1268197/


All Articles