次のコードを RSpec テストに入れました。
it { should validate_format_of(:email).not_with('test@test')}
実際のクラスを次のようにセットアップします。
validates :email, :presence => true, :format => /\b[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i
テストを実行すると、次のようになります。
失敗: 1) ユーザーの失敗/エラー: it { should validate_format_of(:email).not_with('test@test')}エラー: ["name can't be blank (nil)", "email is invalid (\"test@test\")"] # ./spec/models/user_spec.rb:8:in `block (2 レベル)の '
次のような合格テストを行うと:
it { should validate_format_of(:email).with('adam@trimediatlantic.com')}
すべてが期待どおりに機能します。私が何か間違ったことをしているのか、それともフレームワークの問題なのか、誰か教えてもらえますか? ありがとうございました。