Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSpec controller error wrong number of arguments

I'm starting to learn RSpec from a tutorial.

I'm stuck on tests for the controller.

For some reason, I can’t run the next test in my application:

require "rails_helper"

RSpec.describe PostsController, type: :controller do
  context "GET #index" do
    it "returns a success response" do
      get :index
      expect(response).to be_success
    end
  end
end

I get the error:

     ActionView::Template::Error:
       wrong number of arguments (given 2, expected 1)
     # ./spec/controllers/posts_controller_spec.rb:6:in `block (3 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # ArgumentError:
     #   wrong number of arguments (given 2, expected 1)
     #   ./spec/controllers/posts_controller_spec.rb:6:in `block (3 levels) in <top (required)>'

I don’t understand what could be the problem, because in the tutorial it works.

like image 739
SsPay Avatar asked Nov 25 '25 21:11

SsPay


1 Answers

This is an issue with Rails 6 and rspec-rails 3.x gem, which has been fixed in rspec-rails 4.0 version, upgrade your rspec-rails gem version

gem 'rspec-rails', '~> 4.0.0.beta4'

bundle install and run the specs again.

More info - https://github.com/rails/rails/issues/35417#issuecomment-475723528

like image 94
Rajdeep Singh Avatar answered Nov 28 '25 11:11

Rajdeep Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!