夹具错误Hartl第8章

时间:2015-03-08 19:03:17

标签: ruby-on-rails shell sublimetext3

我刚刚通过了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>'

1 个答案:

答案 0 :(得分:5)

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