Skip to content

Commit

Permalink
Reload I18n after stubbing available locales
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javierm committed Dec 10, 2018
1 parent ddd3cd4 commit 0745c78
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions spec/features/localization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@
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
Expand Down

0 comments on commit 0745c78

Please sign in to comment.