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)
也是如此使用默认设置:
个感谢,如果对一个