[前][次][番号順一覧][スレッド一覧]

ruby-changes:14418

From: ryan <ko1@a...>
Date: Thu, 7 Jan 2010 07:59:19 +0900 (JST)
Subject: [ruby-changes:14418] Ruby:r26247 (trunk): Imported minitest 1.5.0 r5596

ryan	2010-01-07 07:58:07 +0900 (Thu, 07 Jan 2010)

  New Revision: 26247

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26247

  Log:
    Imported minitest 1.5.0 r5596

  Modified files:
    trunk/ChangeLog
    trunk/lib/minitest/spec.rb
    trunk/lib/minitest/unit.rb
    trunk/test/minitest/test_mini_test.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26246)
+++ ChangeLog	(revision 26247)
@@ -1,3 +1,8 @@
+Thu Jan  7 07:56:09 2010  Ryan Davis  <ryand-ruby@z...>
+
+	* lib/minitest/*.rb: Imported minitest 1.5.0 r5596.
+	* test/minitest/*.rb: ditto.
+
 Tue Jan  5 19:30:53 2010  Kazuhiro NISHIYAMA  <zn@m...>
 
 	* test/ruby/test_exception.rb: add a test. cf [ruby-dev:39116]
@@ -50496,7 +50501,7 @@
 	* lib/mkmf.rb (create_makefile): prevent substitution of macro
 	  definition.  fixed: http://www.yotabanana.com/lab/20060624.html#p02
 
-Sun Jul  9 07:58:48 2006  Ryan Davis  <ryand@z...>
+Sun Jul  9 07:58:48 2006  Ryan Davis  <ryand-ruby@z...>
 
 	* lib/rdoc/parsers/parse_f95.rb: massive overhaul from Yasuhiro
 	  Morikawa including new file suffixes, function support, public
@@ -65904,7 +65909,7 @@
 	* struct.c (rb_struct_s_def): Struct::new executes block with
 	  generated struct class. [ruby-talk:02606]
 
-Wed Mar 10 15:58:43 2004  Ryan Davis  <ryand@z...>
+Wed Mar 10 15:58:43 2004  Ryan Davis  <ryand-ruby@z...>
 
 	* eval.c (eval): Only print backtrace if generating the backtrace
 	  doesn't generate an exception.  [ruby-core:02621]
Index: lib/minitest/unit.rb
===================================================================
--- lib/minitest/unit.rb	(revision 26246)
+++ lib/minitest/unit.rb	(revision 26247)
@@ -95,25 +95,25 @@
     end
 
     def assert_includes collection, obj, msg = nil
-      msg = message(msg) { "Expected #{mu_pp(collection)} to include #{mu_pp(obj)}" }
-      flip = (obj.respond_to? :include?) && ! (collection.respond_to? :include?) # HACK for specs
-      obj, collection = collection, obj if flip
+      msg = message(msg) {
+        "Expected #{mu_pp(collection)} to include #{mu_pp(obj)}"
+      }
       assert_respond_to collection, :include?
       assert collection.include?(obj), msg
     end
 
     def assert_instance_of cls, obj, msg = nil
-      msg = message(msg) { "Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}" }
-      flip = (Module === obj) && ! (Module === cls) # HACK for specs
-      obj, cls = cls, obj if flip
+      msg = message(msg) {
+        "Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}"
+      }
+
       assert obj.instance_of?(cls), msg
     end
 
     def assert_kind_of cls, obj, msg = nil # TODO: merge with instance_of
       msg = message(msg) {
         "Expected #{mu_pp(obj)} to be a kind of #{cls}, not #{obj.class}" }
-      flip = (Module === obj) && ! (Module === cls) # HACK for specs
-      obj, cls = cls, obj if flip
+
       assert obj.kind_of?(cls), msg
     end
 
@@ -136,28 +136,29 @@
 
     def assert_raises *exp
       msg = String === exp.last ? exp.pop : nil
+      msg = msg.to_s + "\n" if msg
       should_raise = false
       begin
         yield
         should_raise = true
       rescue Exception => e
+        details = "#{msg}#{mu_pp(exp)} exception expected, not"
         assert(exp.any? { |ex|
                  ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
-               }, exception_details(e, "#{mu_pp(exp)} exception expected, not"))
+               }, exception_details(e, details))
 
         return e
       end
 
       exp = exp.first if exp.size == 1
-      flunk "#{mu_pp(exp)} expected but nothing was raised." if should_raise
+      flunk "#{msg}#{mu_pp(exp)} expected but nothing was raised." if
+        should_raise
     end
 
     def assert_respond_to obj, meth, msg = nil
       msg = message(msg) {
           "Expected #{mu_pp(obj)} (#{obj.class}) to respond to ##{meth}"
         }
-      flip = (Symbol === obj) && ! (Symbol === meth) # HACK for specs
-      obj, meth = meth, obj if flip
       assert obj.respond_to?(meth), msg
     end
 
@@ -247,13 +248,17 @@
     end
 
     def refute_equal exp, act, msg = nil
-      msg = message(msg) { "Expected #{mu_pp(act)} to not be equal to #{mu_pp(exp)}" }
+      msg = message(msg) {
+        "Expected #{mu_pp(act)} to not be equal to #{mu_pp(exp)}"
+      }
       refute exp == act, msg
     end
 
     def refute_in_delta exp, act, delta = 0.001, msg = nil
       n = (exp - act).abs
-      msg = message(msg) { "Expected #{exp} - #{act} (#{n}) to not be < #{delta}" }
+      msg = message(msg) {
+        "Expected #{exp} - #{act} (#{n}) to not be < #{delta}"
+      }
       refute delta > n, msg
     end
 
@@ -262,24 +267,22 @@
     end
 
     def refute_includes collection, obj, msg = nil
-      msg = message(msg) { "Expected #{mu_pp(collection)} to not include #{mu_pp(obj)}" }
-      flip = (obj.respond_to? :include?) && ! (collection.respond_to? :include?) # HACK for specs
-      obj, collection = collection, obj if flip
+      msg = message(msg) {
+        "Expected #{mu_pp(collection)} to not include #{mu_pp(obj)}"
+      }
       assert_respond_to collection, :include?
       refute collection.include?(obj), msg
     end
 
     def refute_instance_of cls, obj, msg = nil
-      msg = message(msg) { "Expected #{mu_pp(obj)} to not be an instance of #{cls}" }
-      flip = (Module === obj) && ! (Module === cls) # HACK for specs
-      obj, cls = cls, obj if flip
+      msg = message(msg) {
+        "Expected #{mu_pp(obj)} to not be an instance of #{cls}"
+      }
       refute obj.instance_of?(cls), msg
     end
 
     def refute_kind_of cls, obj, msg = nil # TODO: merge with instance_of
       msg = message(msg) { "Expected #{mu_pp(obj)} to not be a kind of #{cls}" }
-      flip = (Module === obj) && ! (Module === cls) # HACK for specs
-      obj, cls = cls, obj if flip
       refute obj.kind_of?(cls), msg
     end
 
@@ -296,19 +299,22 @@
     end
 
     def refute_operator o1, op, o2, msg = nil
-      msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}" }
+      msg = message(msg) {
+        "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}"
+      }
       refute o1.__send__(op, o2), msg
     end
 
     def refute_respond_to obj, meth, msg = nil
       msg = message(msg) { "Expected #{mu_pp(obj)} to not respond to #{meth}" }
-      flip = (Symbol === obj) && ! (Symbol === meth) # HACK for specs
-      obj, meth = meth, obj if flip
+
       refute obj.respond_to?(meth), msg
     end
 
     def refute_same exp, act, msg = nil
-      msg = message(msg) { "Expected #{mu_pp(act)} to not be the same as #{mu_pp(exp)}" }
+      msg = message(msg) {
+        "Expected #{mu_pp(act)} to not be the same as #{mu_pp(exp)}"
+      }
       refute exp.equal?(act), msg
     end
 
@@ -319,7 +325,7 @@
   end
 
   class Unit
-    VERSION = "1.4.2"
+    VERSION = "1.5.0"
 
     attr_accessor :report, :failures, :errors, :skips
     attr_accessor :test_count, :assertion_count
@@ -520,8 +526,8 @@
 
       include MiniTest::Assertions
     end # class TestCase
-  end # class Test
-end # module Mini
+  end # class Unit
+end # module MiniTest
 
 if $DEBUG then
   # this helps me ferret out porting issues
Index: lib/minitest/spec.rb
===================================================================
--- lib/minitest/spec.rb	(revision 26246)
+++ lib/minitest/spec.rb	(revision 26247)
@@ -9,7 +9,23 @@
 require 'minitest/unit'
 
 class Module
-  def infect_with_assertions pos_prefix, neg_prefix, skip_re, map = {}
+  def infect_an_assertion meth, new_name, dont_flip = false
+    # warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
+    self.class_eval <<-EOM
+      def #{new_name} *args, &block
+        return MiniTest::Spec.current.#{meth}(*args, &self) if
+          Proc === self
+        return MiniTest::Spec.current.#{meth}(args.first, self) if
+          args.size == 1 unless #{!!dont_flip}
+        return MiniTest::Spec.current.#{meth}(self, *args)
+      end
+    EOM
+  end
+
+  def infect_with_assertions(pos_prefix, neg_prefix,
+                             skip_re,
+                             dont_flip_re = /\c0/,
+                             map = {})
     MiniTest::Assertions.public_instance_methods(false).each do |meth|
       meth = meth.to_s
 
@@ -25,14 +41,7 @@
       regexp, replacement = map.find { |re, _| new_name =~ re }
       new_name.sub! regexp, replacement if replacement
 
-      # warn "%-22p -> %p %p" % [meth, new_name, regexp]
-      self.class_eval <<-EOM
-        def #{new_name} *args, &block
-          return MiniTest::Spec.current.#{meth}(*args, &self)     if Proc === self
-          return MiniTest::Spec.current.#{meth}(args.first, self) if args.size == 1
-          return MiniTest::Spec.current.#{meth}(self, *args)
-        end
-      EOM
+      infect_an_assertion meth, new_name, new_name =~ dont_flip_re
     end
   end
 end
@@ -40,6 +49,7 @@
 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_',
@@ -57,7 +67,9 @@
   def describe desc, &block
     stack = MiniTest::Spec.describe_stack
     name  = desc.to_s.split(/\W+/).map { |s| s.capitalize }.join + "Spec"
-    cls   = Object.class_eval "class #{name} < #{stack.last}; end; #{name}"
+    prev  = stack.last
+    name  = "#{prev == MiniTest::Spec ? nil : prev}::#{name}"
+    cls   = Object.class_eval "class #{name} < #{prev}; end; #{name}"
 
     cls.nuke_test_methods!
 
@@ -85,7 +97,7 @@
 
   def self.nuke_test_methods!
     self.public_instance_methods.grep(/^test_/).each do |name|
-      send :remove_method, name rescue nil
+      self.send :undef_method, name
     end
   end
 
@@ -99,11 +111,19 @@
   end
 
   def self.before(type = :each, &block)
+    if type == :all
+      warn "change before :all to before :each"
+      type = :each
+    end
     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
     raise "unsupported after type: #{type}" unless type == :each
     define_inheritable_method :teardown, &block
   end
Index: test/minitest/test_mini_test.rb
===================================================================
--- test/minitest/test_mini_test.rb	(revision 26246)
+++ test/minitest/test_mini_test.rb	(revision 26247)
@@ -616,6 +616,27 @@
     assert_equal expected, actual
   end
 
+  def test_assert_raises_triggered_different_msg
+    e = assert_raises MiniTest::Assertion do
+      @tc.assert_raises RuntimeError, "XXX" do
+        raise SyntaxError, "icky"
+      end
+    end
+
+    expected = "XXX
+[RuntimeError] exception expected, not
+Class: <SyntaxError>
+Message: <\"icky\">
+---Backtrace---
+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/
+
+    assert_equal expected, actual
+  end
+
   def test_assert_raises_triggered_none
     e = assert_raises MiniTest::Assertion do
       @tc.assert_raises MiniTest::Assertion do
@@ -628,6 +649,18 @@
     assert_equal expected, e.message
   end
 
+  def test_assert_raises_triggered_none_msg
+    e = assert_raises MiniTest::Assertion do
+      @tc.assert_raises MiniTest::Assertion, "XXX" do
+        # do nothing
+      end
+    end
+
+    expected = "XXX\nMiniTest::Assertion expected but nothing was raised."
+
+    assert_equal expected, e.message
+  end
+
   def test_assert_raises_triggered_subclass
     e = assert_raises MiniTest::Assertion do
       @tc.assert_raises StandardError do

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]