Sha256: 82cddb9b52b321b140ff18b8a4ef593b9b9c4728917e714f81da8541b7de61b3

Contents?: true

Size: 1.64 KB

Versions: 4

Compression:

Stored size: 1.64 KB

Contents

require 'rspec/core/formatters/base_formatter'
require 'json'

module RSpec
  module Core
    module Formatters
      class GorgonRspecFormatter < BaseFormatter
        if Formatters.respond_to? :register
          Formatters.register self, :message, :stop, :close
        end

        attr_reader :output

        def initialize(output)
          super
          @failures = []
        end

        def message(_notification)
        end

        def stop(notification=nil)
          @failures += failures(notification).map do |failure|
            {
              test_name: "#{failure.full_description}: line #{failure.metadata[:line_number]}",
              description: failure.description,
              full_description: failure.full_description,
              status: :failed,
              file_path: failure.metadata[:file_path],
              line_number: failure.metadata[:line_number],
            }.tap do |hash|
              exception = failure.exception
              unless exception.nil?
                hash[:class] = exception.class.name
                hash[:message] = exception.message
                hash[:location] = exception.backtrace
              end
            end
          end
        end

        def failures(notification)
          if !notification.nil?
            notification.examples.select { |e| e.execution_result.status == :failed }
          else
            examples.select { |e| e.execution_result[:status] == "failed" }
          end
        end

        def close(_notification=nil)
          output.write @failures.to_json
          output.close if IO === output && output != $stdout
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gorgon-0.11.1 lib/gorgon/gorgon_rspec_formatter.rb
gorgon-0.11.0 lib/gorgon/gorgon_rspec_formatter.rb
gorgon-0.10.5 lib/gorgon/gorgon_rspec_formatter.rb
gorgon-0.10.4 lib/gorgon/gorgon_rspec_formatter.rb