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が発生します。
あなたの回答
tips
プレビュー