railsのテストを作成しています。
railsチュートリアル5.1版に従い、10.48まで進みましたが、ここでテストを行うと存在すべきuserのURLが無くエラーとなります。
users_index_test.rb
1 test "index including pagination" do 2 log_in_as(@user) 3 get users_path 4 assert_template 'users/index' 5 assert_select 'div.pagination', count: 2 6 User.paginate(page: 1).each do |user| 7 assert_select 'a[href=?]', user_path(user), text: user.name 8 end 9 end
error
1 FAIL["test_index_including_pagination", Minitest::Result, 1.055881918000523] 2 test_index_including_pagination#Minitest::Result (1.06s) 3 Expected at least 1 element matching "a[href="/users/1028376774"]", found 0.. 4 Expected 0 to be >= 1. 5 test/integration/users_index_test.rb:23:in `block (2 levels) in <class:UsersIndexTest>' 6 test/integration/users_index_test.rb:21:in `block in <class:UsersIndexTest>'
本当にURLが存在しないのかと思い、エラー該当箇所前に検索対象URLを出力するコードを入れてみたのですが、存在しているようでした。
test "index including pagination" do log_in_as(@user) get users_path assert_template 'users/index' assert_select 'div.pagination', count: 2 #debugger User.paginate(page: 1).each do |user| puts "NAME:" + user.name + " PATH:" + user_path(user) + " ADMIN?:" + user.admin.to_s end User.paginate(page: 1).each do |user| assert_select 'a[href=?]', user_path(user), text: user.name end end
NAME:Sterling Archer PATH:/users/950961012 ADMIN?:false ] 11% Time: 00:00:00, ETA: 00:00:04 NAME:Lana Kane PATH:/users/409608538 ADMIN?:false NAME:Malory Archer PATH:/users/659682706 ADMIN?:false NAME:User 0 PATH:/users/338193910 ADMIN?:false NAME:User 1 PATH:/users/590306657 ADMIN?:false NAME:User 2 PATH:/users/975572189 ADMIN?:false NAME:User 3 PATH:/users/220281934 ADMIN?:false NAME:User 4 PATH:/users/323332591 ADMIN?:false NAME:User 5 PATH:/users/608344442 ADMIN?:false NAME:User 6 PATH:/users/1028376774 ADMIN?:false NAME:User 7 PATH:/users/172816471 ADMIN?:false NAME:User 8 PATH:/users/452191684 ADMIN?:false NAME:User 9 PATH:/users/771020115 ADMIN?:false NAME:User 10 PATH:/users/956993830 ADMIN?:false NAME:User 11 PATH:/users/235774389 ADMIN?:false NAME:User 12 PATH:/users/386199561 ADMIN?:false NAME:User 13 PATH:/users/537116830 ADMIN?:false NAME:User 14 PATH:/users/1046959423 ADMIN?:false NAME:User 15 PATH:/users/157312430 ADMIN?:false NAME:User 16 PATH:/users/275330066 ADMIN?:false NAME:User 17 PATH:/users/661521543 ADMIN?:false NAME:User 18 PATH:/users/936450328 ADMIN?:false NAME:User 19 PATH:/users/14035331 ADMIN?:false NAME:User 20 PATH:/users/304595689 ADMIN?:false NAME:User 21 PATH:/users/622916212 ADMIN?:false NAME:User 22 PATH:/users/1009361868 ADMIN?:false NAME:User 23 PATH:/users/187601757 ADMIN?:false NAME:User 24 PATH:/users/357172992 ADMIN?:false NAME:User 25 PATH:/users/575485547 ADMIN?:false NAME:User 26 PATH:/users/994338771 ADMIN?:false FAIL["test_index_including_pagination", Minitest::Result, 0.573080492002191] test_index_including_pagination#Minitest::Result (0.57s) Expected at least 1 element matching "a[href="/users/1028376774"]", found 0.. Expected 0 to be >= 1. test/integration/users_index_test.rb:23:in `block (2 levels) in <class:UsersIndexTest>' test/integration/users_index_test.rb:21:in `block in <class:UsersIndexTest>'
URLは間違いなく存在していますが、assert_selectでエラー…もう、訳が分かりません。
どなたか、原因が分かりますでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。