1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2013-10-09 15:17:20 +00:00
parent e92ee13c6d
commit 2918f391dd
5 changed files with 6 additions and 12 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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