症状
Rails 5.0.2です。タイトル通りなのですが、
gem 'better_errors'を利用時、テストを行うと、
66/66: [===================================================================================================================================] 100% Time: 00:00:09, Time: 00:00:09 Finished in 10.01715s 66 tests, 237 assertions, 0 failures, 0 errors, 0 skips
しっかりテストが通るのですが、一方でGemfileから
Gemfile
1 2 gem 'better_errors' 3
を削除し、
$ bundle install
をします。その後、
$ rails test
を行うと
ERROR["test_フォロー", FollowingTest, 9.163654325999914] test_フォロー#FollowingTest (9.16s) NoMethodError: NoMethodError: undefined method `user_host_host_url' for #<User::RelationshipsController:0x007f8a7e6612b8> Did you mean? user_host_url user_hosts_url app/controllers/user/relationships_controller.rb:9:in `block (2 levels) in create' app/controllers/user/relationships_controller.rb:8:in `create' test/integration/following_test.rb:24:in `block (2 levels) in <class:FollowingTest>' test/integration/following_test.rb:23:in `block in <class:FollowingTest>' ERROR["test_フォロー解除", FollowingTest, 9.32458399099994] test_フォロー解除#FollowingTest (9.32s) NoMethodError: NoMethodError: undefined method `user_host_host_url' for #<User::RelationshipsController:0x007f8a7e2646b0> Did you mean? user_host_url user_hosts_url app/controllers/user/relationships_controller.rb:19:in `block (2 levels) in destroy' app/controllers/user/relationships_controller.rb:18:in `destroy' test/integration/following_test.rb:38:in `block (2 levels) in <class:FollowingTest>' test/integration/following_test.rb:37:in `block in <class:FollowingTest>' ERROR["test_フォロー(Ajax)", FollowingTest, 9.491528167999945] test_フォロー(Ajax)#FollowingTest (9.49s) ActionView::Template::Error: ActionView::Template::Error: undefined method `followers' for nil:NilClass app/views/user/relationships/create.js.erb:3:in `_app_views_user_relationships_create_js_erb___2393907348688590802_70116398321340' test/integration/following_test.rb:30:in `block (2 levels) in <class:FollowingTest>' test/integration/following_test.rb:29:in `block in <class:FollowingTest>' 66/66: [===================================================================================================================================] 100% Time: 00:00:09, Time: 00:00:09 Finished in 9.80524s 66 tests, 234 assertions, 0 failures, 3 errors, 0 skips
このようにエラーが出ます。
今後ゆっくりテストがパスするよう頑張るつもりですが、
どうして、better_errors削除前後でテスト結果が変わるのかがさっぱりです。
個別エラーの意味というより、better_errors削除前後でのテスト仕様(?) について
もし情報をお持ちの方、ご助言頂けるとと幸いです。宜しくお願いします。
テストのファイル内容
念のため、記載します。
require 'test_helper' class FollowingTest < ActionDispatch::IntegrationTest def setup @user = users(:michael) @host = hosts(:google) log_in_as(@user) end test "フォローリストページ" do get following_user_mypage_path assert_not @user.following.empty? assert_match @user.following.count.to_s,response.body @user.following.each do |host| assert_select "a[href=?]",user_host_path(host) end end test "フォロー" do assert_difference '@user.following.count',1 do post user_relationships_path, params: { followed_id: @host.id } end end test "フォロー(Ajax)" do assert_difference '@user.following.count',1 do post user_relationships_path, params: { followed_id: @host.id }, xhr: true end end test "フォロー解除" do @user.follow(@host) relationship = @user.active_relationships.find_by(followed_id: @host.id) assert_difference '@user.following.count', -1 do delete user_relationship_path(relationship) end end test "フォロー解除(Ajax)" do @user.follow(@host) relationship = @user.active_relationships.find_by(followed_id: @host.id) assert_difference '@user.following.count', -1 do delete user_relationship_path(relationship),xhr:true end end end
あなたの回答
tips
プレビュー