dimanche 4 janvier 2015

How to set the locale in RSpec View Examples

I want to test the view to make sure that error messages are properly rendered. My config.default_locale is 'fr'. So, I expect my view to find the proper Active Record error message from my french locale file.



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


This test passes when ran in isolation or with the other spec/views. But when I run the full test suite the view gets rendered with the message:translation missing: en.activerecord.errors.models.book.attributes.title.blank.


I don't understand why it renders with an en locale. I tried to force the locale with:



before do
allow(I18n).to receive(:locale).and_return(:fr)
allow(I18n).to receive(:default_locale).and_return(:fr)
end


and



before do
default_url_options[:locale] = 'fr'
end


Does anyone have an idea?


Aucun commentaire:

Enregistrer un commentaire