我一直在浏览 Rails 教程,将用户帐户放在一起并为我正在处理的项目运行测试。
Failures:
1) when email format is invalid should be invalid
Failure/Error: @user.email = invalid_address
NoMethodError:
undefined method `email=' for nil:NilClass
# ./spec/models/user_spec.rb:71:in `block (3 levels) in <top (required)>'
# ./spec/models/user_spec.rb:70:in `each'
# ./spec/models/user_spec.rb:70:in `block (2 levels) in <top (required)>'
2) when email format is valid should be valid
Failure/Error: @user.email = valid_address
NoMethodError:
undefined method `email=' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (3 levels) in <top (required)>'
# ./spec/models/user_spec.rb:80:in `each'
# ./spec/models/user_spec.rb:80:in `block (2 levels) in <top (required)>'
Finished in 0.527 seconds
9 examples, 2 failures
Failed examples:
rspec ./spec/models/user_spec.rb:67 # when email format is invalid should be invalid
rspec ./spec/models/user_spec.rb:78 # when email format is valid should be valid
我不知道问题是什么。我看到了它的内容,但我什至 C&P 了教程中的代码,以仔细检查我所做的工作,以确保所有内容都正确输入。
这是 user_spec 文件。
https://gist.github.com/pwz2k/4770845
这是 user.rb 文件。
https://gist.github.com/pwz2k/4770854
直到我添加了电子邮件验证,失败才出现。