mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Imported minitest 1.7.2 r5879.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d1a4b54218
commit
4c6551b7d3
3 changed files with 80 additions and 27 deletions
|
|
@ -9,7 +9,7 @@
|
|||
require 'minitest/unit'
|
||||
|
||||
class Module
|
||||
def infect_an_assertion meth, new_name, dont_flip = false
|
||||
def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:
|
||||
# warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
|
||||
self.class_eval <<-EOM
|
||||
def #{new_name} *args, &block
|
||||
|
|
@ -22,11 +22,17 @@ class Module
|
|||
EOM
|
||||
end
|
||||
|
||||
##
|
||||
# Create your own expectations from MiniTest::Assertions using a
|
||||
# flexible set of rules. If you don't like must/wont, then this
|
||||
# method is your friend. For an example of its usage see the bottom
|
||||
# of minitest/spec.rb.
|
||||
|
||||
def infect_with_assertions(pos_prefix, neg_prefix,
|
||||
skip_re,
|
||||
dont_flip_re = /\c0/,
|
||||
map = {})
|
||||
MiniTest::Assertions.public_instance_methods(false).each do |meth|
|
||||
MiniTest::Assertions.public_instance_methods(false).sort.each do |meth|
|
||||
meth = meth.to_s
|
||||
|
||||
new_name = case meth
|
||||
|
|
@ -41,28 +47,14 @@ class Module
|
|||
regexp, replacement = map.find { |re, _| new_name =~ re }
|
||||
new_name.sub! regexp, replacement if replacement
|
||||
|
||||
puts "\n##\n# :method: #{new_name}\n# See MiniTest::Assertions##{meth}" if
|
||||
$0 == __FILE__
|
||||
|
||||
infect_an_assertion meth, new_name, new_name =~ dont_flip_re
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Object.infect_with_assertions(:must, :wont,
|
||||
/^(must|wont)$|wont_(throw)|
|
||||
must_(block|not?_|nothing|raise$)/x,
|
||||
/(must|wont)_(include|respond_to)/,
|
||||
/(must_throw)s/ => '\1',
|
||||
/(?!not)_same/ => '_be_same_as',
|
||||
/_in_/ => '_be_within_',
|
||||
/_operator/ => '_be',
|
||||
/_includes/ => '_include',
|
||||
/(must|wont)_(.*_of|nil|silent|empty)/ => '\1_be_\2',
|
||||
/must_raises/ => 'must_raise')
|
||||
|
||||
class Object
|
||||
alias :must_be_close_to :must_be_within_delta
|
||||
alias :wont_be_close_to :wont_be_within_delta
|
||||
end
|
||||
|
||||
module Kernel
|
||||
##
|
||||
# Describe a series of expectations for a given target +desc+.
|
||||
|
|
@ -97,6 +89,12 @@ class Module
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# MiniTest::Spec -- The faster, better, less-magical spec framework!
|
||||
#
|
||||
# For a list of expectations, see Object.
|
||||
|
||||
|
||||
class MiniTest::Spec < MiniTest::Unit::TestCase
|
||||
@@describe_stack = [MiniTest::Spec]
|
||||
def self.describe_stack # :nodoc:
|
||||
|
|
@ -174,10 +172,36 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|||
mod.send :undef_method, name if mod.respond_to? name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Object.infect_with_assertions(:must, :wont,
|
||||
/^(must|wont)$|wont_(throw)|
|
||||
must_(block|not?_|nothing|raise$)/x,
|
||||
/(must|wont)_(include|respond_to)/,
|
||||
/(must_throw)s/ => '\1',
|
||||
/(?!not)_same/ => '_be_same_as',
|
||||
/_in_/ => '_be_within_',
|
||||
/_operator/ => '_be',
|
||||
/_includes/ => '_include',
|
||||
/(must|wont)_(.*_of|nil|silent|empty)/ => '\1_be_\2',
|
||||
/must_raises/ => 'must_raise')
|
||||
|
||||
class Object
|
||||
alias :must_be_close_to :must_be_within_delta
|
||||
alias :wont_be_close_to :wont_be_within_delta
|
||||
|
||||
if $0 == __FILE__ then
|
||||
{ "must" => "assert", "wont" => "refute" }.each do |a, b|
|
||||
puts "\n"
|
||||
puts "##"
|
||||
puts "# :method: #{a}_be_close_to"
|
||||
puts "# See MiniTest::Assertions##{b}_in_delta"
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# :method: must_be
|
||||
# See MiniTest::Assertions#assert
|
||||
# See MiniTest::Assertions#assert_operator
|
||||
|
||||
##
|
||||
# :method: must_be_close_to
|
||||
|
|
@ -245,11 +269,11 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|||
|
||||
##
|
||||
# :method: must_throw
|
||||
# See MiniTest::Assertions#assert_throw
|
||||
# See MiniTest::Assertions#assert_throws
|
||||
|
||||
##
|
||||
# :method: wont_be
|
||||
# See MiniTest::Assertions#refute
|
||||
# See MiniTest::Assertions#refute_operator
|
||||
|
||||
##
|
||||
# :method: wont_be_close_to
|
||||
|
|
@ -279,10 +303,6 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
|
|||
# :method: wont_be_within_delta
|
||||
# See MiniTest::Assertions#refute_in_delta
|
||||
|
||||
##
|
||||
# :method: wont_be_within_delta
|
||||
# See MiniTest::Assertions#refute_in_delta
|
||||
|
||||
##
|
||||
# :method: wont_be_within_epsilon
|
||||
# See MiniTest::Assertions#refute_in_epsilon
|
||||
|
|
|
|||
|
|
@ -222,6 +222,14 @@ module MiniTest
|
|||
begin
|
||||
yield
|
||||
should_raise = true
|
||||
rescue MiniTest::Skip => e
|
||||
details = "#{msg}#{mu_pp(exp)} exception expected, not"
|
||||
|
||||
if exp.include? MiniTest::Skip then
|
||||
return e
|
||||
else
|
||||
raise e
|
||||
end
|
||||
rescue Exception => e
|
||||
details = "#{msg}#{mu_pp(exp)} exception expected, not"
|
||||
assert(exp.any? { |ex|
|
||||
|
|
@ -261,6 +269,7 @@ module MiniTest
|
|||
# +send_ary+ is a receiver, message and arguments.
|
||||
#
|
||||
# Fails unless the call returns a true value
|
||||
# TODO: I should prolly remove this from specs
|
||||
|
||||
def assert_send send_ary, m = nil
|
||||
recv, msg, *args = send_ary
|
||||
|
|
@ -503,7 +512,7 @@ module MiniTest
|
|||
end
|
||||
|
||||
class Unit
|
||||
VERSION = "1.7.1" # :nodoc:
|
||||
VERSION = "1.7.2" # :nodoc:
|
||||
|
||||
attr_accessor :report, :failures, :errors, :skips # :nodoc:
|
||||
attr_accessor :test_count, :assertion_count # :nodoc:
|
||||
|
|
|
|||
|
|
@ -642,6 +642,26 @@ class TestMiniTestTestCase < MiniTest::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# *sigh* This is quite an odd scenario, but it is from real (albeit
|
||||
# ugly) test code in ruby-core:
|
||||
#
|
||||
# http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29259
|
||||
|
||||
def test_assert_raises_skip
|
||||
@assertion_count = 0
|
||||
|
||||
util_assert_triggered "skipped", MiniTest::Skip do
|
||||
@tc.assert_raises ArgumentError do
|
||||
begin
|
||||
raise "blah"
|
||||
rescue
|
||||
skip "skipped"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_raises_module
|
||||
@tc.assert_raises M do
|
||||
raise E
|
||||
|
|
@ -828,6 +848,8 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
|
|||
def test_capture_io
|
||||
@assertion_count = 0
|
||||
|
||||
orig_verbose = $VERBOSE
|
||||
$VERBOSE = false
|
||||
out, err = capture_io do
|
||||
puts 'hi'
|
||||
warn 'bye!'
|
||||
|
|
@ -835,6 +857,8 @@ FILE:LINE:in `test_assert_raises_triggered_subclass'
|
|||
|
||||
assert_equal "hi\n", out
|
||||
assert_equal "bye!\n", err
|
||||
ensure
|
||||
$VERBOSE = orig_verbose
|
||||
end
|
||||
|
||||
def test_class_asserts_match_refutes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue