dimanche 8 mars 2020

Test failing in get :index with wrong number of arguments (given 2, expected 1) using Rspec

I have a very simple RSpec controller test that looks like this:

require 'rails_helper'

RSpec.describe IndexController, type: :controller do
  describe 'GET #index' do
    it 'returns http success' do
      get :index
      expect(response).to have_http_status(:success)
    end
  end
end

and it fails with the error:

  1) IndexController GET #index returns http success
     Failure/Error: get :index

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

Line 6 is get :index. Why is it claiming 2 arguments? only 1 is given.

The controller looks like this:

class IndexController < ApplicationController
end

and there's a view in app/views/index/index.html.erb that looks like this:

Nothing to see here.

It works correctly with this route: root to: 'index#index'.

Any ideas what's wrong here?

Aucun commentaire:

Enregistrer un commentaire