我刚刚通过Hartl教程的第8章,但在我尝试运行测试时仍然遇到错误.我得到3个相同的错误,问题似乎源于用户登录测试,其中夹具:michael未在夹具集(用户)中找到.
这是我的user_login_test
require 'test_helper'
class UsersLoginTest < ActionDispatch::IntegrationTest
def setup
@user = users(:michael)
end
test "login with invalid information" do
get login_path
assert_template 'sessions/new'
post login_path, session: { email: "", password: "" }
assert_template 'sessions/new'
assert_not flash.empty?
get root_path
assert flash.empty?
end
test "login with valid information" do
get login_path
post login_path, session: { email: @user.email, password: 'password' }
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
end
end
Run Code Online (Sandbox Code Playgroud)
这是错误
ERROR["test_login_with_invalid_information", UsersLoginTest, …Run Code Online (Sandbox Code Playgroud) 我在Hartl的RoR指南的第10章中不断得到这两个错误,似乎无法找到解决方案.我已经故障排除了一段时间,但答案继续避开我.USER.rb有什么问题吗?
FAIL["test_name_should_not_be_too_long", UserTest, 0.436818]
test_name_should_not_be_too_long#UserTest (0.44s)
Expected true to be nil or false
test/models/user_test.rb:25:in `block in <class:UserTest>'
FAIL["test_name_should_be_present", UserTest, 0.441668]
test_name_should_be_present#UserTest (0.44s)
Expected true to be nil or false
test/models/user_test.rb:15:in `block in <class:UserTest>'
Run Code Online (Sandbox Code Playgroud)
这是我的User_test
require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@user = User.new(name: "Example User", email: "user@example.com", password: "foobar", password_confirmation: "foobar")
end
test "should be valid" do
assert @user.valid?
end
test "name should be present" do
@user.name = ""
assert_not @user.valid?
end
test "email should be present" do …Run Code Online (Sandbox Code Playgroud)