Class Uttk::Strategies::RUnit
In: lib/uttk/strategies/RUnit.rb
Parent: Strategy

Description

This strategy is wrapper around a Ruby unit test suite based on the test/unit library. Using RUnit you avoid the Ruby `require’ problem and you use all the power of the Uttk‘s Suite and/or Pool.

How it works ?

RUnit works by invoking Ruby on the specified file and then by parsing the output in order to inject it into the Uttk‘s log stream. To do that, you must use a specific TestRunner based on YAML. This TestRunner produces a YAML output readable by a human and the strategy.

Examples

You need to first write your unit test suite using the test/unit package and the YAML TestRunner. Then, you write a few line in the input Uttk file to incorporate the unit test in the Uttk‘s suite.

The unit test suite file: foo_test.rb

  require 'foo'

  class FooTest < Test::Unit::TestCase

    def test_1
      assert(true)
    end

  end

The YAML input file for Uttk

  ---
  RUnit example test:
    strategy: RUnit
    input: !path my_unit_directory/foo_test.rb

One suite for all your unit test suite

If you find cumbersome to write for every unit test files a single RUnit strategy into the YAML input file of Uttk, there is another way that is used in test/unit-suite.yml.

Methods

Included Modules

Concrete

Protected Instance methods

[Source]

# File lib/uttk/strategies/RUnit.rb, line 116
      def abort_hook
        @runner.abort @data if @runner and defined? @data
        super
      end

[Source]

# File lib/uttk/strategies/RUnit.rb, line 83
      def assertion
        matcher_result = command_matcher[UM::StreamMatcher, {:error => ''}, @data]
        @log << matcher_result
        raise_error('Error output not empty') if matcher_result.failure?

        if @data.output.zero?
          skip('No result has been collected probably because no test ' +
               'suite has been run')
        end

        output = YAML.load @data.output.read
        @log[:result] = output
        o = OpenStruct.new output

        if o.tests_number.zero?
          skip_pass 'No test suite in this file'
        end

        pass if o.failures_number.zero? and o.errors_number.zero?

        rpath = '/^failures$/^default_test/No tests were specified'
        if o.failures_number == 1 and output.rpath_find :first, rpath
          skip 'No tests were specified'
        elsif o.failures_number.zero?
          fail 'There are errors'
        elsif o.errors_number.zero?
          fail 'There are failures'
        end

        fail 'There are failures and errors'
      end

[Source]

# File lib/uttk/strategies/RUnit.rb, line 122
      def epilogue
        @data.clean if defined? @data
        super
      end

[Source]

# File lib/uttk/strategies/RUnit.rb, line 61
      def prologue
        super
        @runner = mk_system_runner
        @command = '<<ruby>>'.to_ocmd << '--' << '<<uttk-unit>>'
        if @verbose
          @command << '--verbose'
        else
          @command << '--no-verbose'
        end
        @load_path.each { |x| @command << '-I' << x }
        @requires.to_ocmd_args.each { |x| @command << '-r' << x }
        @command += @uttk_unit_options.to_ocmd_args
        @command << '--' << @input << '--' << '--runner' << 'yaml'
        @command.dir = @dir
      end

[Source]

# File lib/uttk/strategies/RUnit.rb, line 78
      def run_impl
        @data = @command.run @runner
      end

[Validate]