Sha256: 3bac8e442a1195a4ee167d15e170431d42fdbcdc78fae08742ec80a555e4b0de

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

require 'parallelized_specs/spec_logger_base'

class ParallelizedSpecs::TrendingExampleFailures < ParallelizedSpecs::SpecLoggerBase
  def initialize(*args)
    @output ||= args[1] || args[0] # rspec 1 has output as second argument
    @hudson_build_info = File.read("#{RAILS_ROOT}/spec/build_info.txt")
    if String === @output # a path ?
      FileUtils.mkdir_p(File.dirname(@output))
      @output = File.open(@output, 'a+')
    elsif File === @output # close and restart in append mode
      @output.close
      @output = File.open(@output.path, 'a+')
    end
  end

  def example_failed(example, counter, failure)
    if RSPEC_1
      if example.location != nil  && failure != nil
        backtrace_tweaker.tweak_backtrace(error)
        @failed_examples ||= {}
        @failed_examples["#{example.location.match(/spec.*\d/).to_s}*"] = ["#{example.description}*", "#{failure.header}*", "#{failure.exception.to_s.gsub(/\n/,"")}*", "#{failure.exception.backtrace.to_s.gsub(/\n/,"")}*", "#{Date.today}*", "#{@hudson_build_info}"]
      end
    end
  end

  # RSpec 1: dumps 1 failed spec
  def dump_failure(*args)
  end

  # RSpec 2: dumps all failed specs
  def dump_failures(*args)
  end

  def dump_summary(*args)
    lock_output do
      (@failed_examples||{}).each_pair do |example, details|
        @output.puts "#{example}#{details}"
      end
      @output.flush
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
parallelized_specs-0.3.08 lib/parallelized_specs/trending_example_failures_logger.rb
parallelized_specs-0.3.04 lib/parallelized_specs/trending_example_failures_logger.rb