Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I just started a new project in Rails 5, (my first, though I have several projects in Rails 4.x.) and am having trouble with controller specs.

describe RequestsController, :type => :controller do

  it "receives new request" do
    post :accept_request, my_params
  end

end

Returns the error:

 Failure/Error: post :accept_request, my_params

 ArgumentError:
   wrong number of arguments (given 2, expected 1)

I understand there has been a shift in the preferred testing strategy for controllers with Rails 5 as noted on Everyday Rails, specifically, shifting controller tests into request specs, but no word on changes to this basic method of controller testing.

like image 560
Nick Avatar asked May 24 '17 22:05

Nick


1 Answers

It appears that Rails 5 expects keyword arguments instead of hash arguments, which is a change from previous versions. Also, the first argument is a URL rather than an action. Try

post some_url, params: some_hash
like image 145
zetetic Avatar answered Nov 29 '22 08:11

zetetic