mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
7a6cafc88e
commit
f0bb63782a
3 changed files with 35 additions and 4 deletions
|
|
@ -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.<%% : <%="<%%"%>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue