Sha256: 92697335054659baaeda03bce2094e971cb73038d9586f52a05815751f01eb25

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

module Test
  module Unit # :nodoc:
    class TestCase # :nodoc:
      
      def name # :nodoc:
        "#{self.class.name}\t\t#{@method_name}"
      end
      
      # Let's alias the run method in the class above us so we can create a new one here
      # but still reference it.
      alias_method :super_run, :run # :nodoc:

      # We need to wrap the run method so we can do things like
      # run a cleanup method if it exists
      def run(result, &progress_block) # :nodoc:
        super_run(result) do |state, name|
          if state == Test::Unit::TestCase::STARTED
            cleanup if self.respond_to?(:cleanup)
            log_start(name)
          else
            cleanup if self.respond_to?(:cleanup)
            log_end(name)
          end
        end
      end
      
      def log_start(name = "")
        @log_start_time = Time.now      
        puts "\n#{format_log_time(@log_start_time)}: Starting\t#{name}"
      end

      def log_end(name = "")                 
        @log_end_time = Time.now
        puts "#{format_log_time(@log_end_time)}: Ending\t#{name}"
        et = @log_end_time - @log_start_time
        suffix = ""
        et.round.times { suffix += "!" } if et > 1.0
        if et > 0.5
          puts "#{suffix}Elapsed Time: #{et} seconds#{suffix}"
        end
      end
      
      private
      def format_log_time(time = Time.now)
        time.strftime("%I:%M:%S %p")
      end
      
    end # TestCase
  end # Unit
end # Test

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mack-0.5.0 lib/test_extensions/test_case.rb
mack-0.5.5.1 lib/test_extensions/test_case.rb
mack-0.5.5.2 lib/test_extensions/test_case.rb
mack-0.5.5.3 lib/test_extensions/test_case.rb
mack-0.5.5.4 lib/test_extensions/test_case.rb
mack-0.5.5 lib/test_extensions/test_case.rb