diff options
author | Sven Fuchs <svenfuchs@artweb-design.de> | 2009-07-08 18:17:42 +0200 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-07-18 11:27:27 -0700 |
commit | 17d5cc12b9f8d0d78a081d231e7e0c5ec9df1104 (patch) | |
tree | fcaf7a53e12c4c960f4cc55af3315886f8ba4344 /activesupport/test/core_ext | |
parent | 1c11437a32a973fa9b521c32caa7256f9772acd7 (diff) | |
download | rails-17d5cc12b9f8d0d78a081d231e7e0c5ec9df1104.tar.gz rails-17d5cc12b9f8d0d78a081d231e7e0c5ec9df1104.tar.bz2 rails-17d5cc12b9f8d0d78a081d231e7e0c5ec9df1104.zip |
* don't include String#% for Ruby 1.9
* raise a KeyError exception for missing named interpolation args (like Ruby 1.9 does)
* raise an ArgumentError when mixing named and unnamed placeholders (like Ruby 1.9 does)
* improve docs and comply a bit more w/ Rails names/conventions
[#2870 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index f77ad5236e..a23d3f6fef 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -311,8 +311,8 @@ class TestGetTextString < Test::Unit::TestCase end def test_sprintf_lack_argument - assert_equal("%{num}, test", "%{num}, %{record}" % {:record => "test"}) - assert_equal("%{record}", "%{record}" % {:num => 1}) + assert_raises(KeyError) { "%{num}, %{record}" % {:record => "test"} } + assert_raises(KeyError) { "%{record}" % {:num => 1} } end def test_no_placeholder @@ -336,9 +336,12 @@ class TestGetTextString < Test::Unit::TestCase assert_equal("foo 1.000000", "%s %f" % ["foo", 1.0]) end - def test_sprintf_mix + def test_sprintf_mix_unformatted_and_formatted_named_placeholders assert_equal("foo 1.000000", "%{name} %<num>f" % {:name => "foo", :num => 1.0}) - assert_equal("%{name} 1.000000", "%{name} %f" % [1.0]) - assert_equal("%{name} 1.000000", "%{name} %f" % [1.0, 2.0]) + end + + def test_string_interpolation_raises_an_argument_error_when_mixing_named_and_unnamed_placeholders + assert_raises(ArgumentError) { "%{name} %f" % [1.0] } + assert_raises(ArgumentError) { "%{name} %f" % [1.0, 2.0] } end end |