【发布时间】:2015-05-23 06:23:14
【问题描述】:
我正在关注 MICHAEL HARTL 的“Ruby on Rails 教程”一书,在第 8 节中,我实现了几个测试。现在,当您启动 bundle exec rake test 时出现 26 个错误,我不明白什么不好。
ERROR["test_invalid_signup_information", UsersSignupTest, 2015-05-22 11:12:19 +0200]
test_invalid_signup_information#UsersSignupTest (1432285939.41s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_valid_signup_information", UsersSignupTest, 2015-05-22 11:12:19 +0200]
test_valid_signup_information#UsersSignupTest (1432285939.42s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_password_should_have_a_minimum_length", UserTest, 2015-05-22 11:12:19 +0200]
test_password_should_have_a_minimum_length#UserTest (1432285939.43s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_email_addresses_should_be_saved_as_lower-case", UserTest, 2015-05-22 11:12:19 +0200]
test_email_addresses_should_be_saved_as_lower-case#UserTest (1432285939.43s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_email_validation_should_accept_valid_addresses", UserTest, 2015-05-22 11:12:19 +0200]
test_email_validation_should_accept_valid_addresses#UserTest (1432285939.43s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_name_should_not_be_too_long", UserTest, 2015-05-22 11:12:19 +0200]
test_name_should_not_be_too_long#UserTest (1432285939.44s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_password_should_be_present", UserTest, 2015-05-22 11:12:19 +0200]
test_password_should_be_present#UserTest (1432285939.44s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_authenticated?_should_return_false_for_a_user_with_nil_digest", UserTest, 2015-05-22 11:12:19 +0200]
test_authenticated?_should_return_false_for_a_user_with_nil_digest#UserTest (1432285939.45s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_email_addresses_should_be_unique", UserTest, 2015-05-22 11:12:19 +0200]
test_email_addresses_should_be_unique#UserTest (1432285939.45s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_email_should_be_present", UserTest, 2015-05-22 11:12:19 +0200]
test_email_should_be_present#UserTest (1432285939.46s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_email_should_not_be_too_long", UserTest, 2015-05-22 11:12:19 +0200]
test_email_should_not_be_too_long#UserTest (1432285939.46s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_name_should_be_present", UserTest, 2015-05-22 11:12:19 +0200]
test_name_should_be_present#UserTest (1432285939.46s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_should_be_valid", UserTest, 2015-05-22 11:12:19 +0200]
test_should_be_valid#UserTest (1432285939.47s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_login_with_remembering", UsersLoginTest, 2015-05-22 11:12:19 +0200]
test_login_with_remembering#UsersLoginTest (1432285939.47s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_login_without_remembering", UsersLoginTest, 2015-05-22 11:12:19 +0200]
test_login_without_remembering#UsersLoginTest (1432285939.48s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_login_with_valid_information_followed_by_logout", UsersLoginTest, 2015-05-22 11:12:19 +0200]
test_login_with_valid_information_followed_by_logout#UsersLoginTest (1432285939.48s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_should_get_new", UsersControllerTest, 2015-05-22 11:12:19 +0200]
test_should_get_new#UsersControllerTest (1432285939.49s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_current_user_returns_right_user_when_session_is_nil", SessionsHelperTest, 2015-05-22 11:12:19 +0200]
test_current_user_returns_right_user_when_session_is_nil#SessionsHelperTest (1432285939.50s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_current_user_returns_nil_when_remember_digest_is_wrong", SessionsHelperTest, 2015-05-22 11:12:19 +0200]
test_current_user_returns_nil_when_remember_digest_is_wrong#SessionsHelperTest (1432285939.50s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_layout_links", SiteLayoutTest, 2015-05-22 11:12:19 +0200]
test_layout_links#SiteLayoutTest (1432285939.51s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_should_get_new", SessionsControllerTest, 2015-05-22 11:12:19 +0200]
test_should_get_new#SessionsControllerTest (1432285939.52s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_should_get_contact", StaticPagesControllerTest, 2015-05-22 11:12:19 +0200]
test_should_get_contact#StaticPagesControllerTest (1432285939.52s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_should_get_help", StaticPagesControllerTest, 2015-05-22 11:12:19 +0200]
test_should_get_help#StaticPagesControllerTest (1432285939.53s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_should_get_home", StaticPagesControllerTest, 2015-05-22 11:12:19 +0200]
test_should_get_home#StaticPagesControllerTest (1432285939.53s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_should_get_about", StaticPagesControllerTest, 2015-05-22 11:12:19 +0200]
test_should_get_about#StaticPagesControllerTest (1432285939.54s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
ERROR["test_full_title_helper", ApplicationHelperTest, 2015-05-22 11:12:19 +0200]
test_full_title_helper#ApplicationHelperTest (1432285939.54s)
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
这些是测试文件:
Users.yml
michael:
name: Michael Example
email: michael@example.com
password_digest: <%= User.digest('password') %>
用户会话控制器测试
require 'test_helper'
class SessionsControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end
谢谢大家的帮助!
我编辑了 User.yml 文件,现在只有以下错误:
FAIL["test_current_user_returns_right_user_when_session_is_nil", SessionsHelperTest, 2015-05-22 11:12:20 +0200]
test_current_user_returns_right_user_when_session_is_nil#SessionsHelperTest (1432285940.28s)
--- expected
+++ actual
@@ -1 +1 @@
-#<User id: 762146111, name: "Michael Example", email: "michael@example.com", password: nil, created_at: "2015-05-22 22:13:21", updated_at: "2015-05-22 22:13:22", password_digest: "$2a$04$PvQxwZgXnhi9RxICezCHJuQRRkUiSoP9qjPixSvx8mb...", remember_digest: "$2a$04$obYQeBWrZ59amJ9Ey2nd6.r8aeD.2h14uiEGB1XpywS...">
+nil
test/helpers/sessions_helper_test.rb:10:in `block in <class:SessionsHelperTest>'
会话助手测试
require 'test_helper'
class SessionsHelperTest < ActionView::TestCase
def setup
@user = users(:micheal)
remember(@user)
end
test "current_user returns right user when session is nil" do
assert_equal @user, current_user
assert is_logged_in?
end
test "current_user returns nil when remember digest is wrong" do
@user.update_attribute(:remember_digest, User.digest(User.new_token))
assert_nil current_user
end
end
【问题讨论】:
标签: ruby-on-rails ruby activerecord