2017-07-16 7 views
1

:: RecordInvalidエラーメッセージ

ActiveRecord::RecordInvalid with "translated error", 
got #<ActiveRecord::RecordInvalid: Validation failed: translated error> 

期待値は引用符なしの値を待機し、値se NTは引用しています。

activerecord: 
    errors: 
     models: 
     item: 
      attributes: 
      title: 
       taken: 'translated error' 

同じテストは、以下を渡します:

expect { xxx }.to raise_error

expect { xxx }.to raise_error(ActiveRecord::RecordInvalid)

がそう、それは私が、デフォルトの設定で非常に同じエラーを取得している

に失敗しますデフォルトの設定を使用:

ありがとうございました

答えて

1

ActiveRecordは、接頭辞Validation failed:をエラーメッセージに追加します。代わりに、あなたのテストでこれを試してみてください:

expect { xxx }.to raise_error(
    ActiveRecord::RecordInvalid, 
    "Validation failed: " + I18n.t('errors.key', value: '...passing the title...') 
) 

あなたの言語ファイルで次のキーを設定することで、このデフォルトを変更できます。

en: 
    activerecord: 
    errors: 
     messages: 
     record_invalid: "Validation failed: %{errors}"