Sha256: 77833616ce508850161c497887b5e7ebc682e5173910d00d53f7872456a1fe21

Contents?: true

Size: 942 Bytes

Versions: 1

Compression:

Stored size: 942 Bytes

Contents

require_relative '../abstract_result'

module CircleCI
  module CoverageReporter
    module SimpleCov
      class BuildResult < AbstractResult
        # @param build [Build]
        def initialize(build)
          @build = build
        end

        # @note Implement {AbstractResult#coverage}
        # @return [Float]
        def coverage
          last_run_json = find_artifact('.last_run.json') or return Float::NaN
          JSON.parse(last_run_json.body)['result']['covered_percent']
        end

        # @note Implement {AbstractResult#url}
        # @return [String]
        def url
          index_html = find_artifact('index.html') or return '#'
          index_html.url
        end

        private

        attr_reader :build

        # @param end_with [String]
        # @return [Artifact]
        def find_artifact(end_with)
          build.artifacts.find { |a| a.end_with?(end_with) }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
circleci-coverage_reporter-0.1.3 lib/circleci/coverage_reporter/simplecov/build_result.rb