class RspecFailsafeFormatter

Constants

Color

Attributes

failed_notifications[R]
output[R]

Public Class Methods

new(output) click to toggle source
# File lib/rspec_failsafe_formatter.rb, line 19
def initialize(output)
  FileUtils::mkdir_p 'target/failsafe-reports'
  @out_file = File.new('target/failsafe-reports/rspec.txt', 'w')
  @output = TeeIO.new(output, @out_file)
  @group_level = 0
  @index_offset = 0
  @failed_notifications = []
end

Public Instance Methods

close(notification) click to toggle source
# File lib/rspec_failsafe_formatter.rb, line 91
def close(notification)
  @out_file.close
end
dump_summary(notification) click to toggle source
# File lib/rspec_failsafe_formatter.rb, line 65
def dump_summary notification # SummaryNotification
  xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
    xml.send(:'failsafe-summary', timeout: false) {
      xml.completed notification.example_count
      xml.errors 0
      xml.failures notification.failure_count
      xml.skipped notification.pending_count
      if notification.failure_count > 0
        xml.failureMessage notification.failed_examples.first.exception.to_s
      else
        xml.failureMessage
      end
    }
  end

  file = File.new('target/failsafe-reports/failsafe-summary-rspec.xml', 'wb')
  file.write(xml.to_xml)
  file.close
  @output << "\n\nFinished in #{notification.duration.round(4)} seconds.\n\n"
end
example_failed(notification) click to toggle source
# File lib/rspec_failsafe_formatter.rb, line 38
def example_failed(notification)
  @failed_notifications << notification
  output.print Color.wrap('F', :failure)
end
example_group_finished(event) click to toggle source
# File lib/rspec_failsafe_formatter.rb, line 52
def example_group_finished(event)
  @group_level -= 1

  if @group_level.zero?
    failed_notifications.each_with_index do |failure, index|
      output.puts failure.fully_formatted(@index_offset + index + 1)
    end

    @index_offset += failed_notifications.size
    failed_notifications.clear
  end
end
example_group_started(event) click to toggle source
# File lib/rspec_failsafe_formatter.rb, line 43
def example_group_started(event)
  if @group_level.zero?
    output.print "#{event.group.description} "
    @start_time = Time.now
  end

  @group_level += 1
end
example_passed(notification) click to toggle source
# File lib/rspec_failsafe_formatter.rb, line 30
def example_passed(notification)
  output.print Color.wrap('.', :success)
end
example_pending(notification) click to toggle source
# File lib/rspec_failsafe_formatter.rb, line 34
def example_pending(notification)
  output.print Color.wrap('*', :pending)
end
seed(notification) click to toggle source
# File lib/rspec_failsafe_formatter.rb, line 86
def seed(notification)
  return unless notification.seed_used?
  output.puts notification.fully_formatted
end