mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* test/lib/minitest/spec.rb: Unused file removed.
* test/lib/minitest/autorun.rb: Don't require minitest/spec. * test/lib/minitest/benchmark.rb: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									4edc1c07a4
								
							
						
					
					
						commit
						1e2374f1e9
					
				
					 5 changed files with 8 additions and 1352 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,11 @@
 | 
			
		|||
Sat May 24 19:08:47 2014  Tanaka Akira  <akr@fsij.org>
 | 
			
		||||
 | 
			
		||||
	* test/lib/minitest/spec.rb: Unused file removed.
 | 
			
		||||
 | 
			
		||||
	* test/lib/minitest/autorun.rb: Don't require minitest/spec.
 | 
			
		||||
 | 
			
		||||
	* test/lib/minitest/benchmark.rb: Ditto.
 | 
			
		||||
 | 
			
		||||
Sat May 24 18:45:30 2014  Tanaka Akira  <akr@fsij.org>
 | 
			
		||||
 | 
			
		||||
	* test/benchmark/test_benchmark.rb: Use test/unit.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,6 @@ rescue Gem::LoadError
 | 
			
		|||
end
 | 
			
		||||
 | 
			
		||||
require 'minitest/unit'
 | 
			
		||||
require 'minitest/spec'
 | 
			
		||||
require 'minitest/mock'
 | 
			
		||||
 | 
			
		||||
MiniTest::Unit.autorun
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,6 @@
 | 
			
		|||
# encoding: utf-8
 | 
			
		||||
 | 
			
		||||
require 'minitest/unit'
 | 
			
		||||
require 'minitest/spec'
 | 
			
		||||
 | 
			
		||||
class MiniTest::Unit # :nodoc:
 | 
			
		||||
  def run_benchmarks # :nodoc:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,546 +0,0 @@
 | 
			
		|||
# encoding: utf-8
 | 
			
		||||
 | 
			
		||||
#!/usr/bin/ruby -w
 | 
			
		||||
 | 
			
		||||
require 'minitest/unit'
 | 
			
		||||
 | 
			
		||||
class Module # :nodoc:
 | 
			
		||||
  def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:
 | 
			
		||||
    # warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
 | 
			
		||||
    self.class_eval <<-EOM
 | 
			
		||||
      def #{new_name} *args
 | 
			
		||||
        case
 | 
			
		||||
        when Proc === self then
 | 
			
		||||
          MiniTest::Spec.current.#{meth}(*args, &self)
 | 
			
		||||
        when #{!!dont_flip} then
 | 
			
		||||
          MiniTest::Spec.current.#{meth}(self, *args)
 | 
			
		||||
        else
 | 
			
		||||
          MiniTest::Spec.current.#{meth}(args.first, self, *args[1..-1])
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    EOM
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # infect_with_assertions has been removed due to excessive clever.
 | 
			
		||||
  # Use infect_an_assertion directly instead.
 | 
			
		||||
 | 
			
		||||
  def infect_with_assertions(pos_prefix, neg_prefix,
 | 
			
		||||
                             skip_re,
 | 
			
		||||
                             dont_flip_re = /\c0/,
 | 
			
		||||
                             map = {})
 | 
			
		||||
    abort "infect_with_assertions is dead. Use infect_an_assertion directly"
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
module Kernel # :nodoc:
 | 
			
		||||
  ##
 | 
			
		||||
  # Describe a series of expectations for a given target +desc+.
 | 
			
		||||
  #
 | 
			
		||||
  # TODO: find good tutorial url.
 | 
			
		||||
  #
 | 
			
		||||
  # Defines a test class subclassing from either MiniTest::Spec or
 | 
			
		||||
  # from the surrounding describe's class. The surrounding class may
 | 
			
		||||
  # subclass MiniTest::Spec manually in order to easily share code:
 | 
			
		||||
  #
 | 
			
		||||
  #     class MySpec < MiniTest::Spec
 | 
			
		||||
  #       # ... shared code ...
 | 
			
		||||
  #     end
 | 
			
		||||
  #
 | 
			
		||||
  #     class TestStuff < MySpec
 | 
			
		||||
  #       it "does stuff" do
 | 
			
		||||
  #         # shared code available here
 | 
			
		||||
  #       end
 | 
			
		||||
  #       describe "inner stuff" do
 | 
			
		||||
  #         it "still does stuff" do
 | 
			
		||||
  #           # ...and here
 | 
			
		||||
  #         end
 | 
			
		||||
  #       end
 | 
			
		||||
  #     end
 | 
			
		||||
 | 
			
		||||
  def describe desc, additional_desc = nil, &block # :doc:
 | 
			
		||||
    stack = MiniTest::Spec.describe_stack
 | 
			
		||||
    name  = [stack.last, desc, additional_desc].compact.join("::")
 | 
			
		||||
    sclas = stack.last || if Class === self && is_a?(MiniTest::Spec::DSL) then
 | 
			
		||||
                            self
 | 
			
		||||
                          else
 | 
			
		||||
                            MiniTest::Spec.spec_type desc
 | 
			
		||||
                          end
 | 
			
		||||
 | 
			
		||||
    cls = sclas.create name, desc
 | 
			
		||||
 | 
			
		||||
    stack.push cls
 | 
			
		||||
    cls.class_eval(&block)
 | 
			
		||||
    stack.pop
 | 
			
		||||
    cls
 | 
			
		||||
  end
 | 
			
		||||
  private :describe
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
##
 | 
			
		||||
# MiniTest::Spec -- The faster, better, less-magical spec framework!
 | 
			
		||||
#
 | 
			
		||||
# For a list of expectations, see MiniTest::Expectations.
 | 
			
		||||
 | 
			
		||||
