Sha256: a0f44b9af7285a11eb12234cae37beafbd2be72e520a23b3b807999771fc7c8b

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module FastCI
  class RspecFormatter
    attr_reader :current_test_key

    def initialize
      @output = {}
      @is_failed = false
    end

    def passed?
      !@is_failed
    end

    def current_test_key=(value)
      @current_test_key = value
    end

    def example_finished(notification)
      example =  notification.example
      metadata = example.metadata

      *example_group_ids, example_id = metadata[:scoped_id].split(":")

      file_output = @output[current_test_key] ||= {}

      example_group = example_group_ids.reduce(file_output) do |output, scope_id|
        output[scope_id] ||= {}
        output[scope_id]
      end

      example_group[example_id] = {
        run_time: example.execution_result.run_time,
        status: example.execution_result.status
      }

      if example.execution_result.status == :failed
        @is_failed = true
        example_group[example_id][:fully_formatted] =
          notification.fully_formatted(0, ::RSpec::Core::Formatters::ConsoleCodes)
      elsif metadata[:retry_attempts] && metadata[:retry_attempts] > 0
        example_group[example_id][:retry_attempts] = metadata[:retry_attempts]
        example_group[example_id][:fully_formatted] =
          example.set_exception metadata[:retry_exceptions].first.to_s
      end

      example_group[example_id]
    end

    def dump_and_reset
      output = @output
      @output = {}
      output
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fast_ci-1.0.11 lib/fast_ci/rspec_formatter.rb
fast_ci-1.0.10 lib/fast_ci/rspec_formatter.rb
fast_ci-1.0.9 lib/fast_ci/rspec_formatter.rb
fast_ci-1.0.8 lib/fast_ci/rspec_formatter.rb
fast_ci-1.0.7 lib/fast_ci/rspec_formatter.rb
fast_ci-1.0.6 lib/fast_ci/rspec_formatter.rb
fast_ci-1.0.5 lib/fast_ci/rspec_formatter.rb