我目前正在從作者邁克爾哈特爾遵循Ruby on Rails教程。和我被困在其中測試應該是綠色的,但目前紅章10.1.4,這是錯誤消息:10.1.4邁克爾哈特爾的鐵軌上的紅寶石教程測試紅
Started with run options --seed 48963
FAIL["test_valid_signup_information_with_account_activation", UsersSignupTest, 1.7533403700217605]
test_valid_signup_information_with_account_activation#UsersSignupTest (1.75s)
Failed assertion, no message given.
test/integration/users_signup_test.rb:44:in `block in <class:UsersSignupTest>'
41/41: [=========================================================================================================] 100% Time: 00:00:01, Time: 00:00:01
Finished in 1.78481s
41 tests, 173 assertions, 1 failures, 0 errors, 0 skips
這是一個包含主要的錯誤(FAIL)的文件,根據該報告它應該是 '斷言user.reload.activated?':
require 'test_helper'
class UsersSignupTest < ActionDispatch::IntegrationTest
def setup
ActionMailer::Base.deliveries.clear
end
test "invalid signup information" do
get signup_path
assert_no_difference 'User.count' do
post users_path, user: { name: "",
email: "[email protected]",
password: "foo",
password_confirmation: "bar" }
end
assert_template 'users/new'
assert_select 'div#error_explanation'
assert_select 'div.alert.alert-danger'
end
test "valid signup information with account activation" do
get signup_path
assert_difference 'User.count', 1 do
post users_path, user: { name: "Example User",
email: "[email protected]",
password: "password",
password_confirmation: "password" }
end
assert_equal 1, ActionMailer::Base.deliveries.size
user = assigns(:user)
assert_not user.activated?
# Try to log in before activation.
log_in_as(user)
assert_not is_logged_in?
# Invalid activation token
get edit_account_activation_path("invalid token")
assert_not is_logged_in?
get edit_account_activation_path(user.activation_token, email: 'wrong')
assert_not is_logged_in?
get edit_account_activation_path(user.activation_token, email: user.email)
assert user.reload.activated?
follow_redirect!
assert_template 'users/show'
assert is_logged_in?
end
end
-
您還可以檢查Git Repository
我的倉庫如果有人能夠幫助我解決這個問題,我將非常感激,它會爲我節省寶貴的時間。
感謝您的評論,但我不認爲這是問題在這裏。我跟着邁克爾哈特爾的書以及激活方法部分出現在下一頁,但現在測試應該是綠色的。無論如何,我嘗試添加激活方法,但它仍然會進行RED測試。在我的sessions_controller.rb中,我有一個名爲message的變量,我認爲它與此有關,但我似乎無法弄清楚它是什麼。無論如何,感謝您的幫助。 – luissimo
@luissimo我想我已經找到你的問題。絕對是一個容易犯的錯誤:) –
剛纔看到你的評論一段時間後,我已經解決了這個問題,但是你是對的,那是問題。無論如何,這是一個很好的答案。乾杯。 – luissimo