1
有模型如下:比較rspec的定製的ActiveRecord :: RecordInvalid錯誤的消息
validates_uniqueness_of :title,
if: proc { |item| item.item_type == 'tag' },
case_sensitive: false,
message: I18n.t('errors.key', value: "%{value}")
,並試圖在rspec的驗證與以下幾點:
expect { xxx }.to raise_error(
ActiveRecord::RecordInvalid,
I18n.t('errors.key', value: '...passing the title...')
)
我堅持用非常接近以下:
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)
也是如此使用默認設置:
個感謝,如果對一個