class MiniTest::Spec < MiniTest::Unit::TestCase
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # Oh look! A MiniTest::Spec::DSL module! Eat your heart out DHH.
 | 
			
		||||
 | 
			
		||||
  module DSL
 | 
			
		||||
    ##
 | 
			
		||||
    # Contains pairs of matchers and Spec classes to be used to
 | 
			
		||||
    # calculate the superclass of a top-level describe. This allows for
 | 
			
		||||
    # automatically customizable spec types.
 | 
			
		||||
    #
 | 
			
		||||
    # See: register_spec_type and spec_type
 | 
			
		||||
 | 
			
		||||
    TYPES = [[//, MiniTest::Spec]]
 | 
			
		||||
 | 
			
		||||
    ##
 | 
			
		||||
    # Register a new type of spec that matches the spec's description.
 | 
			
		||||
    # This method can take either a Regexp and a spec class or a spec
 | 
			
		||||
    # class and a block that takes the description and returns true if
 | 
			
		||||
    # it matches.
 | 
			
		||||
    #
 | 
			
		||||
    # Eg:
 | 
			
		||||
    #
 | 
			
		||||
    #     register_spec_type(/Controller$/, MiniTest::Spec::Rails)
 | 
			
		||||
    #
 | 
			
		||||
    # or:
 | 
			
		||||
    #
 | 
			
		||||
    #     register_spec_type(MiniTest::Spec::RailsModel) do |desc|
 | 
			
		||||
    #       desc.superclass == ActiveRecord::Base
 | 
			
		||||
    #     end
 | 
			
		||||
 | 
			
		||||
    def register_spec_type(*args, &block)
 | 
			
		||||
      if block then
 | 
			
		||||
        matcher, klass = block, args.first
 | 
			
		||||
      else
 | 
			
		||||
        matcher, klass = *args
 | 
			
		||||
      end
 | 
			
		||||
      TYPES.unshift [matcher, klass]
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    ##
 | 
			
		||||
    # Figure out the spec class to use based on a spec's description. Eg:
 | 
			
		||||
    #
 | 
			
		||||
    #     spec_type("BlahController") # => MiniTest::Spec::Rails
 | 
			
		||||
 | 
			
		||||
    def spec_type desc
 | 
			
		||||
      TYPES.find { |matcher, klass|
 | 
			
		||||
        if matcher.respond_to? :call then
 | 
			
		||||
          matcher.call desc
 | 
			
		||||
        else
 | 
			
		||||
          matcher === desc.to_s
 | 
			
		||||
        end
 | 
			
		||||
      }.last
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def describe_stack # :nodoc:
 | 
			
		||||
      Thread.current[:describe_stack] ||= []
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    ##
 | 
			
		||||
    # Returns the children of this spec.
 | 
			
		||||
 | 
			
		||||
    def children
 | 
			
		||||
      @children ||= []
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def nuke_test_methods! # :nodoc:
 | 
			
		||||
      self.public_instance_methods.grep(/^test_/).each do |name|
 | 
			
		||||
        self.send :undef_method, name
 | 
			
		||||
      end
 | 
			
		||||
    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 before type = nil, &block
 | 
			
		||||
      define_method :setup do
 | 
			
		||||
        super()
 | 
			
		||||
        self.instance_eval(&block)
 | 
			
		||||
      end
 | 
			
		||||
    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 after type = nil, &block
 | 
			
		||||
      define_method :teardown do
 | 
			
		||||
        self.instance_eval(&block)
 | 
			
		||||
        super()
 | 
			
		||||
      end
 | 
			
		||||
    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 inheritance, 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 it desc = "anonymous", &block
 | 
			
		||||
      block ||= proc { skip "(no tests defined)" }
 | 
			
		||||
 | 
			
		||||
      @specs ||= 0
 | 
			
		||||
      @specs += 1
 | 
			
		||||
 | 
			
		||||
      name = "test_%04d_%s" % [ @specs, desc ]
 | 
			
		||||
 | 
			
		||||
      define_method name, &block
 | 
			
		||||
 | 
			
		||||
      self.children.each do |mod|
 | 
			
		||||
        mod.send :undef_method, name if mod.public_method_defined? name
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      name
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    ##
 | 
			
		||||
    # Essentially, define an accessor for +name+ with +block+.
 | 
			
		||||
    #
 | 
			
		||||
    # Why use let instead of def? I honestly don't know.
 | 
			
		||||
 | 
			
		||||
    def let name, &block
 | 
			
		||||
      define_method name do
 | 
			
		||||
        @_memoized ||= {}
 | 
			
		||||
        @_memoized.fetch(name) { |k| @_memoized[k] = instance_eval(&block) }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    ##
 | 
			
		||||
    # Another lazy man's accessor generator. Made even more lazy by
 | 
			
		||||
    # setting the name for you to +subject+.
 | 
			
		||||
 | 
			
		||||
    def subject &block
 | 
			
		||||
      let :subject, &block
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def create name, desc # :nodoc:
 | 
			
		||||
      cls = Class.new(self) do
 | 
			
		||||
        @name = name
 | 
			
		||||
        @desc = desc
 | 
			
		||||
 | 
			
		||||
        nuke_test_methods!
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      children << cls
 | 
			
		||||
 | 
			
		||||
      cls
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def name # :nodoc:
 | 
			
		||||
      defined?(@name) ? @name : super
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def to_s # :nodoc:
 | 
			
		||||
      name # Can't alias due to 1.8.7, not sure why
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # :stopdoc:
 | 
			
		||||
    attr_reader :desc
 | 
			
		||||
    alias :specify :it
 | 
			
		||||
    # :startdoc:
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  extend DSL
 | 
			
		||||
 | 
			
		||||
  TYPES = DSL::TYPES # :nodoc:
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
##
 | 
			
		||||
# It's where you hide your "assertions".
 | 
			
		||||
 | 
			
		||||
module MiniTest::Expectations
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_empty.
 | 
			
		||||
  #
 | 
			
		||||
  #    collection.must_be_empty
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_be_empty
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_empty, :must_be_empty, :unary
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_equal
 | 
			
		||||
  #
 | 
			
		||||
  #    a.must_equal b
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_equal
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_equal, :must_equal
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_in_delta
 | 
			
		||||
  #
 | 
			
		||||
  #    n.must_be_close_to m [, delta]
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_be_close_to
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_in_delta, :must_be_close_to
 | 
			
		||||
 | 
			
		||||
  alias :must_be_within_delta :must_be_close_to # :nodoc:
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_in_epsilon
 | 
			
		||||
  #
 | 
			
		||||
  #    n.must_be_within_epsilon m [, epsilon]
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_be_within_epsilon
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_in_epsilon, :must_be_within_epsilon
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_includes
 | 
			
		||||
  #
 | 
			
		||||
  #    collection.must_include obj
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_include
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_includes, :must_include, :reverse
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_instance_of
 | 
			
		||||
  #
 | 
			
		||||
  #    obj.must_be_instance_of klass
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_be_instance_of
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_instance_of, :must_be_instance_of
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_kind_of
 | 
			
		||||
  #
 | 
			
		||||
  #    obj.must_be_kind_of mod
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_be_kind_of
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_kind_of, :must_be_kind_of
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_match
 | 
			
		||||
  #
 | 
			
		||||
  #    a.must_match b
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_match
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_match, :must_match
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_nil
 | 
			
		||||
  #
 | 
			
		||||
  #    obj.must_be_nil
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_be_nil
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_nil, :must_be_nil, :unary
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_operator
 | 
			
		||||
  #
 | 
			
		||||
  #    n.must_be :<=, 42
 | 
			
		||||
  #
 | 
			
		||||
  # This can also do predicates:
 | 
			
		||||
  #
 | 
			
		||||
  #    str.must_be :empty?
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_be
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_operator, :must_be, :reverse
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_output
 | 
			
		||||
  #
 | 
			
		||||
  #    proc { ... }.must_output out_or_nil [, err]
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_output
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_output, :must_output
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_raises
 | 
			
		||||
  #
 | 
			
		||||
  #    proc { ... }.must_raise exception
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_raise
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_raises, :must_raise
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_respond_to
 | 
			
		||||
  #
 | 
			
		||||
  #    obj.must_respond_to msg
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_respond_to
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_respond_to, :must_respond_to, :reverse
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_same
 | 
			
		||||
  #
 | 
			
		||||
  #    a.must_be_same_as b
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_be_same_as
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_same, :must_be_same_as
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_send
 | 
			
		||||
  # TODO: remove me
 | 
			
		||||
  #
 | 
			
		||||
  #    a.must_send
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_send
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_send, :must_send
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_silent
 | 
			
		||||
  #
 | 
			
		||||
  #    proc { ... }.must_be_silent
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_be_silent
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_silent, :must_be_silent
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#assert_throws
 | 
			
		||||
  #
 | 
			
		||||
  #    proc { ... }.must_throw sym
 | 
			
		||||
  #
 | 
			
		||||
  # :method: must_throw
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :assert_throws, :must_throw
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_empty
 | 
			
		||||
  #
 | 
			
		||||
  #    collection.wont_be_empty
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_be_empty
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_empty, :wont_be_empty, :unary
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_equal
 | 
			
		||||
  #
 | 
			
		||||
  #    a.wont_equal b
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_equal
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_equal, :wont_equal
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_in_delta
 | 
			
		||||
  #
 | 
			
		||||
  #    n.wont_be_close_to m [, delta]
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_be_close_to
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_in_delta, :wont_be_close_to
 | 
			
		||||
 | 
			
		||||
  alias :wont_be_within_delta :wont_be_close_to # :nodoc:
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_in_epsilon
 | 
			
		||||
  #
 | 
			
		||||
  #    n.wont_be_within_epsilon m [, epsilon]
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_be_within_epsilon
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_in_epsilon, :wont_be_within_epsilon
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_includes
 | 
			
		||||
  #
 | 
			
		||||
  #    collection.wont_include obj
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_include
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_includes, :wont_include, :reverse
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_instance_of
 | 
			
		||||
  #
 | 
			
		||||
  #    obj.wont_be_instance_of klass
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_be_instance_of
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_instance_of, :wont_be_instance_of
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_kind_of
 | 
			
		||||
  #
 | 
			
		||||
  #    obj.wont_be_kind_of mod
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_be_kind_of
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_kind_of, :wont_be_kind_of
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_match
 | 
			
		||||
  #
 | 
			
		||||
  #    a.wont_match b
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_match
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_match, :wont_match
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_nil
 | 
			
		||||
  #
 | 
			
		||||
  #    obj.wont_be_nil
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_be_nil
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_nil, :wont_be_nil, :unary
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_operator
 | 
			
		||||
  #
 | 
			
		||||
  #    n.wont_be :<=, 42
 | 
			
		||||
  #
 | 
			
		||||
  # This can also do predicates:
 | 
			
		||||
  #
 | 
			
		||||
  #    str.wont_be :empty?
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_be
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_operator, :wont_be, :reverse
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_respond_to
 | 
			
		||||
  #
 | 
			
		||||
  #    obj.wont_respond_to msg
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_respond_to
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_respond_to, :wont_respond_to, :reverse
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  # See MiniTest::Assertions#refute_same
 | 
			
		||||
  #
 | 
			
		||||
  #    a.wont_be_same_as b
 | 
			
		||||
  #
 | 
			
		||||
  # :method: wont_be_same_as
 | 
			
		||||
 | 
			
		||||
  infect_an_assertion :refute_same, :wont_be_same_as
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Object # :nodoc:
 | 
			
		||||
  include MiniTest::Expectations unless ENV["MT_NO_EXPECTATIONS"]
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -1,804 +0,0 @@
 | 
			
		|||
# encoding: utf-8
 | 
			
		||||
 | 
			
		||||
# encoding: utf-8
 | 
			
		||||
require "minitest/autorun"
 | 
			
		||||
require "stringio"
 | 
			
		||||
 | 
			
		||||
class MiniSpecA < MiniTest::Spec; end
 | 
			
		||||
class MiniSpecB < MiniTest::Unit::TestCase; extend MiniTest::Spec::DSL; end
 | 
			
		||||
class MiniSpecC < MiniSpecB; end
 | 
			
		||||
class NamedExampleA < MiniSpecA; end
 | 
			
		||||
class NamedExampleB < MiniSpecB; end
 | 
			
		||||
class NamedExampleC < MiniSpecC; end
 | 
			
		||||
class ExampleA; end
 | 
			
		||||
class ExampleB < ExampleA; end
 | 
			
		||||
 | 
			
		||||
describe MiniTest::Spec do
 | 
			
		||||
  # do not parallelize this suite... it just can"t handle it.
 | 
			
		||||
 | 
			
		||||
  def assert_triggered expected = "blah", klass = MiniTest::Assertion
 | 
			
		||||
    @assertion_count += 2
 | 
			
		||||
 | 
			
		||||
    e = assert_raises(klass) do
 | 
			
		||||
      yield
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    msg = e.message.sub(/(---Backtrace---).*/m, '\1')
 | 
			
		||||
    msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
 | 
			
		||||
 | 
			
		||||
    assert_equal expected, msg
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  before do
 | 
			
		||||
    @assertion_count = 4
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  after do
 | 
			
		||||
    self._assertions.must_equal @assertion_count if passed? and not skipped?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to be able to catch a MiniTest::Assertion exception" do
 | 
			
		||||
    @assertion_count = 1
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 1 to not be equal to 1." do
 | 
			
		||||
      1.wont_equal 1
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to be sensible about must_include order" do
 | 
			
		||||
    @assertion_count += 3 # must_include is 2 assertions
 | 
			
		||||
 | 
			
		||||
    [1, 2, 3].must_include(2).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected [1, 2, 3] to include 5." do
 | 
			
		||||
      [1, 2, 3].must_include 5
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected [1, 2, 3] to include 5." do
 | 
			
		||||
      [1, 2, 3].must_include 5, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to be sensible about wont_include order" do
 | 
			
		||||
    @assertion_count += 3 # wont_include is 2 assertions
 | 
			
		||||
 | 
			
		||||
    [1, 2, 3].wont_include(5).must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected [1, 2, 3] to not include 2." do
 | 
			
		||||
      [1, 2, 3].wont_include 2
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected [1, 2, 3] to not include 2." do
 | 
			
		||||
      [1, 2, 3].wont_include 2, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to catch an expected exception" do
 | 
			
		||||
    @assertion_count = 2
 | 
			
		||||
 | 
			
		||||
    proc { raise "blah" }.must_raise RuntimeError
 | 
			
		||||
    proc { raise MiniTest::Assertion }.must_raise MiniTest::Assertion
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to catch an unexpected exception" do
 | 
			
		||||
    @assertion_count -= 2 # no positive
 | 
			
		||||
 | 
			
		||||
    msg = <<-EOM.gsub(/^ {6}/, "").chomp
 | 
			
		||||
      [RuntimeError] exception expected, not
 | 
			
		||||
      Class: <MiniTest::Assertion>
 | 
			
		||||
      Message: <"MiniTest::Assertion">
 | 
			
		||||
      ---Backtrace---
 | 
			
		||||
    EOM
 | 
			
		||||
 | 
			
		||||
    assert_triggered msg do
 | 
			
		||||
      proc { raise MiniTest::Assertion }.must_raise RuntimeError
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\n#{msg}" do
 | 
			
		||||
      proc { raise MiniTest::Assertion }.must_raise RuntimeError, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to ensure silence" do
 | 
			
		||||
    @assertion_count -= 1 # no msg
 | 
			
		||||
    @assertion_count += 2 # assert_output is 2 assertions
 | 
			
		||||
 | 
			
		||||
    proc {  }.must_be_silent.must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "In stdout.\nExpected: \"\"\n  Actual: \"xxx\"" do
 | 
			
		||||
      proc { print "xxx" }.must_be_silent
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to have all methods named well" do
 | 
			
		||||
    @assertion_count = 2
 | 
			
		||||
 | 
			
		||||
    methods = Object.public_instance_methods.find_all { |n| n =~ /^must|^wont/ }
 | 
			
		||||
    methods.map! { |m| m.to_s } if Symbol === methods.first
 | 
			
		||||
 | 
			
		||||
    musts, wonts = methods.sort.partition { |m| m =~ /^must/ }
 | 
			
		||||
 | 
			
		||||
    expected_musts = %w(must_be
 | 
			
		||||
                        must_be_close_to
 | 
			
		||||
                        must_be_empty
 | 
			
		||||
                        must_be_instance_of
 | 
			
		||||
                        must_be_kind_of
 | 
			
		||||
                        must_be_nil
 | 
			
		||||
                        must_be_same_as
 | 
			
		||||
                        must_be_silent
 | 
			
		||||
                        must_be_within_delta
 | 
			
		||||
                        must_be_within_epsilon
 | 
			
		||||
                        must_equal
 | 
			
		||||
                        must_include
 | 
			
		||||
                        must_match
 | 
			
		||||
                        must_output
 | 
			
		||||
                        must_raise
 | 
			
		||||
                        must_respond_to
 | 
			
		||||
                        must_send
 | 
			
		||||
                        must_throw)
 | 
			
		||||
 | 
			
		||||
    bad = %w[not raise throw send output be_silent]
 | 
			
		||||
 | 
			
		||||
    expected_wonts = expected_musts.map { |m| m.sub(/^must/, "wont") }
 | 
			
		||||
    expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }
 | 
			
		||||
 | 
			
		||||
    musts.must_equal expected_musts
 | 
			
		||||
    wonts.must_equal expected_wonts
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to raise if an expected exception is not raised" do
 | 
			
		||||
    @assertion_count -= 2 # no positive test
 | 
			
		||||
 | 
			
		||||
    assert_triggered "RuntimeError expected but nothing was raised." do
 | 
			
		||||
      proc { 42 }.must_raise RuntimeError
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nRuntimeError expected but nothing was raised." do
 | 
			
		||||
      proc { 42 }.must_raise RuntimeError, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify binary messages" do
 | 
			
		||||
    42.wont_be(:<, 24).must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 24 to not be < 42." do
 | 
			
		||||
      24.wont_be :<, 42
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected 24 to not be < 42." do
 | 
			
		||||
      24.wont_be :<, 42, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify emptyness" do
 | 
			
		||||
    @assertion_count += 3 # empty is 2 assertions
 | 
			
		||||
 | 
			
		||||
    [].must_be_empty.must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected [42] to be empty." do
 | 
			
		||||
      [42].must_be_empty
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected [42] to be empty." do
 | 
			
		||||
      [42].must_be_empty "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify equality" do
 | 
			
		||||
    (6 * 7).must_equal(42).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected: 42\n  Actual: 54" do
 | 
			
		||||
      (6 * 9).must_equal 42
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected: 42\n  Actual: 54" do
 | 
			
		||||
      (6 * 9).must_equal 42, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify floats outside a delta" do
 | 
			
		||||
    @assertion_count += 1 # extra test
 | 
			
		||||
 | 
			
		||||
    24.wont_be_close_to(42).must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected |42 - 42.0| (0.0) to not be <= 0.001." do
 | 
			
		||||
      (6 * 7.0).wont_be_close_to 42
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    x = maglev? ? "1.0000000000000001e-05" : "1.0e-05"
 | 
			
		||||
    assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
 | 
			
		||||
      (6 * 7.0).wont_be_close_to 42, 0.00001
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be <= #{x}." do
 | 
			
		||||
      (6 * 7.0).wont_be_close_to 42, 0.00001, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify floats outside an epsilon" do
 | 
			
		||||
    @assertion_count += 1 # extra test
 | 
			
		||||
 | 
			
		||||
    24.wont_be_within_epsilon(42).must_equal false
 | 
			
		||||
 | 
			
		||||
    x = maglev? ? "0.042000000000000003" : "0.042"
 | 
			
		||||
    assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
 | 
			
		||||
      (6 * 7.0).wont_be_within_epsilon 42
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    x = maglev? ? "0.00042000000000000002" : "0.00042"
 | 
			
		||||
    assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
 | 
			
		||||
      (6 * 7.0).wont_be_within_epsilon 42, 0.00001
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be <= #{x}." do
 | 
			
		||||
      (6 * 7.0).wont_be_within_epsilon 42, 0.00001, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify floats within a delta" do
 | 
			
		||||
    @assertion_count += 1 # extra test
 | 
			
		||||
 | 
			
		||||
    (6.0 * 7).must_be_close_to(42.0).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.001." do
 | 
			
		||||
      (1.0 / 100).must_be_close_to 0.0
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    x = maglev? ? "9.9999999999999995e-07" : "1.0e-06"
 | 
			
		||||
    assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
 | 
			
		||||
      (1.0 / 1000).must_be_close_to 0.0, 0.000001
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be <= #{x}." do
 | 
			
		||||
      (1.0 / 1000).must_be_close_to 0.0, 0.000001, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify floats within an epsilon" do
 | 
			
		||||
    @assertion_count += 1 # extra test
 | 
			
		||||
 | 
			
		||||
    (6.0 * 7).must_be_within_epsilon(42.0).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.0." do
 | 
			
		||||
      (1.0 / 100).must_be_within_epsilon 0.0
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= 0.0." do
 | 
			
		||||
      (1.0 / 1000).must_be_within_epsilon 0.0, 0.000001
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be <= 0.0." do
 | 
			
		||||
      (1.0 / 1000).must_be_within_epsilon 0.0, 0.000001, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify identity" do
 | 
			
		||||
    1.must_be_same_as(1).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 1 (oid=N) to be the same as 2 (oid=N)." do
 | 
			
		||||
      1.must_be_same_as 2
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected 1 (oid=N) to be the same as 2 (oid=N)." do
 | 
			
		||||
      1.must_be_same_as 2, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify inequality" do
 | 
			
		||||
    42.wont_equal(6 * 9).must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 1 to not be equal to 1." do
 | 
			
		||||
      1.wont_equal 1
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected 1 to not be equal to 1." do
 | 
			
		||||
      1.wont_equal 1, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify instances of a class" do
 | 
			
		||||
    42.wont_be_instance_of(String).must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 42 to not be an instance of Fixnum." do
 | 
			
		||||
      42.wont_be_instance_of Fixnum
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected 42 to not be an instance of Fixnum." do
 | 
			
		||||
      42.wont_be_instance_of Fixnum, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify kinds of a class" do
 | 
			
		||||
    42.wont_be_kind_of(String).must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 42 to not be a kind of Integer." do
 | 
			
		||||
      42.wont_be_kind_of Integer
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected 42 to not be a kind of Integer." do
 | 
			
		||||
      42.wont_be_kind_of Integer, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify kinds of objects" do
 | 
			
		||||
    @assertion_count += 2 # extra test
 | 
			
		||||
 | 
			
		||||
    (6 * 7).must_be_kind_of(Fixnum).must_equal true
 | 
			
		||||
    (6 * 7).must_be_kind_of(Numeric).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 42 to be a kind of String, not Fixnum." do
 | 
			
		||||
      (6 * 7).must_be_kind_of String
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected 42 to be a kind of String, not Fixnum." do
 | 
			
		||||
      (6 * 7).must_be_kind_of String, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify mismatch" do
 | 
			
		||||
    @assertion_count += 3 # match is 2
 | 
			
		||||
 | 
			
		||||
    "blah".wont_match(/\d+/).must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected /\\w+/ to not match \"blah\"." do
 | 
			
		||||
      "blah".wont_match(/\w+/)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected /\\w+/ to not match \"blah\"." do
 | 
			
		||||
      "blah".wont_match(/\w+/, "msg")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify nil" do
 | 
			
		||||
    nil.must_be_nil.must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 42 to be nil." do
 | 
			
		||||
      42.must_be_nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected 42 to be nil." do
 | 
			
		||||
      42.must_be_nil "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify non-emptyness" do
 | 
			
		||||
    @assertion_count += 3 # empty is 2 assertions
 | 
			
		||||
 | 
			
		||||
    ["some item"].wont_be_empty.must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected [] to not be empty." do
 | 
			
		||||
      [].wont_be_empty
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected [] to not be empty." do
 | 
			
		||||
      [].wont_be_empty "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify non-identity" do
 | 
			
		||||
    1.wont_be_same_as(2).must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do
 | 
			
		||||
      1.wont_be_same_as 1
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected 1 (oid=N) to not be the same as 1 (oid=N)." do
 | 
			
		||||
      1.wont_be_same_as 1, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify non-nil" do
 | 
			
		||||
    42.wont_be_nil.must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected nil to not be nil." do
 | 
			
		||||
      nil.wont_be_nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected nil to not be nil." do
 | 
			
		||||
      nil.wont_be_nil "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify objects not responding to a message" do
 | 
			
		||||
    "".wont_respond_to(:woot!).must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected \"\" to not respond to to_s." do
 | 
			
		||||
      "".wont_respond_to :to_s
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected \"\" to not respond to to_s." do
 | 
			
		||||
      "".wont_respond_to :to_s, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify output in stderr" do
 | 
			
		||||
    @assertion_count -= 1 # no msg
 | 
			
		||||
 | 
			
		||||
    proc { $stderr.print "blah" }.must_output(nil, "blah").must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "In stderr.\nExpected: \"blah\"\n  Actual: \"xxx\"" do
 | 
			
		||||
      proc { $stderr.print "xxx" }.must_output(nil, "blah")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify output in stdout" do
 | 
			
		||||
    @assertion_count -= 1 # no msg
 | 
			
		||||
 | 
			
		||||
    proc { print "blah" }.must_output("blah").must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "In stdout.\nExpected: \"blah\"\n  Actual: \"xxx\"" do
 | 
			
		||||
      proc { print "xxx" }.must_output("blah")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify regexp matches" do
 | 
			
		||||
    @assertion_count += 3 # must_match is 2 assertions
 | 
			
		||||
 | 
			
		||||
    "blah".must_match(/\w+/).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected /\\d+/ to match \"blah\"." do
 | 
			
		||||
      "blah".must_match(/\d+/)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected /\\d+/ to match \"blah\"." do
 | 
			
		||||
      "blah".must_match(/\d+/, "msg")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify throw" do
 | 
			
		||||
    @assertion_count += 2 # 2 extra tests
 | 
			
		||||
 | 
			
		||||
    proc { throw :blah }.must_throw(:blah).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected :blah to have been thrown." do
 | 
			
		||||
      proc { }.must_throw :blah
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected :blah to have been thrown, not :xxx." do
 | 
			
		||||
      proc { throw :xxx }.must_throw :blah
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected :blah to have been thrown." do
 | 
			
		||||
      proc { }.must_throw :blah, "msg"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected :blah to have been thrown, not :xxx." do
 | 
			
		||||
      proc { throw :xxx }.must_throw :blah, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify types of objects" do
 | 
			
		||||
    (6 * 7).must_be_instance_of(Fixnum).must_equal true
 | 
			
		||||
 | 
			
		||||
    exp = "Expected 42 to be an instance of String, not Fixnum."
 | 
			
		||||
 | 
			
		||||
    assert_triggered exp do
 | 
			
		||||
      (6 * 7).must_be_instance_of String
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\n#{exp}" do
 | 
			
		||||
      (6 * 7).must_be_instance_of String, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify using any (negative) predicate" do
 | 
			
		||||
    @assertion_count -= 1 # doesn"t take a message
 | 
			
		||||
 | 
			
		||||
    "blah".wont_be(:empty?).must_equal false
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected \"\" to not be empty?." do
 | 
			
		||||
      "".wont_be :empty?
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify using any binary operator" do
 | 
			
		||||
    @assertion_count -= 1 # no msg
 | 
			
		||||
 | 
			
		||||
    41.must_be(:<, 42).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 42 to be < 41." do
 | 
			
		||||
      42.must_be(:<, 41)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify using any predicate" do
 | 
			
		||||
    @assertion_count -= 1 # no msg
 | 
			
		||||
 | 
			
		||||
    "".must_be(:empty?).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected \"blah\" to be empty?." do
 | 
			
		||||
      "blah".must_be :empty?
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "needs to verify using respond_to" do
 | 
			
		||||
    42.must_respond_to(:+).must_equal true
 | 
			
		||||
 | 
			
		||||
    assert_triggered "Expected 42 (Fixnum) to respond to #clear." do
 | 
			
		||||
      42.must_respond_to :clear
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_triggered "msg.\nExpected 42 (Fixnum) to respond to #clear." do
 | 
			
		||||
      42.must_respond_to :clear, "msg"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
describe MiniTest::Spec, :let do
 | 
			
		||||
  i_suck_and_my_tests_are_order_dependent!
 | 
			
		||||
 | 
			
		||||
  def _count
 | 
			
		||||
    $let_count ||= 0
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  let :count do
 | 
			
		||||
    $let_count += 1
 | 
			
		||||
    $let_count
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "is evaluated once per example" do
 | 
			
		||||
    _count.must_equal 0
 | 
			
		||||
 | 
			
		||||
    count.must_equal 1
 | 
			
		||||
    count.must_equal 1
 | 
			
		||||
 | 
			
		||||
    _count.must_equal 1
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "is REALLY evaluated once per example" do
 | 
			
		||||
    _count.must_equal 1
 | 
			
		||||
 | 
			
		||||
    count.must_equal 2
 | 
			
		||||
    count.must_equal 2
 | 
			
		||||
 | 
			
		||||
    _count.must_equal 2
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
describe MiniTest::Spec, :subject do
 | 
			
		||||
  attr_reader :subject_evaluation_count
 | 
			
		||||
 | 
			
		||||
  subject do
 | 
			
		||||
    @subject_evaluation_count ||= 0
 | 
			
		||||
    @subject_evaluation_count  += 1
 | 
			
		||||
    @subject_evaluation_count
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "is evaluated once per example" do
 | 
			
		||||
    subject.must_equal 1
 | 
			
		||||
    subject.must_equal 1
 | 
			
		||||
    subject_evaluation_count.must_equal 1
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class TestMetaStatic < MiniTest::Unit::TestCase
 | 
			
		||||
  def test_children
 | 
			
		||||
    MiniTest::Spec.children.clear # prevents parallel run
 | 
			
		||||
 | 
			
		||||
    x = y = z = nil
 | 
			
		||||
    x = describe "top-level thingy" do
 | 
			
		||||
      y = describe "first thingy" do end
 | 
			
		||||
 | 
			
		||||
      it "top-level-it" do end
 | 
			
		||||
 | 
			
		||||
      z = describe "second thingy" do end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_equal [x], MiniTest::Spec.children
 | 
			
		||||
    assert_equal [y, z], x.children
 | 
			
		||||
    assert_equal [], y.children
 | 
			
		||||
    assert_equal [], z.children
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class TestMeta < MiniTest::Unit::TestCase
 | 
			
		||||
  def util_structure
 | 
			
		||||
    x = y = z = nil
 | 
			
		||||
    before_list = []
 | 
			
		||||
    after_list  = []
 | 
			
		||||
    x = describe "top-level thingy" do
 | 
			
		||||
      before { before_list << 1 }
 | 
			
		||||
      after  { after_list  << 1 }
 | 
			
		||||
 | 
			
		||||
      it "top-level-it" do end
 | 
			
		||||
 | 
			
		||||
      y = describe "inner thingy" do
 | 
			
		||||
        before { before_list << 2 }
 | 
			
		||||
        after  { after_list  << 2 }
 | 
			
		||||
        it "inner-it" do end
 | 
			
		||||
 | 
			
		||||
        z = describe "very inner thingy" do
 | 
			
		||||
          before { before_list << 3 }
 | 
			
		||||
          after  { after_list  << 3 }
 | 
			
		||||
          it "inner-it" do end
 | 
			
		||||
 | 
			
		||||
          it      {} # ignore me
 | 
			
		||||
          specify {} # anonymous it
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    return x, y, z, before_list, after_list
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_register_spec_type
 | 
			
		||||
    original_types = MiniTest::Spec::TYPES.dup
 | 
			
		||||
 | 
			
		||||
    assert_equal [[//, MiniTest::Spec]], MiniTest::Spec::TYPES
 | 
			
		||||
 | 
			
		||||
    MiniTest::Spec.register_spec_type(/woot/, TestMeta)
 | 
			
		||||
 | 
			
		||||
    p = lambda do |x| true end
 | 
			
		||||
    MiniTest::Spec.register_spec_type TestMeta, &p
 | 
			
		||||
 | 
			
		||||
    keys = MiniTest::Spec::TYPES.map(&:first)
 | 
			
		||||
 | 
			
		||||
    assert_includes keys, /woot/
 | 
			
		||||
    assert_includes keys, p
 | 
			
		||||
  ensure
 | 
			
		||||
    MiniTest::Spec::TYPES.replace original_types
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_spec_type
 | 
			
		||||
    original_types = MiniTest::Spec::TYPES.dup
 | 
			
		||||
 | 
			
		||||
    MiniTest::Spec.register_spec_type(/A$/, MiniSpecA)
 | 
			
		||||
    MiniTest::Spec.register_spec_type MiniSpecB do |desc|
 | 
			
		||||
      desc.superclass == ExampleA
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_equal MiniSpecA, MiniTest::Spec.spec_type(ExampleA)
 | 
			
		||||
    assert_equal MiniSpecB, MiniTest::Spec.spec_type(ExampleB)
 | 
			
		||||
  ensure
 | 
			
		||||
    MiniTest::Spec::TYPES.replace original_types
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_name
 | 
			
		||||
    spec_a = describe ExampleA do; end
 | 
			
		||||
    spec_b = describe ExampleB, :random_method do; end
 | 
			
		||||
 | 
			
		||||
    assert_equal "ExampleA", spec_a.name
 | 
			
		||||
    assert_equal "ExampleB::random_method", spec_b.name
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_name2
 | 
			
		||||
    assert_equal "NamedExampleA", NamedExampleA.name
 | 
			
		||||
    assert_equal "NamedExampleB", NamedExampleB.name
 | 
			
		||||
    assert_equal "NamedExampleC", NamedExampleC.name
 | 
			
		||||
 | 
			
		||||
    spec_a = describe ExampleA do; end
 | 
			
		||||
    spec_b = describe ExampleB, :random_method do; end
 | 
			
		||||
 | 
			
		||||
    assert_equal "ExampleA", spec_a.name
 | 
			
		||||
    assert_equal "ExampleB::random_method", spec_b.name
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_structure
 | 
			
		||||
    x, y, z, * = util_structure
 | 
			
		||||
 | 
			
		||||
    assert_equal "top-level thingy",                                  x.to_s
 | 
			
		||||
    assert_equal "top-level thingy::inner thingy",                    y.to_s
 | 
			
		||||
    assert_equal "top-level thingy::inner thingy::very inner thingy", z.to_s
 | 
			
		||||
 | 
			
		||||
    assert_equal "top-level thingy",  x.desc
 | 
			
		||||
    assert_equal "inner thingy",      y.desc
 | 
			
		||||
    assert_equal "very inner thingy", z.desc
 | 
			
		||||
 | 
			
		||||
    top_methods = %w(setup teardown test_0001_top-level-it)
 | 
			
		||||
    inner_methods1 = %w(setup teardown 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(&: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
 | 
			
		||||
    _, _, z, before_list, after_list = util_structure
 | 
			
		||||
 | 
			
		||||
    @tu = MiniTest::Unit.new
 | 
			
		||||
    MiniTest::Unit.runner = nil # protect the outer runner from the inner tests
 | 
			
		||||
 | 
			
		||||
    with_output do
 | 
			
		||||
      tc = z.new :test_0002_anonymous
 | 
			
		||||
      tc.run @tu
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_equal [1, 2, 3], before_list
 | 
			
		||||
    assert_equal [3, 2, 1], after_list
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_describe_first_structure
 | 
			
		||||
    x = x1 = x2 = y = z = nil
 | 
			
		||||
    x = describe "top-level thingy" do
 | 
			
		||||
      y = describe "first thingy" do end
 | 
			
		||||
 | 
			
		||||
      x1 = it "top level it" do end
 | 
			
		||||
      x2 = it "не латинские буквы-и-спецсимволы&いった α, β, γ, δ, ε hello!!! world" do end
 | 
			
		||||
 | 
			
		||||
      z = describe "second thingy" do end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test_methods = ["test_0001_top level it", "test_0002_не латинские буквы-и-спецсимволы&いった α, β, γ, δ, ε hello!!! world"].sort
 | 
			
		||||
 | 
			
		||||
    assert_equal test_methods, [x1, x2]
 | 
			
		||||
    assert_equal test_methods,
 | 
			
		||||
      x.instance_methods.grep(/^test/).map {|o| o.to_s}.sort
 | 
			
		||||
    assert_equal [], y.instance_methods.grep(/^test/)
 | 
			
		||||
    assert_equal [], z.instance_methods.grep(/^test/)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_structure_subclasses
 | 
			
		||||
    z = nil
 | 
			
		||||
    x = Class.new MiniTest::Spec do
 | 
			
		||||
      def xyz; end
 | 
			
		||||
    end
 | 
			
		||||
    y = Class.new x do
 | 
			
		||||
      z = describe("inner") {}
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    assert_respond_to x.new(nil), "xyz"
 | 
			
		||||
    assert_respond_to y.new(nil), "xyz"
 | 
			
		||||
    assert_respond_to z.new(nil), "xyz"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def with_output # REFACTOR: dupe from metametameta
 | 
			
		||||
    synchronize do
 | 
			
		||||
      begin
 | 
			
		||||
        @output = StringIO.new("")
 | 
			
		||||
        MiniTest::Unit.output = @output
 | 
			
		||||
 | 
			
		||||
        yield
 | 
			
		||||
      ensure
 | 
			
		||||
        MiniTest::Unit.output = STDOUT
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
require "minitest/metametameta"
 | 
			
		||||
 | 
			
		||||
class TestSpecInTestCase < MetaMetaMetaTestCase
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
 | 
			
		||||
    @tc = MiniTest::Unit::TestCase.new "fake tc"
 | 
			
		||||
    @assertion_count = 1
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def util_assert_triggered expected, klass = MiniTest::Assertion # REFACTOR
 | 
			
		||||
    e = assert_raises klass do
 | 
			
		||||
      yield
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    msg = e.message.sub(/(---Backtrace---).*/m, "\1")
 | 
			
		||||
    msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
 | 
			
		||||
 | 
			
		||||
    assert_equal expected, msg
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def teardown # REFACTOR
 | 
			
		||||
    assert_equal(@assertion_count, @tc._assertions,
 | 
			
		||||
                 "expected #{@assertion_count} assertions to be fired during the test, not #{@tc._assertions}") if @tc.passed?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_expectation
 | 
			
		||||
    @assertion_count = 2
 | 
			
		||||
 | 
			
		||||
    @tc.assert_equal true, 1.must_equal(1)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_expectation_triggered
 | 
			
		||||
    util_assert_triggered "Expected: 2\n  Actual: 1" do
 | 
			
		||||
      1.must_equal 2
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_expectation_with_a_message
 | 
			
		||||
    util_assert_triggered "Expected: 2\n  Actual: 1" do
 | 
			
		||||
      1.must_equal 2, ""
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue