2016-03-08 71 views
0

登錄測試哈特爾教程CH 8.2.4:使用燈具

$ bundle exec rake test TEST=test/integration/users_login_test.rb \ 
>      TESTOPTS="--name test_login_with_valid_information" 

測試時,錯誤應該通過,但我得到的錯誤信息: 「的ActiveRecord ::夾具:: FormatError:」 3次。一些其他類似的帖子已經回答了檢查.yml文件的建議,因爲它需要看到空格而不是標籤。我嘗試直接粘貼到教程中的文件中,嘗試了各種製表符和空格的組合,但無法擺脫此錯誤。這裏是我的/test/fixtures/users.yml文件:

#michael: 
    name: Michael Example 
    email: [email protected] 
    password_digest: <%= User.digest('password') %> 

這裏是我的/test/integration/users_login_test.rb文件:

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 

任何援助將不勝感激,事情已經進展如此順利,令人沮喪停頓!

+1

您YAML的第一行被註釋掉(''#),這似乎是一個問題。 –

+0

謝謝@Jordan。有多少次你可以看到正前方的東西,但仍然看不到。 – FBtLL

回答

0

在你測試/裝置/ users.yml裏文件:

#michael: 
    name: Michael Example 
    email: [email protected] 
    password_digest: <%= User.digest('password') %> 

存在的michael前不必要#(註釋)。

[參考:Rails的教程repo]

相關問題