Skip to content

Commit

Permalink
Imported minitest 1.6.0 r5717.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ryan committed Mar 28, 2010
1 parent d8cc6cc commit 1392791
Show file tree
Hide file tree
Showing 6 changed files with 509 additions and 107 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Sun Mar 28 10:35:45 2010 Ryan Davis <[email protected]>

* lib/minitest/*.rb: Imported minitest 1.6.0 r5717.
* test/minitest/*.rb: ditto.

Sun Mar 28 10:12:28 2010 Tanaka Akira <[email protected]>

* time.c (rb_time_magnify): fix for LP64.
Expand Down
1 change: 1 addition & 0 deletions lib/minitest/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def initialize
def expect(name, retval, args=[])
n, r, a = name, retval, args # for the closure below
@expected_calls[name] = { :retval => retval, :args => args }
self.class.__send__ :remove_method, name if respond_to? name
self.class.__send__(:define_method, name) { |*x|
raise ArgumentError unless @expected_calls[n][:args].size == x.size
@actual_calls[n] << { :retval => r, :args => x }
Expand Down
190 changes: 174 additions & 16 deletions lib/minitest/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ class Object
end

module Kernel
##
# Describe a series of expectations for a given target +desc+.
#
# TODO: find good tutorial url.
#
# Defines a test class subclassing from either
# MiniTest::Unit::TestCase or from the surrounding describe's class.

def describe desc, &block
stack = MiniTest::Spec.describe_stack
name = desc.to_s.split(/\W+/).map { |s| s.capitalize }.join + "Spec"
Expand All @@ -80,28 +88,36 @@ def describe desc, &block
private :describe
end

class Module
def classes type = Object # :nodoc:
constants.map { |n| const_get n }.find_all { |c|
c.class == Class and type > c
} - [self]
end
end

class MiniTest::Spec < MiniTest::Unit::TestCase
@@describe_stack = [MiniTest::Spec]
def self.describe_stack
def self.describe_stack # :nodoc:
@@describe_stack
end

def self.current
def self.current # :nodoc:
@@current_spec
end

def initialize name
def initialize name # :nodoc:
super
@@current_spec = self
end

def self.nuke_test_methods!
def self.nuke_test_methods! # :nodoc:
self.public_instance_methods.grep(/^test_/).each do |name|
self.send :undef_method, name
end
end

def self.define_inheritable_method name, &block
def self.define_inheritable_method name, &block # :nodoc:
super_method = self.superclass.instance_method name

define_method name do
Expand All @@ -110,25 +126,167 @@ def self.define_inheritable_method name, &block
end
end

def self.before(type = :each, &block)
if type == :all
warn "change before :all to before :each"
type = :each
end
##
# Define a 'before' action. Inherits the way normal methods should.
#
# NOTE: +type+ is ignored and is only there to make porting easier.
#
# Equivalent to MiniTest::Unit::TestCase#setup.

def self.before type = :each, &block
raise "unsupported before type: #{type}" unless type == :each
define_inheritable_method :setup, &block
end

def self.after(type = :each, &block)
if type == :all # REFACTOR
warn "change before :all to before :each"
type = :each
end
##
# Define an 'after' action. Inherits the way normal methods should.
#
# NOTE: +type+ is ignored and is only there to make porting easier.
#
# Equivalent to MiniTest::Unit::TestCase#teardown.

def self.after type = :each, &block
raise "unsupported after type: #{type}" unless type == :each
define_inheritable_method :teardown, &block
end

##
# Define an expectation with name +desc+. Name gets morphed to a
# proper test method name. For some freakish reason, people who
# write specs don't like class inheritence, so this goes way out of
# its way to make sure that expectations aren't inherited.
#
# Hint: If you _do_ want inheritence, use minitest/unit. You can mix
# and match between assertions and expectations as much as you want.

def self.it desc, &block
define_method "test_#{desc.gsub(/\W+/, '_').downcase}", &block
block ||= proc { skip "(no tests defined)" }

@specs ||= 0
@specs += 1

name = "test_%04d_%s" % [ @specs, desc.gsub(/\W+/, '_').downcase ]

define_method name, &block

classes(MiniTest::Spec).each do |mod|
mod.send :undef_method, name if mod.respond_to? name
end
end

##
# :method: must_be
# See MiniTest::Assertions#assert

##
# :method: must_be_close_to
# See MiniTest::Assertions#assert_in_delta

##
# :method: must_be_empty
# See MiniTest::Assertions#assert_empty

##
# :method: must_be_instance_of
# See MiniTest::Assertions#assert_instance_of

##
# :method: must_be_kind_of
# See MiniTest::Assertions#assert_kind_of

##
# :method: must_be_nil
# See MiniTest::Assertions#assert_nil

##
# :method: must_be_same_as
# See MiniTest::Assertions#assert_same

##
# :method: must_be_within_delta
# See MiniTest::Assertions#assert_in_delta

##
# :method: must_be_within_epsilon
# See MiniTest::Assertions#assert_in_epsilon

##
# :method: must_equal
# See MiniTest::Assertions#assert_equal

##
# :method: must_include
# See MiniTest::Assertions#assert_includes

##
# :method: must_match
# See MiniTest::Assertions#assert_match

##
# :method: must_raise
# See MiniTest::Assertions#assert_raises

##
# :method: must_respond_to
# See MiniTest::Assertions#assert_respond_to

##
# :method: must_send
# See MiniTest::Assertions#assert_send

##
# :method: must_throw
# See MiniTest::Assertions#assert_throw

##
# :method: wont_be
# See MiniTest::Assertions#refute

##
# :method: wont_be_close_to
# See MiniTest::Assertions#refute_in_delta

##
# :method: wont_be_empty
# See MiniTest::Assertions#refute_empty

##
# :method: wont_be_instance_of
# See MiniTest::Assertions#refute_instance_of

##
# :method: wont_be_kind_of
# See MiniTest::Assertions#refute_kind_of

##
# :method: wont_be_nil
# See MiniTest::Assertions#refute_nil

##
# :method: wont_be_same_as
# See MiniTest::Assertions#refute_same

##
# :method: wont_be_within_delta
# See MiniTest::Assertions#refute_in_delta

##
# :method: wont_be_within_epsilon
# See MiniTest::Assertions#refute_in_epsilon

##
# :method: wont_equal
# See MiniTest::Assertions#refute_equal

##
# :method: wont_include
# See MiniTest::Assertions#refute_includes

##
# :method: wont_match
# See MiniTest::Assertions#refute_match

##
# :method: wont_respond_to
# See MiniTest::Assertions#refute_respond_to
end
Loading

0 comments on commit 1392791

Please sign in to comment.