Sha256: e72ae8c21e5d0a0868acecceddacaf6e3e183945ef54073f85fc013ce51e4ae1

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'rspec/core/formatters/base_text_formatter'
require 'progressbar'
require 'rspec/instafail'

class Fuubar < RSpec::Core::Formatters::BaseTextFormatter

  attr_reader :example_count, :finished_count
  COLORS = { :green =>  "\e[32m", :yellow => "\e[33m", :red => "\e[31m" }

  def start(example_count)
    @example_count = example_count
    @finished_count = 0
    @progress_bar = ProgressBar.new("  #{example_count} examples", example_count, output)
    @progress_bar.bar_mark = '='
  end

  def increment
    with_color do
      @finished_count += 1
      @progress_bar.instance_variable_set("@title", "  #{finished_count}/#{example_count}")
      @progress_bar.inc
    end
  end

  def example_passed(example)
    super
    increment
  end

  def example_pending(example)
    super
    @state = :yellow unless @state == :red
    increment
  end

  def example_failed(example)
    super
    @state = :red

    output.print "\e[K"
    instafail.example_failed(example)
    output.puts

    increment
  end

  def start_dump
    with_color { @progress_bar.finish }
  end

  def dump_failures
    # don't!
  end

  def instafail
    @instafail ||= RSpec::Instafail.new(output)
  end

  def with_color
    output.print COLORS[state] if color_enabled?
    yield
    output.print "\e[0m"
  end

  def state
    @state ||= :green
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fuubar-0.0.3 lib/fuubar.rb