Permalink
Browse files

Ensuring that with_locale changes locale back even on error, using Ar…

…ray#reverse_each for fallback iteration instead of complicated down_to logic
  • Loading branch information...
1 parent 14cfd70 commit e2050372e99fd60ce750db91a62461eb1df3a8e4 Cameron Dutro committed Jan 8, 2013
Showing with 15 additions and 0 deletions.
  1. +15 −0 spec/twitter_cldr_spec.rb
@@ -277,6 +277,21 @@
TwitterCldr.with_locale(:es) { TwitterCldr::Shared::Languages.from_code(:es) }.should match_normalized("español")
TwitterCldr::Shared::Languages.from_code(:es).should == "Spanish"
end
+
+ it "switches the locale back to the original if the block raises an error" do
+ TwitterCldr.locale.should == :en
+ locale_inside_block = nil
+
+ lambda do
+ TwitterCldr.with_locale(:es) do
+ locale_inside_block = TwitterCldr.locale
+ raise "Error!"
+ end
+ end.should raise_error
+
+ locale_inside_block.should == :es
+ TwitterCldr.locale.should == :en
+ end
end
describe '#resources' do

0 comments on commit e205037

Please sign in to comment.