\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef.upgrade/embedded/lib/ruby/gems/2.3.0/gems/systemu-2.6.5/test/

Viewing File: testing.rb

require 'test/unit'

testdir = File.expand_path(File.dirname(__FILE__))
rootdir = File.dirname(testdir)
libdir = File.join(rootdir, 'lib')

STDOUT.sync = true

$:.unshift(testdir) unless $:.include?(testdir)
$:.unshift(libdir) unless $:.include?(libdir)
$:.unshift(rootdir) unless $:.include?(rootdir)

class Testing
  class Slug < ::String
    def Slug.for(*args)
      string = args.flatten.compact.join('-')
      words = string.to_s.scan(%r/\w+/)
      words.map!{|word| word.gsub %r/[^0-9a-zA-Z_-]/, ''}
      words.delete_if{|word| word.nil? or word.strip.empty?}
      new(words.join('-').downcase)
    end
  end
  
  class Context
    attr_accessor :name

    def initialize(name, *args)
      @name = name
    end

    def to_s
      Slug.for(name)
    end
  end
end

def Testing(*args, &block)
  Class.new(::Test::Unit::TestCase) do

  ## class methods
  #
    class << self
      def contexts
        @contexts ||= []
      end

      def context(*args, &block)
        return contexts.last if(args.empty? and block.nil?)

        context = Testing::Context.new(*args)
        contexts.push(context)

        begin
          block.call(context)
        ensure
          contexts.pop
        end
      end

      def slug_for(*args)
        string = [context, args].flatten.compact.join('-')
        words = string.to_s.scan(%r/\w+/)
        words.map!{|word| word.gsub %r/[^0-9a-zA-Z_-]/, ''}
        words.delete_if{|word| word.nil? or word.strip.empty?}
        words.join('-').downcase.sub(/_$/, '')
      end

      def name() const_get(:Name) end

      def testno()
        '%05d' % (@testno ||= 0)
      ensure
        @testno += 1
      end

      def testing(*args, &block)
        method = ["test", testno, slug_for(*args)].delete_if{|part| part.empty?}.join('_')
        define_method(method, &block)
      end

      def test(*args, &block)
        testing(*args, &block)
      end

      def setup(&block)
        define_method(:setup, &block) if block
      end

      def teardown(&block)
        define_method(:teardown, &block) if block
      end

      def prepare(&block)
        @prepare ||= []
        @prepare.push(block) if block
        @prepare
      end

      def cleanup(&block)
        @cleanup ||= []
        @cleanup.push(block) if block
        @cleanup
      end
    end

  ## configure the subclass!
  #
    const_set(:Testno, '0')
    slug = slug_for(*args).gsub(%r/-/,'_')
    name = ['TESTING', '%03d' % const_get(:Testno), slug].delete_if{|part| part.empty?}.join('_')
    name = name.upcase!
    const_set(:Name, name)
    const_set(:Missing, Object.new.freeze)

  ## instance methods
  #
    alias_method('__assert__', 'assert')

    def assert(*args, &block)
      if args.size == 1 and args.first.is_a?(Hash)
        options = args.first
        expected = getopt(:expected, options){ missing }
        actual = getopt(:actual, options){ missing }
        if expected == missing and actual == missing
          actual, expected, *ignored = options.to_a.flatten
        end
        expected = expected.call() if expected.respond_to?(:call)
        actual = actual.call() if actual.respond_to?(:call)
        assert_equal(expected, actual)
      end

      if block
        label = "assert(#{ args.join(' ') })"
        result = nil
        assert_nothing_raised{ result = block.call }
        __assert__(result, label)
        result
      else
        result = args.shift
        label = "assert(#{ args.join(' ') })"
        __assert__(result, label)
        result
      end
    end

    def missing
      self.class.const_get(:Missing)
    end

    def getopt(opt, hash, options = nil, &block)
      [opt.to_s, opt.to_s.to_sym].each do |key|
        return hash[key] if hash.has_key?(key)
      end
      default =
        if block
          block.call
        else
          options.is_a?(Hash) ? options[:default] : nil
        end
      return default
    end

    def subclass_of exception
      class << exception
        def ==(other) super or self > other end
      end
      exception
    end

  ##
  #
    module_eval(&block)

    self.setup()
    self.prepare.each{|b| b.call()}

    at_exit{ 
      self.teardown()
      self.cleanup.each{|b| b.call()}
    }

    self
  end
end


if $0 == __FILE__

  Testing 'Testing' do
    testing('foo'){ assert true }
    test{ assert true }
    p instance_methods.grep(/test/)
  end

end