ruby-changes:21438
From: ryan <ko1@a...>
Date: Thu, 20 Oct 2011 05:34:36 +0900 (JST)
Subject: [ruby-changes:21438] ryan:r33487 (trunk): Imported minitest 2.6.2 (r6712)
ryan 2011-10-20 05:34:21 +0900 (Thu, 20 Oct 2011) New Revision: 33487 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33487 Log: Imported minitest 2.6.2 (r6712) Modified files: trunk/ChangeLog trunk/lib/minitest/README.txt trunk/lib/minitest/mock.rb trunk/lib/minitest/spec.rb trunk/lib/minitest/unit.rb trunk/test/minitest/test_minitest_mock.rb trunk/test/minitest/test_minitest_spec.rb trunk/test/minitest/test_minitest_unit.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 33486) +++ ChangeLog (revision 33487) @@ -1,3 +1,8 @@ +Thu Oct 20 05:13:39 2011 Ryan Davis <ryan@l...> + + * lib/minitest/*: Imported minitest 2.6.2 (r6712) + * test/minitest/*: ditto + Thu Oct 20 06:55:32 2011 Martin Bosslet <Martin.Bosslet@g...> * lib/openssl/buffering.rb: Force multi-byte strings to be treated as Index: lib/minitest/unit.rb =================================================================== --- lib/minitest/unit.rb (revision 33486) +++ lib/minitest/unit.rb (revision 33487) @@ -24,7 +24,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ # 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 @@ 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: Index: lib/minitest/README.txt =================================================================== --- lib/minitest/README.txt (revision 33486) +++ lib/minitest/README.txt (revision 33487) @@ -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 @@ test suite. For example, there is no magic involved for test-case discovery. + "Again, I can 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. Index: lib/minitest/mock.rb =================================================================== --- lib/minitest/mock.rb (revision 33486) +++ lib/minitest/mock.rb (revision 33487) @@ -99,7 +99,7 @@ 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 Index: lib/minitest/spec.rb =================================================================== --- lib/minitest/spec.rb (revision 33486) +++ lib/minitest/spec.rb (revision 33487) @@ -192,10 +192,12 @@ # 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 @@ # :stopdoc: class << self - attr_reader :name, :desc + attr_reader :desc + alias :specify :it + alias :name :to_s end # :startdoc: end @@ -334,9 +338,13 @@ # # 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 @@ # # 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 Index: test/minitest/test_minitest_mock.rb =================================================================== --- test/minitest/test_minitest_mock.rb (revision 33486) +++ test/minitest/test_minitest_mock.rb (revision 33487) @@ -91,6 +91,7 @@ def test_respond_appropriately assert @mock.respond_to?(:foo) + assert @mock.respond_to?('foo') assert !@mock.respond_to?(:bar) end Index: test/minitest/test_minitest_spec.rb =================================================================== --- test/minitest/test_minitest_spec.rb (revision 33486) +++ test/minitest/test_minitest_spec.rb (revision 33487) @@ -95,11 +95,16 @@ 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 @@ 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 @@ 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 @@ 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 Index: test/minitest/test_minitest_unit.rb =================================================================== --- test/minitest/test_minitest_unit.rb (revision 33486) +++ test/minitest/test_minitest_unit.rb (revision 33487) @@ -587,7 +587,7 @@ 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 @@ @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 @@ ---------------" 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 @@ ---------------" 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 @@ ---------------" 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 @@ @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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/