i18n locales and the pass of rspec parallel specs and

First rule of good unit testing is: each test should be independent of the other tests.

But if there is a global variable like I18n.locale than one spec could touch it and another spec will be run in a different locale from the default.


Before each suite of specs set the locale to the default. This ensures that the specs are run against the same locale each time. Specific code is:

# spec/rails_helper.rb
RSpec.configure do |config|
  config.before :each do
    I18n.locale = Globalize.locale = I18n.default_locale

i18n breaks spec isolation

Internationalization, or i18n, should be part of most platforms. This means that i18n features should be properly tests. In suites when one of the specs modifies i18n the specs that are run after that are dependent on this new local.

This seem trivial, but we only go to explore it the moment we started running specs in parallel on different CPU cores. The specs were started and run in different times and order on each run.