Permalink
Browse files

Merge pull request #166 from barsoom/key_in_missing_interpolation_arg…

…s_errors

Include the missing key in "missing interpolation argument" errors.
  • Loading branch information...
2 parents 2b93dc9 + efd9f1c commit 09c0aa7cc08a71f2f53e9cf5fab6fe488cba49b2 @tigrish tigrish committed Sep 16, 2012
@@ -77,7 +77,7 @@ def nil_key(key)
end
def missing_key(key)
- "raise(MissingInterpolationArgument.new(#{key}, self))"
+ "raise(MissingInterpolationArgument.new(#{key}, {}, self))"
end
def reserved_key(key)
@@ -81,10 +81,10 @@ def initialize(entry, count)
end
class MissingInterpolationArgument < ArgumentError
- attr_reader :values, :string
- def initialize(values, string)
- @values, @string = values, string
- super "missing interpolation argument in #{string.inspect} (#{values.inspect} given)"
+ attr_reader :key, :values, :string
+ def initialize(key, values, string)
+ @key, @values, @string = key, values, string
+ super "missing interpolation argument #{key.inspect} in #{string.inspect} (#{values.inspect} given)"
end
end
@@ -21,7 +21,7 @@ def interpolate_hash(string, values)
'%'
else
key = ($1 || $2).to_sym
- value = values.key?(key) ? values[key] : raise(MissingInterpolationArgument.new(values, string))
+ value = values.key?(key) ? values[key] : raise(MissingInterpolationArgument.new(key, values, string))
value = value.call(values) if value.respond_to?(:call)
$3 ? sprintf("%#{$3}", value) : value
end
@@ -54,14 +54,14 @@ def test_invalid_locale_stores_locale
test "MissingInterpolationArgument stores key and string" do
assert_raise(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
force_missing_interpolation_argument do |exception|
- # assert_equal :bar, exception.key
+ assert_equal :bar, exception.key
assert_equal "%{bar}", exception.string
end
end
test "MissingInterpolationArgument message contains the missing and given arguments" do
force_missing_interpolation_argument do |exception|
- assert_equal 'missing interpolation argument in "%{bar}" ({:baz=>"baz"} given)', exception.message
+ assert_equal 'missing interpolation argument :bar in "%{bar}" ({:baz=>"baz"} given)', exception.message
end
end

0 comments on commit 09c0aa7

Please sign in to comment.