title: How to set the locale in RSpec View Examples
body: <p>I want to test the view to make sure that error messages are properly rendered. My <code>config.default_locale</code> is <code>'fr'</code>. So, I expect my view to find the proper Active Record error message from my french locale file.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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:<code>translation missing: en.activerecord.errors.models.book.attributes.title.blank</code>.</p>
  
  <p>I don't understand why it renders with an <code>en</code> locale. I tried to force the locale with:</p>
  
  <pre><code>before do
    allow(I18n).to receive(:locale).and_return(:fr)
    allow(I18n).to receive(:default_locale).and_return(:fr)
  end
  </code></pre>
  
  <p>and</p>
  
  <pre><code>before do
    default_url_options[:locale] = 'fr'
  end
  </code></pre>
  
  <p>Does anyone have an idea?</p>