今回検証した環境
- 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-rails
のv4.0.0
がリリースされました!
group :development do
gem 'rspec-rails', '~> 4.0.0'
end