LoginSignup
10
4

More than 3 years have passed since last update.

【Rails6 + RSpec】controllerテストでActionView::Template::Errorが発生する場合

Last updated at Posted at 2019-08-24

今回検証した環境

  • Rails 6.0.0
  • rspec-rails 3.8.2

現象

例として、users_controller#newアクションをテストするとします。

app/controllers/users_controller.rb
class UsersController < ApplicationController
  def new
  end
end
Gemfile
group :development do
  gem 'rspec-rails'
end
spec/controllers/users_controller_spec.rb
require 'rails_helper'

RSpec.describe UsersController, type: :controller do

  describe "GET #new" do
    it "returns http success" do
      get :new
      expect(response).to have_http_status(:success)
    end
  end

end

この状態でテストを実施すると以下のようなエラーが出ます。

$ bundle exec rspec
1) UsersController GET #new returns http success
   Failure/Error: get :new

   ActionView::Template::Error:
     wrong number of arguments (given 2, expected 1)

原因

RSpecのバグみたいです。
詳しくはこちらを参照

対策

とりあえずv4.0.0のベータ版をインストールすることで解決します。
正式リリースを待ちましょう。

(2020/03/25 追記)
rspec-railsv4.0.0がリリースされました!

group :development do
  gem 'rspec-rails', '~> 4.0.0'
end

参考

Controller spec failed with 6.0.0.beta2

10
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
4