質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

460閲覧

git push前はエラーが出ていなかったのにpush後のrails testがエラーになってしまいます。

Royalchamp

総合スコア0

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2021/08/15 13:22

rails testのエラーについて

プログラミング初心者です。ある教材の中の物をやっているのですが、どのように対処すればよいかわかりません。エラーは複重していると記載されているのですが、一体どの部分でエラーが起きているのかがわからないので、ご教授いただけると幸いです。よろしくお願いします。git push 前はテストエラーが起きていないのに、なぜpushした後にエラーが起きるのでしょうか?

発生している問題・エラーメッセージ

Traceback (most recent call last): 49: from bin/rails:4:in `<main>' 48: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' 47: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' 46: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' 45: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' 44: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' 43: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/commands.rb:18:in `<main>' 42: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/command.rb:48:in `invoke' 41: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/command/base.rb:69:in `perform' 40: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch' 39: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command' 38: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run' 37: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/commands/test/test_command.rb:33:in `perform' 36: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/test_unit/runner.rb:39:in `run' 35: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/test_unit/runner.rb:50:in `load_tests' 34: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/test_unit/runner.rb:50:in `each' 33: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/test_unit/runner.rb:50:in `block in load_tests' 32: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' 31: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' 30: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' 29: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' 28: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' 27: from C:/Users/FMV/environment/sample_app2/test/channels/application_cable/connection_test.rb:1:in `<main>' 26: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' 25: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' 24: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' 23: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' 22: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' 21: from C:/Users/FMV/environment/sample_app2/test/test_helper.rb:3:in `<main>' 20: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require' 19: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' 18: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' 17: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' 16: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' 15: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' 14: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/test_help.rb:17:in `<main>' 13: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:653:in `maintain_test_schema!' 12: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:658:in `method_missing' 11: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:906:in `suppress_messages' 10: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:653:in `block in maintain_test_schema!' 9: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:648:in `load_schema_if_pending!' 8: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:625:in `check_pending!' 7: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:625:in `raise' 6: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:625:in `exception' 5: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:147:in `initialize' 4: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:156:in `detailed_migration_message' 3: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:1104:in `open' 2: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:1104:in `new' 1: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:1226:in `initialize' C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activerecord-6.1.4/lib/active_record/migration.rb:1353:in `validate': (ActiveRecord::DuplicateMigrationNameError) Multiple migrations have the name CreateUsers

該当のソースコード

ruby

1require "test_helper" 2 3class UserTest < ActiveSupport::TestCase 4 5 def setup 6 @user = User.new(name: "Example User", email: "user@example.com", 7 password: "foobar", password_confirmation: "foobar") 8 end 9 10 test "should be valid" do 11 assert @user.valid? 12 end 13 14 test "name should be present" do 15 @user.name = " " 16 assert_not @user.valid? 17 end 18 19 test "email should be present" do 20 @user.email = " " 21 assert_not @user.valid? 22 end 23 24 test "name should not be too long" do 25 @user.name = "a" * 51 26 assert_not @user.valid? 27 end 28 29 test "email should not be too long" do 30 @user.email = "a" * 244 + "@example.com" 31 assert_not @user.valid? 32 end 33 34 test "email validation should accept valid addresses" do 35 valid_addresses = %w[user@example.com USER@foo.COM A_US-ER@foo.bar.org 36 first.last@foo.jp alice+bob@baz.cn] 37 valid_addresses.each do |valid_address| 38 @user.email = valid_address 39 assert @user.valid?, "#{valid_address.inspect} should be valid" 40 end 41 end 42 43 test "email addresses should be unique" do 44 duplicate_user = @user.dup 45 @user.save 46 assert_not duplicate_user.valid? 47 end 48 49 test "password should be present (nonblank)" do 50 @user.password = @user.password_confirmation = " " * 6 51 assert_not @user.valid? 52 end 53 54 test "password should have a minimum length" do 55 @user.password = @user.password_confirmation = "a" * 5 56 assert_not @user.valid? 57 end 58end 59

試したこと

重複している部分は修正して、教材の部分との間違いはないはずです。

補足

最初のrail testは成功したのですが、git checkout master → git merge modeling-users → git push 後のrail test でエラーが出ています。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ktl2018

2021/08/15 15:04 編集

補足を読むとgit mergeのときに何かが起きた気がします。この質問はmodeling-usersブランチではtestで成功するものの,masterブランチでは失敗するという質問に見えます。このため、この2つのブランチの違いを知りたいので以下のコマンドの実行結果が見たいです。 git diff modeling-users master
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問