質問するログイン新規登録

Q&A

0回答

320閲覧

【Rails】gem 'better_errors'を削除前後でテスト結果が異なる

退会済みユーザー

退会済みユーザー

総合スコア0

Ruby on Rails

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

0グッド

0クリップ

投稿2017/06/27 08:54

編集2017/06/27 09:00

0

0

症状

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.29%

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

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

質問する

関連した質問