Ruby on Rails を Rails tutorialで学習中の駆け出しプログラマーです。
10章 10.25において、
以下のテストがエラーになって困っています。
現象の説明と、解決策を教えていただけないでしょうか?
現在の状況としては
Failed assertion, no message given.
test/integration/password_resets_test.rb:56:in `block in <class:PasswordReset
とエラーが表示されており、56行めの
assert is_logged_in?
が原因なのではないかと考えましたが、他のテストではパスしており、問題がないと考えております。
その一つ上の行の
# 有効なパスワードと確認 patch password_reset_path(user.reset_token), email: user.email, user: { password: "foobaz", password_confirmation: "foobaz" }
のvaridationエラーなのでは、と確認しましたが、6文字を最低文字数と制約をかけているだけで問題はないと考えられます。
こういった状況の時の解決のためのとる手順等も教えていただけると幸いです。
__________________以下詳細_____________________
リスト10.54: パスワード再設定の統合テスト
test/integration/password_resets_test.rb
require 'test_helper' class PasswordResetsTest < ActionDispatch::IntegrationTest def setup ActionMailer::Base.deliveries.clear @user = users(:michael) end test "password resets" do get new_password_reset_path assert_template 'password_resets/new' # メールアドレスが無効 post password_resets_path, password_reset: { email: "" } assert_not flash.empty? assert_template 'password_resets/new' # メールアドレスが有効 post password_resets_path, password_reset: { email: @user.email } assert_not_equal @user.reset_digest, @user.reload.reset_digest assert_equal 1, ActionMailer::Base.deliveries.size assert_not flash.empty? assert_redirected_to root_url # パスワード再設定用フォーム user = assigns(:user) # メールアドレスが無効 get edit_password_reset_path(user.reset_token, email: "") assert_redirected_to root_url # 無効なユーザー user.toggle!(:activated) get edit_password_reset_path(user.reset_token, email: user.email) assert_redirected_to root_url user.toggle!(:activated) # メールアドレスが正しく、トークンが無効 get edit_password_reset_path('wrong token', email: user.email) assert_redirected_to root_url # メールアドレスもトークンも有効 get edit_password_reset_path(user.reset_token, email: user.email) assert_template 'password_resets/edit' assert_select "input[name=email][type=hidden][value=?]", user.email # 無効なパスワードと確認 patch password_reset_path(user.reset_token), email: user.email, user: { password: "foobaz", password_confirmation: "barquux" } assert_select 'div#error_explanation' # パスワードが空 patch password_reset_path(user.reset_token), email: user.email, user: { password: "", password_confirmation: "" } assert_select 'div#error_explanation' # 有効なパスワードと確認 patch password_reset_path(user.reset_token), email: user.email, user: { password: "foobaz", password_confirmation: "foobaz" } assert is_logged_in? assert_not flash.empty? assert_redirected_to user end end
以下がエラーメッセージ
FAIL["test_password_resets", PasswordResetsTest, 2016-03-15 23:44:48 +0000]
test_password_resets#PasswordResetsTest (1458085488.12s)
Failed assertion, no message given.
test/integration/password_resets_test.rb:56:in `block in class:PasswordResetsTest'
1/1: [============================================================================================] 100% Time: 00:00:02, Time: 00:00:02
Finished in 2.60142s
1 tests, 15 assertions, 1 failures, 0 errors, 0 skips
あなたの回答
tips
プレビュー