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

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

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

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

Q&A

0回答

1187閲覧

Railsテストにて Expected: 1Actual: 0,Expected: 2Actual: 0というFailureが解決できない

kinu221

総合スコア26

Ruby on Rails 5

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

0グッド

0クリップ

投稿2018/03/21 08:40

cloud9にてrails testを実行するとFollowingTest#test_should_send_follow_notification_email [/home/ubuntu/workspace/environment/sample_app/test/integration/following_test.rb:65]:Expected: 1Actual: 0
FollowingTest#test_should_send_unfollow_notification_email [/home/ubuntu/workspace/environment/sample_app/test/integration/following_test.rb:78]:Expected: 2Actual: 0というFailureが発生しているのですが、下名のスキル不足のため解決できません。お手数ですが、アドバイスをよろしくお願いします。

[ソースコード]

ruby

1---following_test.rb--- 2 3require 'test_helper' 4 5class FollowingTest < ActionDispatch::IntegrationTest 6 7 def setup 8 @user=users(:michael) 9 @other = users(:archer) 10 log_in_as(@user) 11 end 12 13 test "following page" do 14 get following_user_path(@user) 15 assert_not @user.following.empty? 16 assert_match @user.following.count.to_s,response.body 17 @user.following.each do |user| 18 assert_select "a[href=?]",user_path(user) 19 end 20 end 21 22 test "followers page" do 23 get followers_user_path(@user) 24 assert_not @user.followers.empty? 25 assert_match @user.followers.count.to_s,response.body 26 @user.followers.each do |user| 27 assert_select "a[href=?]",user_path(user) 28 end 29 end 30 31 test "should follow a user the standard way" do 32 assert_difference '@user.following.count', 1 do 33 post relationships_path, params: { followed_id: @other.id } 34 end 35 end 36 37 test "should follow a user with Ajax" do 38 assert_difference '@user.following.count', 1 do 39 post relationships_path, xhr: true, params: { followed_id: @other.id } 40 end 41 end 42 43 test "should unfollow a user the standard way" do 44 @user.follow(@other) 45 relationship = @user.active_relationships.find_by(followed_id: @other.id) 46 assert_difference '@user.following.count', -1 do 47 delete relationship_path(relationship) 48 end 49 end 50 51 test "should unfollow a user with Ajax" do 52 @user.follow(@other) 53 relationship = @user.active_relationships.find_by(followed_id: @other.id) 54 assert_difference '@user.following.count', -1 do 55 delete relationship_path(relationship), xhr: true 56 end 57 end 58 59 test "feed on Home page" do 60 get root_path 61 @user.feed.paginate(page: 1).each do |micropost| 62 assert_match CGI.escapeHTML(micropost.content), response.body 63 end 64 end 65 test "should send follow notification email" do 66 post relationships_path, params: {followed_id: @other.id} 67 assert_equal 1, ActionMailer::Base.deliveries.size 68 end 69 70 test "should not send follow notification email" do 71 not_notify = users(:hogehoge) 72 post relationships_path, params: {followed_id: not_notify.id} 73 assert_equal 0, ActionMailer::Base.deliveries.size 74 end 75 76 test "should send unfollow notification email" do 77 @user.follow(@other) 78 relationship = @user.active_relationships.find_by(followed_id: @other.id) 79 delete relationship_path(relationship) 80 assert_equal 2, ActionMailer::Base.deliveries.size # follow email and unfollow email 81 end 82 83 test "should not send unfollow notification email" do 84 not_notify = users(:hogehoge) 85 @user.follow(not_notify) 86 relationship = @user.active_relationships.find_by(followed_id: not_notify.id) 87 delete relationship_path(relationship) 88 assert_equal 0, ActionMailer::Base.deliveries.size 89 end 90end 91 92

[試したこと]
assert_equal 1, ActionMailer::Base.deliveries.size,
assert_equal 2, ActionMailer::Base.deliveries.sizeの所でエラーが起
きているので、ネット上にあるQ&Aを見るとフォローユーザーを設定できていないため発生するとういうことでしたので、followユーザーの登録や設定の見直しを行いましたが、Failureが発生します。

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問