From 2918f391ddc23b9e8b6552a729cea80d71294372 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 9 Oct 2013 15:17:20 +0000 Subject: [PATCH] test/ruby: assert_raise_with_message * test/ruby: use assert_raise_with_message git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_argf.rb | 3 +-- test/ruby/test_array.rb | 3 +-- test/ruby/test_marshal.rb | 3 +-- test/ruby/test_rand.rb | 6 ++---- test/ruby/test_refinement.rb | 3 +-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index 1d2ded81be..fb869561a1 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -799,8 +799,7 @@ class TestArgf < Test::Unit::TestCase end argf = ARGF.class.new(*paths) paths.each do |path| - e = assert_raise(Errno::ENOENT) {argf.gets} - assert_match(/- #{Regexp.quote(path)}\z/, e.message) + assert_raise_with_message(Errno::ENOENT, /- #{Regexp.quote(path)}\z/) {argf.gets} end assert_nil(argf.gets, bug4274) end diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index b4f35af84d..873c49783f 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -2300,8 +2300,7 @@ class TestArray < Test::Unit::TestCase assert_equal([], a.rotate!(13)) assert_equal([], a.rotate!(-13)) a = [].freeze - e = assert_raise(RuntimeError) {a.rotate!} - assert_match(/can't modify frozen/, e.message) + assert_raise_with_message(RuntimeError, /can't modify frozen/) {a.rotate!} a = [1,2,3] assert_raise(ArgumentError) { a.rotate!(1, 1) } end diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index f502026cdf..7bd259329d 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -84,10 +84,9 @@ class TestMarshal < Test::Unit::TestCase def test_too_long_string data = Marshal.dump(C.new("a".force_encoding("ascii-8bit"))) data[-2, 1] = "\003\377\377\377" - e = assert_raise(ArgumentError, "[ruby-dev:32054]") { + assert_raise_with_message(ArgumentError, "marshal data too short", "[ruby-dev:32054]") { Marshal.load(data) } - assert_equal("marshal data too short", e.message) end diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb index 0517dd51c3..974e21e3c0 100644 --- a/test/ruby/test_rand.rb +++ b/test/ruby/test_rand.rb @@ -510,13 +510,11 @@ END assert_equal([2], (1..100).map {[1,2,3].sample(random: gen)}.uniq) def (gen = Object.new).rand(*) 100 end - e = assert_raise(RangeError) {[1,2,3].sample(random: gen)} - assert_match(/big 100\z/, e.message) + assert_raise_with_message(RangeError, /big 100\z/) {[1,2,3].sample(random: gen)} bug7903 = '[ruby-dev:47061] [Bug #7903]' def (gen = Object.new).rand(*) -1 end - e = assert_raise(RangeError) {[1,2,3].sample(random: gen)} - assert_match(/small -1\z/, e.message, bug7903) + assert_raise_with_message(RangeError, /small -1\z/, e.message, bug7903) {[1,2,3].sample(random: gen)} bug7935 = '[ruby-core:52779] [Bug #7935]' class << (gen = Object.new) diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 92f293cad5..31234ed00b 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -441,12 +441,11 @@ class TestRefinement < Test::Unit::TestCase def test_refine_without_block c1 = Class.new - e = assert_raise(ArgumentError) { + assert_raise_with_message(ArgumentError, "no block given") { Module.new do refine c1 end } - assert_equal("no block given", e.message) end module Inspect