Skip to content

Commit

Permalink
Standardize on Proc (vs proc or lambda)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Stringer committed Dec 18, 2013
1 parent 8ccf9a4 commit 229ee94
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/i18n/tests/procs.rb
Expand Up @@ -3,7 +3,7 @@
module I18n
module Tests
module Procs
test "lookup: given a translation is a proc it calls the proc with the key and interpolation values" do
test "lookup: given a translation is a Proc it calls the Proc with the key and interpolation values" do
I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) })
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo')
end
Expand All @@ -19,12 +19,12 @@ module Procs
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => [nil, :a_lambda], :foo => 'foo')
end

test "interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do
test "interpolation: given an interpolation value is a Proc it calls it with key and values before interpolating it" do
proc = lambda { |*args| filter_args(*args) }
assert_match %r(\[\{:foo=>#<Proc.*>\}\]), I18n.t(:does_not_exist, :default => '%{foo}', :foo => proc)
end

test "interpolation: given a key resolves to a lambda that returns a string then interpolation still works" do
test "interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do
proc = lambda { |*args| "%{foo}: " + filter_args(*args) }
assert_equal "foo: [:does_not_exist, {:foo=>\"foo\"}]", I18n.t(:does_not_exist, :default => proc, :foo => 'foo')
end
Expand All @@ -36,12 +36,12 @@ module Procs
assert_equal 'other', I18n.t(:does_not_exist, :default => proc, :count => 2)
end

test "lookup: given the option :resolve => false was passed it does not resolve proc translations" do
test "lookup: given the option :resolve => false was passed it does not resolve Proc translations" do
I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) })
assert_equal Proc, I18n.t(:a_lambda, :resolve => false).class
end

test "lookup: given the option :resolve => false was passed it does not resolve proc default" do
test "lookup: given the option :resolve => false was passed it does not resolve Proc default" do
assert_equal Proc, I18n.t(:does_not_exist, :default => lambda { |*args| filter_args(*args) }, :resolve => false).class
end

Expand Down

0 comments on commit 229ee94

Please sign in to comment.