class Minitest::Docker::Reporter

Public Class Methods

new(_) click to toggle source
# File lib/minitest/docker/reporter.rb, line 4
def initialize(_)
  @containers = {}
end

Public Instance Methods

record(result) click to toggle source
# File lib/minitest/docker/reporter.rb, line 18
def record(result)
  return if result.passed? && !ENV['SAVE']

  ::Docker::Container.all.each do |container|
    container_name = container.info['Names'].min_by(&:length)

    test_name = result.name.gsub(/[^a-zA-Z0-9_.]/, '_')
    test_name.gsub!(/_+/, '_')

    tag = test_name + container_name
    container.commit.tag(repo: tag, force: true)

    @containers[result.name] ||= []
    @containers[result.name] << tag
  end
ensure
  result.run_command!(%w[docker-compose kill])
end
report() click to toggle source
# File lib/minitest/docker/reporter.rb, line 8
def report
  @containers.each do |test_name, containers|
    puts

    containers.each do |container|
      puts "Saved test container for #{test_name.inspect} as an image tagged: #{container}"
    end
  end
end