###前提・実現したいこと
ActionMailerの配信するメッセージ数を確認するテストがエラーになっている原因を修正したい。
###発生している問題・エラーメッセージ
Railsチュートリアルの以下の項の演習の直前までやったところのテストがGREENになりません。
https://railstutorial.jp/chapters/account_activation?version=5.0#sec-activation_test_and_refactoring
Failure: UsersSignupTest#test_valid_signup_information_with_account_activation [/home/ubuntu/workspace/sample_app/test/integration/users_signup_test.rb:30]: Expected: 1 Actual: 2
###該当のソースコード
Ruby
1UsersSignupTest 2 3test "valid signup information with account activation" do 4 get signup_path 5 assert_difference 'User.count', 1 do 6 post users_path, params: { user: { name: "Example User", 7 email: "user@example.com", 8 password: "password", 9 password_confirmation: "password" } } 10 end 11 assert_equal 1, ActionMailer::Base.deliveries.size 12 user = assigns(:user) 13 assert_not user.activated? 14 # 有効化していない状態でログインしてみる 15 log_in_as(user) 16 assert_not is_logged_in? 17 # 有効化トークンが不正な場合 18 get edit_account_activation_path("invalid token", email: user.email) 19 assert_not is_logged_in? 20 # トークンは正しいがメールアドレスが無効な場合 21 get edit_account_activation_path(user.activation_token, email: 'wrong') 22 assert_not is_logged_in? 23 # 有効化トークンが正しい場合 24 get edit_account_activation_path(user.activation_token, email: user.email) 25 assert user.reload.activated? 26 follow_redirect! 27 assert_template 'users/show' 28 assert is_logged_in? 29 end
###試したこと
エラーの原因が本来は「1件」のはずのメールが「2件」来ていることまではわかりましたが、何故2件来ているのかがわかりません。
チュートリアルの前半に戻ってやり直しも試みたのですが、解決に至りませんでした。
質問のために載せるソースコードもどこを載せればいいかわからない状態です。見るべきところのヒントでも構いませんので、よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。