mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test_erb.rb: improve assertions
* test/erb/test_erb.rb: improve failure messages with assert_respond_to and assert_not_respond_to. * test/erb/test_erb.rb: use assert_raise instead of assert(false). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c55ad90a6e
commit
f54b960d30
1 changed files with 26 additions and 38 deletions
|
@ -203,13 +203,13 @@ EOS
|
|||
erb = @erb.new('hello')
|
||||
cls = erb.def_class
|
||||
assert_equal(Object, cls.superclass)
|
||||
assert(cls.new.respond_to?('result'))
|
||||
assert_respond_to(cls.new, 'result')
|
||||
cls = erb.def_class(Foo)
|
||||
assert_equal(Foo, cls.superclass)
|
||||
assert(cls.new.respond_to?('result'))
|
||||
assert_respond_to(cls.new, 'result')
|
||||
cls = erb.def_class(Object, 'erb')
|
||||
assert_equal(Object, cls.superclass)
|
||||
assert(cls.new.respond_to?('erb'))
|
||||
assert_respond_to(cls.new, 'erb')
|
||||
end
|
||||
|
||||
def test_percent
|
||||
|
@ -262,21 +262,21 @@ EOS
|
|||
fname = File.join(File.dirname(File.expand_path(__FILE__)), 'hello.erb')
|
||||
def_erb_method('hello', fname)
|
||||
end
|
||||
assert(klass.new.respond_to?('hello'))
|
||||
assert_respond_to(klass.new, 'hello')
|
||||
|
||||
assert(! klass.new.respond_to?('hello_world'))
|
||||
assert_not_respond_to(klass.new, 'hello_world')
|
||||
erb = @erb.new('hello, world')
|
||||
klass.module_eval do
|
||||
def_erb_method('hello_world', erb)
|
||||
end
|
||||
assert(klass.new.respond_to?('hello_world'))
|
||||
assert_respond_to(klass.new, 'hello_world')
|
||||
end
|
||||
|
||||
def test_def_method_without_filename
|
||||
klass = Class.new
|
||||
erb = ERB.new("<% raise ::TestERB::MyError %>")
|
||||
erb.filename = "test filename"
|
||||
assert(! klass.new.respond_to?('my_error'))
|
||||
assert_not_respond_to(klass.new, 'my_error')
|
||||
erb.def_method(klass, 'my_error')
|
||||
e = assert_raise(::TestERB::MyError) {
|
||||
klass.new.my_error
|
||||
|
@ -288,7 +288,7 @@ EOS
|
|||
klass = Class.new
|
||||
erb = ERB.new("<% raise ::TestERB::MyError %>")
|
||||
erb.filename = "test filename"
|
||||
assert(! klass.new.respond_to?('my_error'))
|
||||
assert_not_respond_to(klass.new, 'my_error')
|
||||
erb.def_method(klass, 'my_error', 'test fname')
|
||||
e = assert_raise(::TestERB::MyError) {
|
||||
klass.new.my_error
|
||||
|
@ -342,12 +342,10 @@ Hello,\s
|
|||
EOS
|
||||
|
||||
erb = ERB.new(src, nil, '%')
|
||||
begin
|
||||
e = assert_raise(RuntimeError) {
|
||||
erb.result
|
||||
assert(false)
|
||||
rescue
|
||||
assert_match(/\A\(erb\):4\b/, $@[0].to_s)
|
||||
end
|
||||
}
|
||||
assert_match(/\A\(erb\):4\b/, e.backtrace[0].to_s)
|
||||
|
||||
src = <<EOS
|
||||
%>
|
||||
|
@ -389,28 +387,22 @@ Hello,\s
|
|||
EOS
|
||||
|
||||
erb = ERB.new(src)
|
||||
begin
|
||||
e = assert_raise(RuntimeError) {
|
||||
erb.result
|
||||
assert(false)
|
||||
rescue
|
||||
assert_match(/\A\(erb\):5\b/, $@[0].to_s)
|
||||
end
|
||||
}
|
||||
assert_match(/\A\(erb\):5\b/, e.backtrace[0].to_s)
|
||||
|
||||
erb = ERB.new(src, nil, '>')
|
||||
begin
|
||||
e = assert_raise(RuntimeError) {
|
||||
erb.result
|
||||
assert(false)
|
||||
rescue
|
||||
assert_match(/\A\(erb\):5\b/, $@[0].to_s)
|
||||
end
|
||||
}
|
||||
assert_match(/\A\(erb\):5\b/, e.backtrace[0].to_s)
|
||||
|
||||
erb = ERB.new(src, nil, '<>')
|
||||
begin
|
||||
e = assert_raise(RuntimeError) {
|
||||
erb.result
|
||||
assert(false)
|
||||
rescue
|
||||
assert_match(/\A\(erb\):5\b/, $@[0].to_s)
|
||||
end
|
||||
}
|
||||
assert_match(/\A\(erb\):5\b/, e.backtrace[0].to_s)
|
||||
|
||||
src = <<EOS
|
||||
% y = 'Hello'
|
||||
|
@ -421,20 +413,16 @@ EOS
|
|||
EOS
|
||||
|
||||
erb = ERB.new(src, nil, '-')
|
||||
begin
|
||||
e = assert_raise(RuntimeError) {
|
||||
erb.result
|
||||
assert(false)
|
||||
rescue
|
||||
assert_match(/\A\(erb\):5\b/, $@[0].to_s)
|
||||
end
|
||||
}
|
||||
assert_match(/\A\(erb\):5\b/, e.backtrace[0].to_s)
|
||||
|
||||
erb = ERB.new(src, nil, '%-')
|
||||
begin
|
||||
e = assert_raise(RuntimeError) {
|
||||
erb.result
|
||||
assert(false)
|
||||
rescue
|
||||
assert_match(/\A\(erb\):5\b/, $@[0].to_s)
|
||||
end
|
||||
}
|
||||
assert_match(/\A\(erb\):5\b/, e.backtrace[0].to_s)
|
||||
end
|
||||
|
||||
def test_explicit
|
||||
|
|
Loading…
Reference in a new issue