0

更新時にユーザーモデルで電子メールが必要ないことをテストしています。

FactoryGirlの場合:

u = FactoryGirl.create(:user)
u.email = nil
expect(u.save).to be_true 

テストに合格します。

べきである:

should_not validate_presence_of(:email).on(:update)

テストは次のエラーで失敗します。

Failure/Error: should_not validate_presence_of(:email)
Did not expect errors to include "can't be blank" when email is set to nil, got error:     can't be blank

この不一致が発生する理由について何か考えがある人はいますか?

4

1 に答える 1