diff options
author | k0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-25 15:38:25 +0000 |
---|---|---|
committer | k0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-25 15:38:25 +0000 |
commit | eb1652b57171f5af5b667010c1721d5d29c5a437 (patch) | |
tree | b4cf5f243c1c55672f7a9ea4b9b3431ab0dbc9bb /test/erb | |
parent | fd8df3ab3d935b4a201f9cb28598c95e4bb1ef14 (diff) | |
download | ruby-eb1652b57171f5af5b667010c1721d5d29c5a437.tar.gz |
erb.rb: Add ERB#result_with_hash
[ruby-core:55985] [Feature #8631] [fix GH-1623]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/erb')
-rw-r--r-- | test/erb/test_erb.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb index 10fb177f58..c41ba25d7c 100644 --- a/test/erb/test_erb.rb +++ b/test/erb/test_erb.rb @@ -564,6 +564,35 @@ EOS assert_equal(flag, erb.result) end end + + def test_result_with_hash + erb = @erb.new("<%= foo %>") + assert_equal("1", erb.result_with_hash(foo: "1")) + end + + def test_result_with_hash_does_not_use_caller_local_variables + erb = @erb.new("<%= foo %>") + foo = 1 + assert_raise(NameError) { erb.result_with_hash({}) } + end + + def test_result_with_hash_does_not_modify_caller_binding + erb = @erb.new("<%= foo %>") + erb.result_with_hash(foo: "1") + assert_equal(false, binding.local_variable_defined?(:foo)) + end + + def test_result_with_hash_does_not_modify_toplevel_binding + erb = @erb.new("<%= foo %>") + erb.result_with_hash(foo: "1") + assert_equal(false, TOPLEVEL_BINDING.local_variable_defined?(:foo)) + end + + # This depends on the behavior that #local_variable_set raises TypeError by invalid key. + def test_result_with_hash_with_invalid_keys_raises_type_error + erb = @erb.new("<%= 1 %>") + assert_raise(TypeError) { erb.result_with_hash({ 1 => "1" }) } + end end class TestERBCoreWOStrScan < TestERBCore |