我在尝试创建用户对象时遇到了异常行为,这对我的用户来说是一个工厂位:
FactoryGirl.define do
factory :user do
firstname "Firstname"
sequence(:surname) { |n| "#{n}" }
sequence(:email) { |n| "user_#{n}@test.com"}
password "pwdddddd"
dob Time.zone.now - 19.years
phone "432423432431"
end
end
我有一个测试:
describe 'just an ordinary test' do
let(:user) { build(:user) }
end
测试因此错误而失败:
ActiveRecord::RecordInvalid:
Validation failed: User can't be blank
所以我添加了这段代码,希望我能获得有关错误的更多信息:
let(:user) {
begin
build(:user)
rescue => e
puts "error: #{e.inspect}"
end
}
我明白了:
error: #<ActiveRecord::RecordInvalid: Validation failed: User can't be blank>
哪个不是很有帮助。如何验证用户user can't be blank
。
我的头疼,这个,任何类似的经历?