Sha256: 6b49df85b950241972abb2c61a1129487965a322dc7e5927a81bf5ff59d010e0

Contents?: true

Size: 1.31 KB

Versions: 17

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

  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 "\e[#{colors[state]}m" if color_enabled?
    yield
    output.print "\e[0m"
  end

  def state
    @state ||= :green
  end

  def colors
    { :red => 31, :green => 32, :yellow => 33 }
  end

end

Version data entries

17 entries across 12 versions & 3 rubygems

Version Path
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
rails-uploader-0.0.1 vendor/bundle/ruby/1.9.1/gems/fuubar-1.0.0/lib/fuubar.rb
fuubar-1.0.0 lib/fuubar.rb
fuubar-1.0.0.rc1 lib/fuubar.rb
fuubar-0.0.6 lib/fuubar.rb
fuubar-0.0.5 lib/fuubar.rb
fuubar-0.0.4 lib/fuubar.rb