0
我已经开始与一个简单的测试:Rails的是使用固定装置没有我的允许
class UserTest < ActiveSupport::TestCase
test 'should not create user without email' do
user = User.new
assert_not user.save
end
end
和Rails自动生成的一些灯具:
one:
email: MyString
login_token: MyString
token_generated_at: 2017-09-10 17:24:55
two:
email: MyString
login_token: MyString
token_generated_at: 2017-09-10 17:24:55
因此,大家可以看到我没有使用任何固定装置进行测试。但是在执行测试时,Rails会抛出一个异常:
Error:
UserTest#test_should_not_create_user_without_email:
ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: users.email: INSERT INTO "users" ("email", "login_token", "token_date", "created_at", "updated_at", "id") VALUES ('MyString', 'MyString', '2017-09-10 17:24:55', '2017-09-10 15:48:11.483364', '2017-09-10 15:48:11.483364', 298486374)
起初我可以简单地删除灯具。但稍后应该有装置,例如非唯一的电子邮件。