Class: Minitest::Reporters::RubyciReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/reporters/rubyci_reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRubyciReporter

Returns a new instance of RubyciReporter.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 29

def initialize
  @tests = {}
  @test_results = {}
  @ids = {}
  @events = []

  $stdout = StringIO.new()

  if ENV['RBCI_REMOTE_TESTS'] != 'true'
    RubyCI.minitest_ws.on(:enq_request) do
      tests
    end

    RubyCI.minitest_ws.on(:deq) do |api_tests|
      test_results
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



146
147
148
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 146

def method_missing(method, *args)
  return
end

Instance Attribute Details

#idsObject

Returns the value of attribute ids.



27
28
29
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 27

def ids
  @ids
end

#test_resultsObject

Returns the value of attribute test_results.



27
28
29
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 27

def test_results
  @test_results
end

#testsObject

Returns the value of attribute tests.



27
28
29
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 27

def tests
  @tests
end

Instance Method Details

#before_test(test) ⇒ Object



65
66
67
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 65

def before_test(test)
  $stdout = StringIO.new()
end

#get_outputObject



55
56
57
58
59
60
61
62
63
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 55

def get_output
  return if $stdout.pos == 0
  $stdout.rewind
  res = $stdout.read
  $stdout.flush
  $stdout.rewind
  return unless res
  res.strip.chomp if res.strip.chomp != ""
end

#passed?Boolean

Returns:

  • (Boolean)


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 121

def passed?
  results = []
  test_results.map do |path, file_results|
    file_results['1'].each do |id, test_result|
      next if id == :description
      if test_result[:status] == 'failed'
        results << false
      else
        results << true
      end
    end
  end

  pass = results.any? {|reult| !result }

  if pass
    @events << ['run_minitest'.upcase, { succeed_after: 1 }]
  else
    @events << ['run_minitest'.upcase, { failed_after: 1 }]
  end
  send_events if ENV['RBCI_REMOTE_TESTS'] == 'true'

  return pass
end

#prerecord(klass, name) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 69

def prerecord(klass, name)
  description = test_description(name)
  path = test_path(klass.name)

  test_results[path] ||= { run_time: 0.0, file_status: 'pending', test_count: 0, test_counters: { failed: 0, passed: 0, pending: 0 }, '1' => { description: klass.name } }
  test_results[path][:test_count] += 1

  id = (test_results[path]['1'].keys.size + 1).to_s
  ids[description] = id

  test_results[path]['1'][id] ||= { status: 'pending', description: description }
  test_results[path]['1'][id][:start] = Minitest.clock_time

  tests[path] ||= { run_time: 0.0, file_status: 'pending', test_count: 0, test_counters: { failed: 0, passed: 0, pending: 0 }, '1' => {} }
  tests[path][:test_count] += 1
  tests[path]['1'][id] ||= { status: 'pending' }
end

#record(result) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 87

def record(result)
  test_finished(result)
  description = test_description(result.name)
  id = ids[description]
  path = test_path(result.klass)

  test_results[path]['1'][id][:end] = Minitest.clock_time
  test_results[path]['1'][id][:run_time] = test_results[path]['1'][id][:end] - test_results[path]['1'][id][:start]
  test_results[path]['1'][id][:status] = result_status(result).to_s
  test_results[path][:test_counters][result_status(result)] += 1
  test_results[path][:run_time] += test_results[path]['1'][id][:run_time]
end

#reportObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 100

def report
  test_results.each do |path, file_results|
    file_status = 'pending'
    file_results['1'].each do |id, test_result|
      next if id == :description
      if (test_result[:status] == 'passed') && (file_status != 'failed')
        file_status = 'passed'
      elsif file_status == 'failed'
        file_status = 'failed'
      end
    end
    test_results[path][:file_status] = file_status
  end

  if ENV['RBCI_REMOTE_TESTS'] == 'true'
    send_events
  else
    RubyCI.minitest_await
  end
end

#startObject



48
49
50
51
52
53
# File 'lib/minitest/reporters/rubyci_reporter.rb', line 48

def start
  test_count = Runnable.runnables.sum { |s| s.runnable_methods.count }
  msg('start', { test_count: test_count })
  @events << ['run_minitest'.upcase, { started_at: Time.current }]
  send_events if ENV['RBCI_REMOTE_TESTS'] == 'true'
end