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
This commit is contained in:
Javi Martín
2018-09-10 11:52:36 +02:00
parent feb4af21c7
commit 34e83292a9

View File

@@ -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