0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Railsチュートリアル 第7章 リスト7.23のテストでArgumentError: wrong number of arguments (given 2, expected 1)

Last updated at Posted at 2021-06-23

はじめに

Railsチュートリアル7章のリスト7.23のテストで
ArgumentError: wrong number of arguments (given 2, expected 1)
とエラーが出たので、解決した方法をまとめておきます。

自分の環境

  • ryby: 3.0.1
  • rails: 6.1.3.2

エラーが出た原因

ruby3.0以上を使っていると、キーワード引数の書き方が変わったため、書き方の問題でひっかかったぽいです。

エラーがでたコードとエラーメッセージ

require 'test_helper'

class UsersSignupTest < ActionDispatch::IntegrationTest

  test "invalid signup information" do
    get signup_path
    assert_no_difference 'User.count' do
      post users_path, params: { user: { name:  "",
                                         email: "user@invalid",
                                         password:              "foo",
                                         password_confirmation: "bar" } }
    end
    assert_template 'users/new'
  end
end
$ rails test
Running via Spring preloader in process 4852
Started with run options --seed 46915

ERROR["test_invalid_signup_information", #<Minitest::Reporters::Suite:0x00007f81d2250d18 @name="UsersSignupTest">, 2.133824999909848]
 test_invalid_signup_information#UsersSignupTest (2.13s)
Minitest::UnexpectedError:         ArgumentError: wrong number of arguments (given 2, expected 1)
            test/integration/users_signup_test.rb:8:in `block (2 levels) in <class:UsersSignupTest>'
            test/integration/users_signup_test.rb:7:in `block in <class:UsersSignupTest>'

  19/19: [=========================================] 100% Time: 00:00:02, Time: 00:00:02

Finished in 2.36285s
19 tests, 37 assertions, 0 failures, 1 errors, 0 skips

解決法

自分の場合はrubyのバージョンを2.7.3に変更しました。
どこかの記事で、8行目のpost users_path,,を削除すればテストが通ったみたいなのですが、その方法では10章で詰むみたいです。
いったんはバージョン下げて対応しました。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?