Rspec-rails: Rails 6 ActionView::Template::Error wrong number of arguments (given 2, expected 1)

Created on 30 Sep 2019  路  9Comments  路  Source: rspec/rspec-rails

Steps to reproduce:

Given I install fresh new Rails 6 project with RSpec and I write controller test as following:

# a/c/companies_controller
class CompaniesController < ApplicationController
  def show
    @company = Company.find(params[:id])
    render :show  # test will blow up at this point
  end
end

# spec/controller/companies_controller_spec.rb
require 'rails_helper'
RSpec.describe CompaniesController, type: :controller do
    it 'should load page' do
      get :show, params: { id: Company.create.id }  # doesn't matter what test is testing, it will fail with ActionView::Template::Error: wrong number of arguments (given 2, expected 1)  at his point
       # .... 
    end
end

What Ruby, Rails and RSpec versions are you using?

Ruby version: 2.6.3
Rails version: 6.0.0
RSpec version:

bundle exec rspec --version

RSpec 3.8
  - rspec-core 3.8.2
  - rspec-expectations 3.8.4
  - rspec-mocks 3.8.1
  - rspec-rails 3.8.2
  - rspec-support 3.8.2


cat Gemfile.lock  | grep rspec

    rspec-core (3.8.2)
      rspec-support (~> 3.8.0)
    rspec-expectations (3.8.4)
      rspec-support (~> 3.8.0)
    rspec-mocks (3.8.1)
      rspec-support (~> 3.8.0)
    rspec-rails (3.8.2)
      rspec-core (~> 3.8.0)
      rspec-expectations (~> 3.8.0)
      rspec-mocks (~> 3.8.0)
      rspec-support (~> 3.8.0)
    rspec-support (3.8.2)
    spring-commands-rspec (1.0.4)
  rspec-rails
  spring-commands-rspe



related links

Most helpful comment

gem 'rspec-rails', '4.0.0.beta3' will work, waiting on a fix for a PR to release final

All 9 comments

so according to http://jessehouse.com/blog/2019/06/19/actionview-template-error-wrong-number-of-arguments-given-2/ if I replace

# Gemfile
gem 'rspec-rails'

with

  # Gemfile
  gem 'rspec-core', git: 'https://github.com/rspec/rspec-core'
  gem 'rspec-expectations', git: 'https://github.com/rspec/rspec-expectations'
  gem 'rspec-mocks', git: 'https://github.com/rspec/rspec-mocks'
  gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails', branch: '4-0-dev'
  gem 'rspec-support', git: 'https://github.com/rspec/rspec-support'

it will work

but the point is that Rails 6 is out some time => would be nice if I can just use gem 'rspec-rails'

:wave: Hi, yes 4-0-dev contains the version of rspec-rails with Rails 6 compatibility. It will be released soon but we are all volunteers. A quick search of issues would have revealed this before opening a new one incidentally.

@JonRowe oh I see, sorry didn't want to push just thought there are some fixes prepared in 3.8.x version not released yet, didn't know they are in 4.0 only. No pressure ;)

When I try to add this to my Gemfile
gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails', branch: '4-0-dev'
I got error:
Revision 4-0-dev does not exist in the repository https://github.com/rspec/rspec-rails. Maybe you misspelled it?

The PR was merged, you can use master or 4.0.0.beta3 until the final version is released.

I got same problem.

This working for me

gem 'rspec-core', git: 'https://github.com/rspec/rspec-core'
gem 'rspec-expectations', git: 'https://github.com/rspec/rspec-expectations'
gem 'rspec-mocks', git: 'https://github.com/rspec/rspec-mocks'
gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails'
gem 'rspec-support', git: 'https://github.com/rspec/rspec-support'

Is there any ETA for when the "final version" is released? Having the same problem on a Rails 6 app.

My solution:

gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails', branch: "4-0-maintenance"

gem 'rspec-rails', '4.0.0.beta3' will work, waiting on a fix for a PR to release final

Was this page helpful?
0 / 5 - 0 ratings