2017-09-10 28 views
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) 

起初我可以簡單地刪除燈具。但稍後應該有裝置,例如非唯一的電子郵件。

回答

0

爲了加載裝置Rails不需要你的權限。從documentation

測試環境會自動負載的所有燈具到 每次測試之前數據庫。爲確保數據一致, 環境在運行負載之前刪除燈具。

相關問題