summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog6
-rw-r--r--lib/erb.rb6
-rw-r--r--test/erb/test_erb.rb27
3 files changed, 35 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 3098dc8..48b18f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Jun 27 17:45:17 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
+
+ * lib/erb.rb: adjust line number for magic comment.
+
+ * test/erb/test_erb.rb: add tests for def_method.
+
Fri Jun 27 14:25:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm.c (vm_eval_body): if thrown exception is frozen, reraise it to
diff --git a/lib/erb.rb b/lib/erb.rb
index d48d00a..c879941 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -736,16 +736,16 @@ class ERB
if @safe_level
th = Thread.start {
$SAFE = @safe_level
- eval(@src, b, (@filename || '(erb)'), 1)
+ eval(@src, b, (@filename || '(erb)'), 0)
}
return th.value
else
- return eval(@src, b, (@filename || '(erb)'), 1)
+ return eval(@src, b, (@filename || '(erb)'), 0)
end
end
def def_method(mod, methodname, fname='(ERB)') # :nodoc:
- mod.module_eval("def #{methodname}\n" + self.src + "\nend\n", fname, 0)
+ mod.module_eval("def #{methodname}\n" + self.src + "\nend\n", fname, -1)
end
def def_module(methodname='erb') # :nodoc:
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.<%% : <%="<%%"%>