Sha256: 4ddc571d9624465328f8daae1d1bb36cc5b806384174259f61c0091b8599c6f4

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

require 'test/unit'
require 'test/unit/testresult'

Test::Unit.run = true # This stops testunit from running the file as soon as it is included. Yep. That's correct. True.

module GorgonTestCases
  def self.cases
    @gorgon_cases ||= []
  end

  def self.clear_cases!
    @gorgon_cases = []
  end
end


if defined? ActiveSupport::TestCase
  class ActiveSupport::TestCase
    def self.inherited(klass)
      GorgonTestCases.cases << klass
    end
  end
end

class Test::Unit::TestCase
  def self.inherited(klass)
    GorgonTestCases.cases << klass
  end
end

class TestRunner
  def self.run_file(filename)
    GorgonTestCases.clear_cases!
    load filename

    result = Test::Unit::TestResult.new
    output = []
    result.add_listener(Test::Unit::TestResult::FAULT) do |value|
      output << value
    end

    GorgonTestCases.cases.each do |klass|
      # Not all descendants of TestCase are actually runnable, but they do all implement #suite
      # Calling suite.run will give us only runnable tests
      klass.suite.run(result) {|s,n|;}
    end

    output
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gorgon-0.3.0 lib/gorgon/testunit_runner.rb
gorgon-0.2.0 lib/gorgon/testunit_runner.rb
gorgon-0.1.1 lib/gorgon/testunit_runner.rb
gorgon-0.1.0 lib/gorgon/testunit_runner.rb
gorgon-0.0.2 lib/gorgon/testunit_runner.rb
gorgon-0.0.1 lib/gorgon/testunit_runner.rb