From 5b6dc9d7ff7cab4f5b7b2cf6951c4b5a6559e3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 11 Aug 2021 05:20:14 +0200 Subject: [PATCH] Fix enforce_available_locales leak between tests Even if it doesn't seem to have consequences right now, we certainly prefer other tests to use the default value. --- spec/i18n_spec.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index 15e588638..bde677915 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -41,13 +41,19 @@ describe "I18n" do I18n.backend.store_translations(I18n.default_locale, { test_plural: keys }) I18n.backend.store_translations(:zz, {}) - I18n.enforce_available_locales = false - I18n.with_locale(:zz) do - I18n.fallbacks[:zz] << I18n.default_locale + default_enforce = I18n.enforce_available_locales - expect(I18n.t("test_plural", count: 0)).to eq("No comments") - expect(I18n.t("test_plural", count: 1)).to eq("1 comment") - expect(I18n.t("test_plural", count: 2)).to eq("2 comments") + begin + I18n.enforce_available_locales = false + I18n.with_locale(:zz) do + I18n.fallbacks[:zz] << I18n.default_locale + + expect(I18n.t("test_plural", count: 0)).to eq("No comments") + expect(I18n.t("test_plural", count: 1)).to eq("1 comment") + expect(I18n.t("test_plural", count: 2)).to eq("2 comments") + end + ensure + I18n.enforce_available_locales = default_enforce end end