gpt4 book ai didi

ruby-on-rails - 夹具错误 Hartl 第 8 章

转载 作者:行者123 更新时间:2023-12-02 09:34:11 24 4
gpt4 key购买 nike

我刚刚完成了 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

这是错误

ERROR["test_login_with_invalid_information", UsersLoginTest, 0.006789]
test_login_with_invalid_information#UsersLoginTest (0.01s)
StandardError: StandardError: No fixture named 'michael' found for fixture set 'users'
test/integration/users_login_test.rb:6:in `setup'
test/integration/users_login_test.rb:6:in `setup'

ERROR["test_login_with_valid_information", UsersLoginTest, 0.008174]
test_login_with_valid_information#UsersLoginTest (0.01s)
StandardError: StandardError: No fixture named 'michael' found for fixture set 'users'
test/integration/users_login_test.rb:6:in `setup'
test/integration/users_login_test.rb:6:in `setup'

DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
unexpected '#' after '[#<Nokogiri::CSS::Node:0x007fa642d4e870 @type=:ELEMENT_NAME, @value=["div"]>]' (called from block in <class:UsersSignupTest> at /Users/SamDavidoff/Documents/workspace/sample_app/test/integration/users_signup_test.rb:14)
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
unexpected '<' after '.' (called from block in <class:UsersSignupTest> at /Users/SamDavidoff/Documents/workspace/sample_app/test/integration/users_signup_test.rb:15)
ERROR["test_valid_signup_information", UsersSignupTest, 0.197435]
test_valid_signup_information#UsersSignupTest (0.20s)
NoMethodError: NoMethodError: undefined method `is_logged_in?' for #<UsersSignupTest:0x007fa642dd6068>
test/integration/users_signup_test.rb:27:in `block in <class:UsersSignupTest>'
test/integration/users_signup_test.rb:27:in `block in <class:UsersSignupTest>'

最佳答案

您没有在文件 test/fixtures/users.yml 中创建用户 Here

关于ruby-on-rails - 夹具错误 Hartl 第 8 章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28930615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com