Created
June 15, 2017 19:42
-
-
Save uhlenbrock/aaad06e738a4488bf41a077a4154e1bf to your computer and use it in GitHub Desktop.
Aggregate minitest failures in S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Minitest | |
def self.plugin_aggregate_init | |
reporter << Aggregate.new | |
end | |
class Aggregate | |
attr_accessor :branch | |
attr_accessor :build | |
attr_accessor :failed_tests | |
attr_accessor :timestamp | |
def initialize | |
self.branch = ENV['CIRCLE_BRANCH'] | |
self.build = ENV['CIRCLE_BUILD_NUM'] | |
self.failed_tests = [] | |
self.timestamp = DateTime.current.strftime('%Y-%m-%d %H:%M:%S') | |
end | |
def passed? | |
true | |
end | |
def start; end | |
def record(result) | |
if result.failure.present? && !result.failure.is_a?(Minitest::Skip) | |
failed_tests << { | |
created_at: timestamp, | |
build: build, | |
test_class: CGI.escapeHTML(result.class.to_s), | |
test_name: CGI.escapeHTML(result.name), | |
}.to_json | |
end | |
end | |
def report | |
return if failed_tests.empty? | |
connection = Fog::Storage.new(AMAZON) | |
directory = connection.directories.new(key: 'BUCKETNAME') | |
directory.files.create(key: "#{build}.json", body: failed_tests.join("\r\n")) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment