diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/minitest/README.txt | 19 | ||||
-rw-r--r-- | lib/minitest/mock.rb | 2 | ||||
-rw-r--r-- | lib/minitest/spec.rb | 20 | ||||
-rw-r--r-- | lib/minitest/unit.rb | 49 | ||||
-rw-r--r-- | test/minitest/test_minitest_mock.rb | 1 | ||||
-rw-r--r-- | test/minitest/test_minitest_spec.rb | 25 | ||||
-rw-r--r-- | test/minitest/test_minitest_unit.rb | 22 |
8 files changed, 119 insertions, 24 deletions
@@ -1,3 +1,8 @@ +Thu Oct 20 05:13:39 2011 Ryan Davis <ryan@lust.zenspider.com> + + * lib/minitest/*: Imported minitest 2.6.2 (r6712) + * test/minitest/*: ditto + Thu Oct 20 06:55:32 2011 Martin Bosslet <Martin.Bosslet@googlemail.com> * lib/openssl/buffering.rb: Force multi-byte strings to be treated as 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: diff --git a/test/minitest/test_minitest_mock.rb b/test/minitest/test_minitest_mock.rb index b6e801c3aa..8ba29840d4 100644 --- a/test/minitest/test_minitest_mock.rb +++ b/test/minitest/test_minitest_mock.rb @@ -91,6 +91,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase def test_respond_appropriately assert @mock.respond_to?(:foo) + assert @mock.respond_to?('foo') assert !@mock.respond_to?(:bar) end diff --git a/test/minitest/test_minitest_spec.rb b/test/minitest/test_minitest_spec.rb index d9f6368a80..27e3dc7628 100644 --- a/test/minitest/test_minitest_spec.rb +++ b/test/minitest/test_minitest_spec.rb @@ -95,11 +95,16 @@ describe MiniTest::Spec do proc { 42.must_be_nil }.must_raise MiniTest::Assertion end - it "needs to verify using any operator" do + it "needs to verify using any binary operator" do 41.must_be(:<, 42).must_equal true proc { 42.must_be(:<, 41) }.must_raise MiniTest::Assertion end + it "needs to verify using any predicate" do + "".must_be(:empty?).must_equal true + proc { "blah".must_be(:empty?) }.must_raise MiniTest::Assertion + end + it "needs to catch an expected exception" do @assertion_count = 2 @@ -156,6 +161,11 @@ describe MiniTest::Spec do proc { "blah".wont_match(/\w+/) }.must_raise MiniTest::Assertion end + it "needs to verify using any (negative) predicate" do + "blah".wont_be(:empty?).must_equal false + proc { "".wont_be(:empty?) }.must_raise MiniTest::Assertion + end + it "needs to verify non-nil" do 42.wont_be_nil.must_equal false proc { nil.wont_be_nil }.must_raise MiniTest::Assertion @@ -277,6 +287,9 @@ class TestMeta < MiniTest::Unit::TestCase before { before_list << 3 } after { after_list << 3 } it "inner-it" do end + + it {} # ignore me + specify {} # anonymous it end end end @@ -328,11 +341,13 @@ class TestMeta < MiniTest::Unit::TestCase assert_equal "very inner thingy", z.desc top_methods = %w(test_0001_top_level_it) - inner_methods = %w(test_0001_inner_it) + inner_methods1 = %w(test_0001_inner_it) + inner_methods2 = inner_methods1 + + %w(test_0002_anonymous test_0003_anonymous) - assert_equal top_methods, x.instance_methods(false).sort.map {|o| o.to_s } - assert_equal inner_methods, y.instance_methods(false).sort.map {|o| o.to_s } - assert_equal inner_methods, z.instance_methods(false).sort.map {|o| o.to_s } + assert_equal top_methods, x.instance_methods(false).sort.map(&:to_s) + assert_equal inner_methods1, y.instance_methods(false).sort.map(&:to_s) + assert_equal inner_methods2, z.instance_methods(false).sort.map(&:to_s) end def test_setup_teardown_behavior diff --git a/test/minitest/test_minitest_unit.rb b/test/minitest/test_minitest_unit.rb index c921ca749e..39e44a33d8 100644 --- a/test/minitest/test_minitest_unit.rb +++ b/test/minitest/test_minitest_unit.rb @@ -587,7 +587,7 @@ Finished tests in 0.00 end def util_expand_bt bt - if RUBY_VERSION =~ /^1\.9/ then + if RUBY_VERSION >= '1.9.0' then bt.map { |f| (f =~ /^\./) ? File.expand_path(f) : f } else bt @@ -883,6 +883,13 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase @tc.assert_operator 2, :>, 1 end + def test_assert_operator_bad_object + bad = Object.new + def bad.==(other) true end + + @tc.assert_operator bad, :equal?, bad + end + def test_assert_operator_triggered util_assert_triggered "Expected 2 to be < 1." do @tc.assert_operator 2, :<, 1 @@ -990,7 +997,7 @@ FILE:LINE:in `test_assert_raises_triggered_different' ---------------" actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE') - actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/ + actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION >= '1.9.0' assert_equal expected, actual end @@ -1011,7 +1018,7 @@ FILE:LINE:in `test_assert_raises_triggered_different_msg' ---------------" actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE') - actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/ + actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION >= '1.9.0' assert_equal expected, actual end @@ -1055,7 +1062,7 @@ FILE:LINE:in `test_assert_raises_triggered_subclass' ---------------" actual = e.message.gsub(/^.+:\d+/, 'FILE:LINE') - actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION =~ /^1\.9/ + actual.gsub!(/block \(\d+ levels\) in /, '') if RUBY_VERSION >= '1.9.0' assert_equal expected, actual end @@ -1364,6 +1371,13 @@ FILE:LINE:in `test_assert_raises_triggered_subclass' @tc.refute_operator 2, :<, 1 end + def test_refute_operator_bad_object + bad = Object.new + def bad.==(other) true end + + @tc.refute_operator true, :equal?, bad + end + def test_refute_operator_triggered util_assert_triggered "Expected 2 to not be > 1." do @tc.refute_operator 2, :>, 1 |