我想测试视图,以确保错误消息被正确地呈现。我的config.default_locale
是'fr'
。因此,我期望我的视图从我的法语区域设置文件中找到适当的Active Record错误消息。
describe 'book/new.html.erb' do
let(:subject) { rendered }
before do
@book = Book.create #this generates errors on my model
render
end
it { should match 'some error message in French' }
end
这个测试在单独运行或与其他规范/视图一起运行时通过。但是当我运行完整的测试套件时,视图会呈现以下消息:translation missing: en.activerecord.errors.models.book.attributes.title.blank
。
我不明白为什么它使用了en
语言环境。我尝试强制使用语言环境:
before do
allow(I18n).to receive(:locale).and_return(:fr)
allow(I18n).to receive(:default_locale).and_return(:fr)
end
并且
before do
default_url_options[:locale] = 'fr'
end
有人有想法吗?