Skip to content

Commit

Permalink
with_locale now returns yielded value, added spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Dutro authored and camertron committed Jan 12, 2013
1 parent 75da55c commit d50d7ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/twitter_cldr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions spec/twitter_cldr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d50d7ba

Please sign in to comment.