夹具错误 Hartl 第 8 章

Fixture error Hartl chapter 8

我刚刚完成了 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 中创建用户