summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-19 20:34:21 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-19 20:34:21 +0000
commit9bec8ef50ce1858ee2070a1637447eb12ce89990 (patch)
treee6cece58a34cf857c56e47bab13a5eeacd71af71 /lib
parent9cfc7a658f1e6f97fd88ee69310f4ccc5f20d73c (diff)
Imported minitest 2.6.2 (r6712)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33487 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/minitest/README.txt19
-rw-r--r--lib/minitest/mock.rb2
-rw-r--r--lib/minitest/spec.rb20
-rw-r--r--lib/minitest/unit.rb49
4 files changed, 75 insertions, 15 deletions
diff --git a/lib/minitest/README.txt b/lib/minitest/README.txt
index 0595083d49..f55f7d9710 100644
--- a/lib/minitest/README.txt
+++ b/lib/minitest/README.txt
@@ -1,13 +1,25 @@
= minitest/{unit,spec,mock,benchmark}
home :: https://github.com/seattlerb/minitest
-rdoc :: http://bfts.rubyforge.org/minitest
+rdoc :: http://docs.seattlerb.org/minitest
+vim :: https://github.com/sunaku/vim-ruby-minitest
== DESCRIPTION:
minitest provides a complete suite of testing facilities supporting
TDD, BDD, mocking, and benchmarking.
+ "I had a class with Jim Weirich on testing last week and we were
+ allowed to choose our testing frameworks. Kirk Haines and I were
+ paired up and we cracked open the code for a few test
+ frameworks...
+
+ I MUST say that mintiest is *very* readable / understandable
+ compared to the 'other two' options we looked at. Nicely done and
+ thank you for helping us keep our mental sanity."
+
+ -- Wayne E. Seguin
+
minitest/unit is a small and incredibly fast unit testing framework.
It provides a rich set of assertions to make your tests clean and
readable.
@@ -32,6 +44,11 @@ implementors that need a minimal set of methods to bootstrap a working
test suite. For example, there is no magic involved for test-case
discovery.
+ "Again, I can’t praise enough the idea of a testing/specing
+ framework that I can actually read in full in one sitting!"
+
+ -- Piotr Szotkowski
+
== FEATURES/PROBLEMS:
* minitest/autorun - the easy and explicit way to run all your tests.
diff --git a/lib/minitest/mock.rb b/lib/minitest/mock.rb
index c342c04995..f46eb15a27 100644
--- a/lib/minitest/mock.rb
+++ b/lib/minitest/mock.rb
@@ -99,7 +99,7 @@ module MiniTest
end
def respond_to?(sym) # :nodoc:
- return true if @expected_calls.has_key?(sym)
+ return true if @expected_calls.has_key?(sym.to_sym)
return __respond_to?(sym)
end
end
diff --git a/lib/minitest/spec.rb b/lib/minitest/spec.rb
index a70bbdd405..c6b6777acf 100644
--- a/lib/minitest/spec.rb
+++ b/lib/minitest/spec.rb
@@ -192,10 +192,12 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
# write specs don't like class inheritence, so this goes way out of
# its way to make sure that expectations aren't inherited.
#
+ # This is also aliased to #specify and doesn't require a +desc+ arg.
+ #
# 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
+ def self.it desc = "anonymous", &block
block ||= proc { skip "(no tests defined)" }
@specs ||= 0
@@ -240,7 +242,9 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
# :stopdoc:
class << self
- attr_reader :name, :desc
+ attr_reader :desc
+ alias :specify :it
+ alias :name :to_s
end
# :startdoc:
end
@@ -334,9 +338,13 @@ module MiniTest::Expectations
#
# n.must_be :<=, 42
#
+ # This can also do predicates:
+ #
+ # str.must_be :empty?
+ #
# :method: must_be
- infect_an_assertion :assert_operator, :must_be
+ infect_an_assertion :assert_operator, :must_be, :reverse
##
# See MiniTest::Assertions#assert_output
@@ -491,9 +499,13 @@ module MiniTest::Expectations
#
# n.wont_be :<=, 42
#
+ # This can also do predicates:
+ #
+ # str.wont_be :empty?
+ #
# :method: wont_be
- infect_an_assertion :refute_operator, :wont_be
+ infect_an_assertion :refute_operator, :wont_be, :reverse
##
# See MiniTest::Assertions#refute_respond_to
diff --git a/lib/minitest/unit.rb b/lib/minitest/unit.rb
index 922ef70183..38e3f3a83e 100644
--- a/lib/minitest/unit.rb
+++ b/lib/minitest/unit.rb
@@ -24,7 +24,7 @@ module MiniTest
class Skip < Assertion; end
- file = if RUBY_VERSION =~ /^1\.9/ then # bt's expanded, but __FILE__ isn't :(
+ file = if RUBY_VERSION >= '1.9.0' then # bt's expanded, but __FILE__ isn't :(
File.expand_path __FILE__
elsif __FILE__ =~ /^[^\.]/ then # assume both relative
require 'pathname'
@@ -253,7 +253,7 @@ module MiniTest
end
##
- # Fails unless +obj+ is an instace of +cls+.
+ # Fails unless +obj+ is an instance of +cls+.
def assert_instance_of cls, obj, msg = nil
msg = message(msg) {
@@ -291,12 +291,16 @@ module MiniTest
assert obj.nil?, msg
end
+ UNDEFINED = Object.new
+ def UNDEFINED.inspect; "UNDEFINED"; end
+
##
- # For testing equality operators and so-forth.
+ # For testing with binary operators.
#
# assert_operator 5, :<=, 4
- def assert_operator o1, op, o2, msg = nil
+ def assert_operator o1, op, o2 = UNDEFINED, msg = nil
+ return assert_predicate o1, op, msg if UNDEFINED == o2
msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op} #{mu_pp(o2)}" }
assert o1.__send__(op, o2), msg
end
@@ -320,6 +324,20 @@ module MiniTest
end
##
+ # For testing with predicates.
+ #
+ # assert_predicate str, :empty?
+ #
+ # This is really meant for specs and is front-ended by assert_operator:
+ #
+ # str.must_be :empty?
+
+ def assert_predicate o1, op, msg = nil
+ msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op}" }
+ assert o1.__send__(op), msg
+ end
+
+ ##
# Fails unless the block raises one of +exp+
def assert_raises *exp
@@ -582,14 +600,27 @@ module MiniTest
# refute_operator 1, :>, 2 #=> pass
# refute_operator 1, :<, 2 #=> fail
- def refute_operator o1, op, o2, msg = nil
- msg = message(msg) {
- "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}"
- }
+ def refute_operator o1, op, o2 = UNDEFINED, msg = nil
+ return refute_predicate o1, op, msg if UNDEFINED == o2
+ msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}"}
refute o1.__send__(op, o2), msg
end
##
+ # For testing with predicates.
+ #
+ # refute_predicate str, :empty?
+ #
+ # This is really meant for specs and is front-ended by refute_operator:
+ #
+ # str.wont_be :empty?
+
+ def refute_predicate o1, op, msg = nil
+ msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op}" }
+ refute o1.__send__(op), msg
+ end
+
+ ##
# Fails if +obj+ responds to the message +meth+.
def refute_respond_to obj, meth, msg = nil
@@ -620,7 +651,7 @@ module MiniTest
end
class Unit
- VERSION = "2.5.1" # :nodoc:
+ VERSION = "2.6.1" # :nodoc:
attr_accessor :report, :failures, :errors, :skips # :nodoc:
attr_accessor :test_count, :assertion_count # :nodoc: