Module: Neospec::Report::BuildkiteAnalytics

Defined in:
lib/neospec/report/buildkite_analytics.rb

Class Method Summary collapse

Class Method Details

.call(results, output: File.open("./test-analytics.json", "w")) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/neospec/report/buildkite_analytics.rb', line 4

def self.call(results, output: File.open("./test-analytics.json", "w"))
  analytics = results.specs.map do |result|
    scope = result.description.split(" ").first.split(".").first.split("#").first
    {
      scope: scope,
      name: result.description,
      identifier: result.description,
      location: result.location,
      file_name: result.file_name,
      result: (result.successful? ? "passed" : "failed"),
      failure_reason: (
        result.failures.map(&:message).join(" ") unless result.successful?
      ),
      history: {
        duration: "%.6f" % [result.duration]
      }
    }
  end

  output.write(analytics.to_json)
ensure
  output.close
end