哈特尔教程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
任何援助将不胜感激,事情已经进展如此顺利,令人沮丧停顿!
答
在你测试/装置/ users.yml里文件:
#michael: name: Michael Example email: [email protected] password_digest: <%= User.digest('password') %>
存在的michael
前不必要#
(注释)。
[参考:Rails的教程repo]
您YAML的第一行被注释掉(''#),这似乎是一个问题。 –
谢谢@Jordan。有多少次你可以看到正前方的东西,但仍然看不到。 – FBtLL