class Minitest::BlinkaPlugin::Reporter

Attributes

tests[RW]

Public Class Methods

new(io = $stdout, options = {}) click to toggle source
Calls superclass method
# File lib/minitest/blinka_plugin.rb, line 18
def initialize(io = $stdout, options = {})
  super
  self.tests = []
end

Public Instance Methods

record(test) click to toggle source
Calls superclass method
# File lib/minitest/blinka_plugin.rb, line 23
def record(test)
  super
  tests << test
end
report() click to toggle source
Calls superclass method
# File lib/minitest/blinka_plugin.rb, line 28
def report
  super

  tap_report if ENV['BLINKA_TAP']
  json_report if ENV['BLINKA_JSON'] || ENV['BLINKA_REPORT']
  BlinkaClient.new.report if ENV['BLINKA_REPORT']
rescue BlinkaClient::BlinkaError => error
  puts(error)
end

Private Instance Methods

find_commit() click to toggle source
# File lib/minitest/blinka_plugin.rb, line 89
def find_commit
  ENV.fetch(
    'BLINKA_COMMIT',
    ENV.fetch(
      'HEROKU_TEST_RUN_COMMIT_VERSION',
      `git rev-parse HEAD`.chomp
    )
  )
end
json_report() click to toggle source
# File lib/minitest/blinka_plugin.rb, line 40
def json_report
  result = {
    total_time: total_time,
    nbr_tests: count,
    nbr_assertions: assertions,
    commit: find_commit,
    tag: ENV.fetch('BLINKA_TAG', ''),
    seed: options[:seed],
    results:
      tests.map { |test_result| BlinkaMinitest.new(test_result).report }
  }

  File.open('blinka_results.json', 'w+') do |file|
    file.write(JSON.pretty_generate(result))
  end
  puts
  puts('Test results written to `./blinka_results.json`')
end
print_padded_comment(line) click to toggle source
tap_report() click to toggle source

Based on github.com/kern/minitest-reporters/blob/master/lib/minitest/reporters/progress_reporter.rb Tries to adhere to testanything.org/tap-specification.html

# File lib/minitest/blinka_plugin.rb, line 61
def tap_report
  puts
  puts('TAP version 13')
  puts("1..#{tests.length}")
  tests.each_with_index do |test, index|
    blinka = BlinkaMinitest.new(test)
    test_str = "#{blinka.path} - #{test.name.tr('#', '_')}"
    if test.passed?
      puts "ok #{index + 1} - #{test_str}"
    elsif test.skipped?
      puts "ok #{index + 1} # skip: #{test_str}"
    elsif test.failure
      puts "not ok #{index + 1} - failed: #{test_str}"
      blinka.message.each_line { |line| print_padded_comment(line) }

      # test.failure.message.each_line { |line| print_padded_comment(line) }
      unless test.failure.is_a?(MiniTest::UnexpectedError)
        blinka.backtrace.each { |line| print_padded_comment(line) }
      end
      puts
    end
  end
end