测试没有通过8.20 railstutorial

时间:2015-09-02 17:46:17

标签: ruby-on-rails railstutorial.org

  

FAIL [“test_test_login_with_valid_information”,UsersLoginTest,2015-08-27 20:00:02 +0000]    test_test_login_with_valid_information#UsersLoginTest(1440705602.54s)           预计至少有1个元素匹配“a [href =”/ users.762146111“]”,找到0 ..           预期0为> = 1。           test / integration / users_login_test.rb:18:在`block in'

中      

2/2:

     

[============================================== ================================================== =======] 100%时间:00:00:00,时间:00:00:00

     

完成0.46825s 2次测试,10次断言,1次失败,0次错误,0次   跳过

这是user_login_test.rb

    require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest


  def setup
    @user = users(:michael)
  end

  test "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=?]", users_path(@user)
  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 flash.any?
    get root_path
    assert flash.empty?
  end
end

User.yml

michael: 
  name: michael 
  email: michael@example.com
  password_digest: <%= User.digest("password") %>

1 个答案:

答案 0 :(得分:0)

我会仔细检查您的标题模板,并确认“配置文件”链接(清单8.16)中有相应的代码,因为它显示的是测试失败。

我对Rails不是很精明,但这部分错误让我有点担心:matching "a[href="/users.762146111"]"。我希望这是/users/762…