Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky localization specs #1631

Merged

Conversation

javierm
Copy link

@javierm javierm commented Sep 10, 2018

References

Objectives

Fix the flaky specs that appeared in spec/features/localization_spec.rb:34 ("Localization Changing the locale") and spec/features/localization_spec.rb:20 ("Localization Available locales appear in the locale switcher").

Explain why the test is flaky, or under which conditions/scenario it fails randomly

These specs fail when executed after spec/customization_engine_spec.rb:19 and spec/features/localization_spec.rb:44, causing the following sequence:

  1. The first test executes I18n.reload!, which causes I18n.config.backend to set @translations = nil.
  2. The second test stubs available_locales to [:en], causing @translations to get only translations for :en.
  3. The third test doesn't find translations for Spanish because @translations only has the English ones, and fails.

Explain why your PR fixes it

Reloading I18n after the test stubbing available_locales solves the problem, since it sets @translations = nil again, and so it fetches translations for Spanish (and all the other languages).

Notes

@javierm javierm force-pushed the 1630-fix_flaky_localization_specs branch from 58b5f01 to 375a83e Compare December 7, 2018 13:33
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
@javierm javierm force-pushed the 1630-fix_flaky_localization_specs branch from 375a83e to 0745c78 Compare December 10, 2018 10:08
@javierm javierm merged commit 991cb6c into AyuntamientoMadrid:master Dec 10, 2018
@javierm javierm deleted the 1630-fix_flaky_localization_specs branch November 11, 2019 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants