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

Imported minitest 1.4.0 r5083.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ryan 2009-06-18 07:31:39 +00:00
parent 7fc9c4a4a0
commit 58cfb41d2a
5 changed files with 49 additions and 24 deletions

View file

@ -1,3 +1,8 @@
Thu Jun 18 16:21:05 2009 Ryan Davis <ryand-ruby@zenspider.com>
* lib/minitest/*.rb: Imported minitest 1.4.0 r5083.
* test/minitest/*.rb: ditto.
Thu Jun 18 01:35:51 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (flo_cmp): Infinity is greater than any bignum

View file

@ -5,5 +5,7 @@
############################################################
require 'minitest/unit'
require 'minitest/spec'
require 'minitest/mock'
MiniTest::Unit.autorun

View file

@ -55,15 +55,25 @@ end
module Kernel
def describe desc, &block
cls = Class.new(MiniTest::Spec)
Object.const_set desc.to_s.split(/\W+/).map { |s| s.capitalize }.join, cls
stack = MiniTest::Spec.describe_stack
name = desc.to_s.split(/\W+/).map { |s| s.capitalize }.join + "Spec"
cls = Object.class_eval "class #{name} < #{stack.last}; end; #{name}"
cls.nuke_test_methods!
stack.push cls
cls.class_eval(&block)
stack.pop
end
private :describe
end
class MiniTest::Spec < MiniTest::Unit::TestCase
@@describe_stack = [MiniTest::Spec]
def self.describe_stack
@@describe_stack
end
def self.current
@@current_spec
end
@ -73,14 +83,29 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
@@current_spec = self
end
def self.nuke_test_methods!
self.public_instance_methods.grep(/^test_/).each do |name|
send :remove_method, name rescue nil
end
end
def self.define_inheritable_method name, &block
super_method = self.superclass.instance_method name
define_method name do
super_method.bind(self).call if super_method # regular super() warns
instance_eval(&block)
end
end
def self.before(type = :each, &block)
raise "unsupported before type: #{type}" unless type == :each
define_method :setup, &block
define_inheritable_method :setup, &block
end
def self.after(type = :each, &block)
raise "unsupported after type: #{type}" unless type == :each
define_method :teardown, &block
define_inheritable_method :teardown, &block
end
def self.it desc, &block

View file

@ -343,7 +343,7 @@ module MiniTest
def location e
last_before_assertion = ""
e.backtrace.reverse_each do |s|
break if s =~ /in .(assert|refute|flunk|pass|fail|raise)/
break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
last_before_assertion = s
end
last_before_assertion.sub(/:in .*$/, '')
@ -430,30 +430,30 @@ module MiniTest
end
class TestCase
attr_reader :name
attr_reader :__name__
def run runner
result = '.'
begin
@passed = nil
self.setup
self.__send__ self.name
self.__send__ self.__name__
@passed = true
rescue Exception => e
@passed = false
result = runner.puke(self.class, self.name, e)
result = runner.puke(self.class, self.__name__, e)
ensure
begin
self.teardown
rescue Exception => e
result = runner.puke(self.class, self.name, e)
result = runner.puke(self.class, self.__name__, e)
end
end
result
end
def initialize name
@name = name
@__name__ = name
@passed = nil
end

View file

@ -325,7 +325,8 @@ Finished in 0.00
output.sub!(/^(\s+)(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+:/o, '\1FILE:LINE:')
output.sub!(/\[(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+\]/o, '[FILE:LINE]')
assert_equal(expected, output)
end
end
def test_run_failing_filtered
tc = Class.new(MiniTest::Unit::TestCase) do
def test_something
@ -468,10 +469,9 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end
def test_assert_in_delta_triggered
e = assert_raises(MiniTest::Assertion) do
util_assert_triggered 'Expected 0.0 - 0.001 (0.001) to be < 1.0e-06.' do
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
end
assert_match /\AExpected 0\.0 - 0\.001 \(0\.001\) to be < (?:1\.0+\de-06|9\.9+\de-07).\z/, e.message
end
def test_assert_in_epsilon
@ -489,10 +489,9 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
end
def test_assert_in_epsilon_triggered
e = assert_raises(MiniTest::Assertion) do
util_assert_triggered 'Expected 10000 - 9990 (10) to be < 9.99.' do
@tc.assert_in_epsilon 10000, 9990
end
assert_match(/\AExpected 10000 - 9990 \(10\) to be < 9\.99*\d*\.\z/, e.message)
end
end
def test_assert_includes
@ -831,10 +830,9 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
end
def test_refute_in_delta_triggered
e = assert_raises(MiniTest::Assertion) do
util_assert_triggered 'Expected 0.0 - 0.001 (0.001) to not be < 0.1.' do
@tc.refute_in_delta 0.0, 1.0 / 1000, 0.1
end
assert_match /\AExpected 0\.0 - 0\.001 \(0\.001\) to not be < 0\.10*\d*\.\z/, e.message
end
def test_refute_in_epsilon
@ -983,11 +981,6 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
msg = e.message.sub(/(---Backtrace---).*/m, '\1')
msg.gsub!(/\(0x[0-9a-f]+\)/, '(0xXXX)')
begin
assert_equal expected, msg
rescue MiniTest::Assertion => e
e.backtrace.shift(3)
raise
end
assert_equal expected, msg
end
end