From 34e83292a9a89a5639fb73fa8a9d61b5e60e7eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 10 Sep 2018 11:52:36 +0200 Subject: [PATCH] Reload I18n after stubbing available locales Not doing so might cause the following test to use translations for only one locale. This scenario happens if the previous test executes I18n.reload!, which resets I18n.config.backend's "@translations" instance variable. So, the sequence could be as follows: 1. The previous tests sets `@translations = nil` 2. This test stubs `available_locales` to `[:en]` 3. `@translations` gets only translations for `en` 4. The following test doesn't find translations for Spanish and fails --- spec/features/localization_spec.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/spec/features/localization_spec.rb b/spec/features/localization_spec.rb index fc9cfb1e6..756af38cd 100644 --- a/spec/features/localization_spec.rb +++ b/spec/features/localization_spec.rb @@ -41,12 +41,19 @@ feature 'Localization' do expect(page).to have_select('locale-switcher', selected: 'EspaƱol') end - scenario 'Locale switcher not present if only one locale' do - allow(I18n).to receive(:available_locales).and_return([:en]) + context "Only one locale" do + before do + allow(I18n).to receive(:available_locales).and_return([:en]) + I18n.reload! + end - visit '/' - expect(page).not_to have_content('Language') - expect(page).not_to have_css('div.locale') + after { I18n.reload! } + + scenario "Locale switcher not present" do + visit '/' + expect(page).not_to have_content('Language') + expect(page).not_to have_css('div.locale') + end end context "Missing language names" do