I have a brand new rails 6 application, and I installed rspec.
I created a controller, and when I run rspec I get this error:
PagesController GET #index returns http success Failure/Error: get :index ActionView::Template::Error: wrong number of arguments (given 2, expected 1) # ./spec/controllers/pages_controller_spec.rb:7:in `block (3 levels) in <top (required)>' # ------------------ # --- Caused by: --- # ArgumentError: # wrong number of arguments (given 2, expected 1) # ./spec/controllers/pages_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
The generated rspec test looks like:
require 'rails_helper'
RSpec.describe CartController, type: :controller do
describe "GET #index" do
it "returns http success" do
get :index
expect(response).to have_http_status(:success)
end
end
end
Is there a bug in the generated code or is some other environmental issue the cause of this?
I don't see where there are 2 arguments anywhere?
Per the following GitHub issue for Rails 6, upgrade to rspec-rails 4.0:
gem 'rspec-rails', '~> 4.0.0.beta3'
This is also referenced in this GitHub issue for rspec-rails.
This question generates pretty regular traffic and rspec-rails is now well past the 4.0.0beta3 version. (v5.0.1 as of today) Always check for the latest version at https://rubygems.org/gems/rspec-rails and use that instead:
gem 'rspec-rails', '~> 5.0.1'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With