Sha256: 0cacd131188eeeed40303935367a97a3216fd7ff3b83f1970c0f05d76e81ef2d

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

class RspecGithubActionsSummary
  class ExampleGroup
    attr_reader :file_path

    def initialize(file_path)
      @file_path = file_path
    end

    def write_row
      [
        passed? ? '✅ Pass' : '❌ Failed',
        json['passed_specs'],
        json['failed_specs'],
        json['skipped_specs'],
        json['total_specs'],
        duration
      ]
    end

    def render_failed_examples
      return [] if json['failed'].empty?

      json['failed'].map do |j|
        "bin/rspec #{j["path"]} # #{j["desc"]}"
      end
    end

    private

    def duration
      helper_humanize_secs(json['duration'])
    end

    def passed?
      json['failed_specs'].zero?
    end

    def json
      @json ||= JSON.parse(File.read(file_path))
    end

    def helper_humanize_secs(secs)
      [[60, :seconds], [60, :minutes], [24, :hours], [Float::INFINITY, :days]].map do |count, name|
        next unless secs.positive?

        secs, n = secs.divmod(count)

        "#{n.to_i} #{name}" unless n.to_i.zero?
      end.compact.reverse.join(' ')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-github-actions-summary-0.1.0 lib/rspec_github_actions_summary/example_group.rb