ruby-changes:41609
From: nobu <ko1@a...>
Date: Fri, 29 Jan 2016 12:17:09 +0900 (JST)
Subject: [ruby-changes:41609] nobu:r53683 (trunk): test_erb.rb: improve assertions
nobu 2016-01-29 12:18:05 +0900 (Fri, 29 Jan 2016) New Revision: 53683 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53683 Log: 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). Modified files: trunk/test/erb/test_erb.rb Index: test/erb/test_erb.rb =================================================================== --- test/erb/test_erb.rb (revision 53682) +++ test/erb/test_erb.rb (revision 53683) @@ -203,13 +203,13 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L203 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 https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L262 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 https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L288 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 https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L342 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 https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L387 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 https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L413 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/