Skip to content
Browse files

with_locale now returns yielded value, added spec

  • Loading branch information...
1 parent 75da55c commit d50d7bacc0cb0fccc8432baba0d7668403e9f68c Cameron Dutro committed with camertron Dec 14, 2012
Showing with 10 additions and 1 deletion.
  1. +2 −1 lib/twitter_cldr.rb
  2. +8 −0 spec/twitter_cldr_spec.rb
View
3 lib/twitter_cldr.rb
@@ -75,8 +75,9 @@ def with_locale(locale)
raise "Unsupported locale" unless supported_locale?(locale)
old_locale = @locale
@locale = locale
- yield
+ result = yield
@locale = old_locale
+ result
end
def register_locale_fallback(proc_or_locale)
View
8 spec/twitter_cldr_spec.rb
@@ -162,6 +162,14 @@
end
end
+ describe "#with_locale" do
+ it "should only change the locale in the context of the block" do
+ TwitterCldr::Shared::Languages.from_code(:es).should == "Spanish"
+ TwitterCldr.with_locale(:es) { TwitterCldr::Shared::Languages.from_code(:es) }.should match_normalized("español")
+ TwitterCldr::Shared::Languages.from_code(:es).should == "Spanish"
+ end
+ end
+
describe '#resources' do
it 'returns @resources' do
resources = TwitterCldr::Resources::Loader.new

0 comments on commit d50d7ba

Please sign in to comment.
Something went wrong with that request. Please try again.