Sha256: 465793f8245a559cd7da8a97d8f24e2813bbc0377b599934ed64f4a4f1fa3492

Contents?: true

Size: 1.72 KB

Versions: 5

Compression:

Stored size: 1.72 KB

Contents

require 'stringio'
require 'test/unit/testcase'
require 'minitest/unit'

class MiniTestResult
  def self.parse_failure(raw)
    matches = %r{(Failure)\:\n([^\(]+)\(([^\)]+)\) \[([^\]]+)\]\:\n(.*)\n}m.match(raw)
    return nil unless matches
    Failure.new(matches[2], matches[3], [matches[4]], matches[5])
  end
  
  def self.parse_error(raw)
    matches = %r{(Error)\:\n([^\(]+)\(([^\)]+)\)\:\n(.+?)\n.+    (.*)\n}m.match(raw)
    return nil unless matches
    Error.new(matches[2], matches[3], matches[4], [matches[5]])
  end
  
  class Failure
    attr_reader :method, :test_case, :location, :message
    def initialize(method, test_case, location, message)
      @method, @test_case, @location, @message = method, test_case, location, message
    end
  end
  
  class Error
    class Exception
      attr_reader :message, :backtrace
      def initialize(message, location)
        @message, @backtrace = message, location
      end
    end
    
    attr_reader :method, :test_case, :exception
    def initialize(method, test_case, message, backtrace)
      @method, @test_case, @exception = method, test_case, Exception.new(message, backtrace)
    end
  end
  
  def initialize(runner, test)
    @runner, @test = runner, test
  end
  
  def failure_count
    @runner.failures
  end
  
  def assertion_count
    @test._assertions
  end
  
  def error_count
    @runner.errors
  end
  
  def passed?
    @test.passed?
  end
  
  def failures
    @runner.report.map { |puked| MiniTestResult.parse_failure(puked) }.compact
  end
  
  def errors
    @runner.report.map { |puked| MiniTestResult.parse_error(puked) }.compact
  end
  
  def failure_messages
    failures.map(&:message)
  end
  
  def error_messages
    errors.map { |e| e.exception.message }
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
mocha-0.9.11 test/mini_test_result.rb
mocha-0.9.10 test/mini_test_result.rb
mocha-macruby-0.9.9.20101102121900 test/mini_test_result.rb
mocha-0.9.9 test/mini_test_result.rb
jferris-mocha-0.9.8.20100526112143 test/mini_test_result.rb