Class: Test::Unit::UI::Launchable::JSON::TestRunner

Inherits:
UI::Console::TestRunner
  • Object
show all
Defined in:
lib/test/unit/ui/launchable/json/testrunner.rb

Instance Method Summary collapse

Constructor Details

#initialize(suite, options = {}) ⇒ TestRunner

Returns a new instance of TestRunner.



11
12
13
14
15
# File 'lib/test/unit/ui/launchable/json/testrunner.rb', line 11

def initialize(suite, options={})
  super
  @curt_test_case = nil
  @json_stream_writer = nil
end

Instance Method Details

#attach_to_mediatorObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/test/unit/ui/launchable/json/testrunner.rb', line 17

def attach_to_mediator
  # To output logs to both stderr/stdout and an XML file,
  # `UI::Console::TestRunner#attach_to_mediator` is called here.
  super

  test_report = @options[:launchable_test_report]
  return unless test_report

  @json_stream_writer = JSONStreamWriter.new(test_report)
  @mediator.add_listener(::Test::Unit::TestCase::STARTED_OBJECT) do |test|
    @curt_test_case = LaunchableTestCase.new(test)
  end
  @mediator.add_listener(::Test::Unit::TestCase::FINISHED_OBJECT) do |test|
    @curt_test_case.elapsed_time = test.elapsed_time
    @json_stream_writer.write_test_case do |writer|
      # The test path is a URL-encoded representation.
      # https://github.com/launchableinc/cli/blob/v1.81.0/launchable/testpath.py#L18
      writer.write_test_path_components(@curt_test_case.test_path)
      writer.write_duration(@curt_test_case.elapsed_time)
      writer.write_status(@curt_test_case.status)
      writer.write_stdout(nil)
      writer.write_stderr(@curt_test_case.stderr)
      writer.write_created_at(Time.now.to_s)
    end
    @curt_test_case = nil
  end
  @mediator.add_listener(TestResult::FAULT) do |fault|
    @curt_test_case.fault = fault
  end
  @mediator.add_listener(TestRunnerMediator::FINISHED) do
    @json_stream_writer.close
  end
end