123456789_123456789_123456789_123456789_123456789_

Class: Test::Unit::UI::XML::TestRunner

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
self, ERB::Util, ::Test::Unit::UI::TestRunner
Inherits: Test::Unit::UI::TestRunner
Defined in: lib/test/unit/ui/xml/testrunner.rb

Overview

Class Method Summary

::Test::Unit::UI::TestRunner - Inherited

::Test::Unit::UI::TestRunnerUtilities - Extended

run

Creates a new TestRunner and runs the suite.

start_command_line_test

Takes care of the ARGV parsing and suite determination necessary for running one of the TestRunners from the command line.

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(suite, options = {}) ⇒ TestRunner

Creates a new TestRunner for running the passed suite. :output option specifies where runner output should go to; defaults to STDOUT.

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 25

def initialize(suite, options={})
  super
  @output = @options[:output] || STDOUT
  if @options[:output_file_descriptor]
    @output = IO.new(@options[:output_file_descriptor], "w")
  end
  @already_outputted = false
  @indent = 0
  @top_level = true
  @current_test = nil
  @current_test_suite = nil
  @already_outputted = false
end

Instance Method Details

#add_content(name, content) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 182

def add_content(name, content)
  return if content.nil?
  case content
  when Time
    content = content.iso8601
  end
  @output.puts("#{indent}<#{name}>#{h(content)}</#{name}>")
end

#attach_to_mediator (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 40

def attach_to_mediator
  @mediator.add_listener(TestResult::PASS_ASSERTION,
                         &method(:result_pass_assertion))
  @mediator.add_listener(TestResult::FAULT,
                         &method(:result_fault))
  @mediator.add_listener(TestRunnerMediator::STARTED,
                         &method(:started))
  @mediator.add_listener(TestRunnerMediator::FINISHED,
                         &method(:finished))
  @mediator.add_listener(TestCase::STARTED_OBJECT,
                         &method(:test_started))
  @mediator.add_listener(TestCase::FINISHED_OBJECT,
                         &method(:test_finished))
  @mediator.add_listener(TestSuite::STARTED_OBJECT,
                         &method(:test_suite_started))
  @mediator.add_listener(TestSuite::FINISHED_OBJECT,
                         &method(:test_suite_finished))
end

#close_tag(name) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 191

def close_tag(name)
  @indent -= 2
  @output.puts("#{indent}</#{name}>")
end

#finished(elapsed_time) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 102

def finished(elapsed_time)
  add_content("success", @result.passed?)
  close_tag("stream")
end

#indent (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 169

def indent
  " " * @indent
end

#open_tag(name) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 173

def open_tag(name)
  @output.puts("#{indent}<#{name}>")
  @indent += 2
  if block_given?
    yield
    close_tag(name)
  end
end

#output_started (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 98

def output_started
  open_tag("stream")
end

#output_test(test) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 196

def output_test(test)
  open_tag("test") do
    add_content("name", test.method_name)
    add_content("start-time", test.start_time)
    add_content("elapsed", test.elapsed_time)
  end
end

#output_test_suite(test_suite) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 204

def output_test_suite(test_suite)
  test_case = test_suite.test_case
  if test_case.nil?
    open_tag("test-suite") do
      add_content("name", test_suite.name)
      add_content("start-time", test_suite.start_time)
      add_content("elapsed", test_suite.elapsed_time)
    end
  else
    open_tag("test-case") do
      add_content("name", test_suite.name)
      add_content("start-time", test_suite.start_time)
      add_content("elapsed", test_suite.elapsed_time)
    end
  end
end

#result_fault(fault) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 65

def result_fault(fault)
  open_tag("test-result") do
    open_tag("result") do
      output_test_suite(@current_test_suite)
      output_test(@current_test)
      open_tag("backtrace") do
        fault.location.each do |entry|
          file, line, info = entry.split(/:/, 3)
          open_tag("entry") do
            add_content("file", file)
            add_content("line", line)
            add_content("info", info)
          end
        end
      end
      if fault.respond_to?(:expected)
        add_content("expected", fault.expected)
      end
      if fault.respond_to?(:actual)
        add_content("actual", fault.actual)
      end
      add_content("detail", fault.message)
      add_content("status", fault.label.downcase)
    end
  end
  @already_outputted = true if fault.critical?
end

#result_pass_assertion(result) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 59

def result_pass_assertion(result)
  open_tag("pass-assertion") do
    output_test(@current_test)
  end
end

#started(result) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 93

def started(result)
  @result = result
  output_started
end

#test_finished(test) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 115

def test_finished(test)
  unless @already_outputted
    open_tag("test-result") do
      output_test(test)
      open_tag("result") do
        output_test_suite(@current_test_suite)
        output_test(test)
        add_content("status", "success")
      end
    end
  end

  open_tag("complete-test") do
    output_test(test)
    add_content("success", test.passed?)
  end
  @current_test = nil
end

#test_started(test) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 107

def test_started(test)
  @already_outputted = false
  @current_test = test
  open_tag("start-test") do
    output_test(test)
  end
end

#test_suite_finished(suite) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 154

def test_suite_finished(suite)
  if suite.test_case.nil?
    open_tag("complete-test-suite") do
      output_test_suite(suite)
      add_content("success", suite.passed?)
    end
  else
    open_tag("complete-test-case") do
      output_test_suite(suite)
      add_content("success", suite.passed?)
    end
  end
  @current_test_suite = nil
end

#test_suite_started(suite) (private)

[ GitHub ]

  
# File 'lib/test/unit/ui/xml/testrunner.rb', line 134

def test_suite_started(suite)
  @current_test_suite = suite
  if suite.test_case.nil?
    open_tag("ready-test-suite") do
      add_content("n-tests", suite.size)
    end
    open_tag("start-test-suite") do
      output_test_suite(suite)
    end
  else
    open_tag("ready-test-case") do
      output_test_suite(suite)
      add_content("n-tests", suite.size)
    end
    open_tag("start-test-case") do
      output_test_suite(suite)
    end
  end
end