[RUBY] What to do if you get an Argument Error: wrong number of arguments (given 2, expected 0) in your RSpec test

Introduction

When you run RSpec tests

   Failure/Error:
       post login_path, params: { session: { email: user.email,
                                             password: user.password } }

     ArgumentError:
       wrong number of arguments (given 2, expected 0)

It took a long time to resolve the error, so I will write it.

error contents

This error is said to be 0 for the "method-side formal argument" (expect 0) for the "caller's argument" (given 2) and 2. It means that the values are out of alignment for some reason.

Cause of occurrence

In RSpec code

let!(:post) { create(:post, user: user) }

Because the post of post login_path, params: {session: {}} calls let! (: post) in the RSpec code instead of the post such as get, post, delete.

Solutions

Just change the name of the code you had earlier.

let!(:new_post) { create(:post, user: user) }

reference

https://qiita.com/yo0917/items/20c165a3b06805bf2e37

Finally

It may be a very rudimentary mistake, but I was really annoyed when I wrote RSpec, so I will continue to do my best to resolve it. I also want to improve my writing skills.

Recommended Posts

What to do if you get an Argument Error: wrong number of arguments (given 2, expected 0) in your RSpec test
What to do if you get a wrong number of arguments error in binding.pry
[RSpec] ArgumentError: wrong number of arguments If you get an error, you may have to worry about variable naming.
What to do if you get a "302" error in your controller unit test code in Rails
What to do if you get an error in Basic authentication during Rails test code
What to do if you get an error with bundle install by entering gem'bcrypt' in your Gemfile
What to do if you can't get the text of an element in Selenium
What to do if you get a gcc error in Docker
What to do if you get a DISPLAY error in gym.render ()
What to do if you get an error during rails db: reset
What to do if you get an uninitialized constant Likes Controller error
What to do if you get an error when you hit Heroku logs
What to do if you get an [An HTTP request took too long to complete.] Error in Docker.
What to do if you get an error on heroku rake db: migrate
ArgumentError (wrong number of arguments (given 0, expected 1)) error message
What to do if you get the error Couldn't find Item without an ID
What to do if you get a java.io.IOException in GlassFish
wrong number of arguments (given 1, expected 0)
What to do if you don't see the test code error message in the terminal console
[Rails] What to do if you can't get an error message with the errors method
[Rails] How to resolve wrong number of arguments (given 2, expected 0..1) of user_id
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do if you get a groovy warning in Thymeleaf Layout
What to do if you get a SQLite3 :: BusyException: database is locked error
What to do if you get the error message unrecognized selector send to instance "***"
What to do if you get an "A server is already running." Error when you try to start the rails server
What to do if an ActionController :: UnknownFormat error occurs
What to do if Failure / Error: require File.expand_path ('../ config / environment', __dir__) appears in RSpec
What to do if you get a port error when docker-compose up on Mac
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
[Rails] What to do if you accidentally install bundle in the production environment in your local environment
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
What to do if you get further occurrences of http header parsing errors will be logged at debug level. In tomcat 8.5.37
What to do if you get ActiveRecord :: StatementInvalid: Mysql2 :: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near when you try to reset Heroku
[Rails] Sign-up function using devise error number of arguments (given 0, expected 1)
What to do if you get angry with OpenSSL with pyenv install
What to do if you forget the root password in CentOS7
[Rails] What to do if you can't get parameters with form_with
What to do if an error occurs when doing npm install axios in React + Typescript project
What to do if an error occurs in VS Code when importing a django module or your own module installed by pip install
What to do if you should have installed Rails but an error occurs with rails -v (for beginners)
What to do if you get the error Too long with no output (exceeded 10m0s) on CircleCI
Add gem'rails-i18n','~> 6.0.0' and what to do if bundle install gives an error
What to do and how to install when an error occurs in DXRuby 1.4.7
What to do if an error occurs when nokogiri enters when bundle install
no space left on device What to do if an error occurs
What to do if you get a MiniMagick vulnerability alert on GitHub
What to do if you install Ubuntu
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
What to do if you get Could not save master table to file after importing a project in Eclipse
How to translate the error message into Japanese (What to do if you cannot log in for some reason)
[Swift] How to get the number of elements in an array (super basic)
If you want to satisfy the test coverage of private methods in JUnit
What to do if you get Could not locate Gemfile or .bundle / directory
wildflly10 java8 ERROR [org.jboss.jca.core.tx.jbossts.XAResourceRecoveryImpl] (Periodic Recovery) IJ000906 What to do if an error occurs
What to do if you get angry if you don't have nokogiri while installing wp2txt
What to do if you get To install the missing version, run `gem install bundler: 2.1.4`
What to do if ffi installation fails when launching an application in Rails
What you need to know before writing a test in an iOS app