diff --git a/test/i18n_test.rb b/test/i18n_test.rb index 28becfc6..eb6a200b 100644 --- a/test/i18n_test.rb +++ b/test/i18n_test.rb @@ -501,18 +501,14 @@ def call(exception, locale, key, options); key; end test "can reserve a key" do begin - reserved_keys_were = I18n::RESERVED_KEYS.dup + stub_const(I18n, :RESERVED_KEYS, []) do + I18n.reserve_key(:foo) + I18n.reserve_key("bar") - assert !I18n::RESERVED_KEYS.include?(:foo) - assert !I18n::RESERVED_KEYS.include?(:bar) - - I18n.reserve_key(:foo) - I18n.reserve_key("bar") - - assert I18n::RESERVED_KEYS.include?(:foo) - assert I18n::RESERVED_KEYS.include?(:bar) + assert I18n::RESERVED_KEYS.include?(:foo) + assert I18n::RESERVED_KEYS.include?(:bar) + end ensure - I18n::RESERVED_KEYS = reserved_keys_were I18n.instance_variable_set(:@reserved_keys_pattern, nil) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 78b96358..f36b20b2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -44,6 +44,16 @@ def store_translations(locale, data, options = I18n::EMPTY_HASH) def locales_dir File.dirname(__FILE__) + '/test_data/locales' end + + def stub_const(klass, constant, new_value) + old_value = klass.const_get(constant) + klass.send(:remove_const, constant) + klass.const_set(constant, new_value) + yield + ensure + klass.send(:remove_const, constant) + klass.const_set(constant, old_value) + end end class DummyRackApp