summaryrefslogtreecommitdiff
path: root/test/erb
diff options
context:
space:
mode:
authorkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-27 08:48:24 +0000
committerkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-27 08:48:24 +0000
commitf0bb63782a2102cf5d353f9b0828370bb5ad85c6 (patch)
tree401611e7580030f0d78c8a9276f397e41c2f81e7 /test/erb
parent7a6cafc88e3b41e94d6473683580b36a39f59be1 (diff)
* lib/erb.rb: adjust line number for magic comment.
* test/erb/test_erb.rb: add tests for def_method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/erb')
-rw-r--r--test/erb/test_erb.rb27
1 files changed, 26 insertions, 1 deletions
diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb
index ccd3ddb..8a6221b 100644
--- a/test/erb/test_erb.rb
+++ b/test/erb/test_erb.rb
@@ -220,7 +220,7 @@ EOS
class Bar; end
- def test_def_method
+ def test_def_erb_method
assert(! Bar.new.respond_to?('hello'))
Bar.module_eval do
extend ERB::DefMethod
@@ -237,6 +237,31 @@ EOS
assert(Bar.new.respond_to?('hello_world'))
end
+ class DefMethodWithoutFname; end
+ class DefMethodWithFname; end
+
+ def test_def_method_without_filename
+ erb = ERB.new("<% raise ::TestERB::MyError %>")
+ erb.filename = "test filename"
+ assert(! DefMethodWithoutFname.new.respond_to?('my_error'))
+ erb.def_method(DefMethodWithoutFname, 'my_error')
+ e = assert_raise(::TestERB::MyError) {
+ DefMethodWithoutFname.new.my_error
+ }
+ assert_match(/\A\(ERB\):1\b/, e.backtrace[0])
+ end
+
+ def test_def_method_with_fname
+ erb = ERB.new("<% raise ::TestERB::MyError %>")
+ erb.filename = "test filename"
+ assert(! DefMethodWithFname.new.respond_to?('my_error'))
+ erb.def_method(DefMethodWithFname, 'my_error', 'test fname')
+ e = assert_raise(::TestERB::MyError) {
+ DefMethodWithFname.new.my_error
+ }
+ assert_match(/\Atest fname:1\b/, e.backtrace[0])
+ end
+
def test_escape
src = <<EOS
1.<%% : <%="<%%"%>