Class: Fuubar

Inherits:
RSpec::Core::Formatters::BaseTextFormatter
  • Object
show all
Defined in:
lib/fuubar.rb

Instance Method Summary collapse

Instance Method Details

#colorsObject



66
67
68
# File 'lib/fuubar.rb', line 66

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

#dump_failuresObject



40
41
42
# File 'lib/fuubar.rb', line 40

def dump_failures
  # don't!
end

#example_failed(example) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/fuubar.rb', line 29

def example_failed(example)
  super
  @state = :red

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

  increment
end

#example_passed(example) ⇒ Object



18
19
20
21
# File 'lib/fuubar.rb', line 18

def example_passed(example)
  super
  increment
end

#example_pending(example) ⇒ Object



23
24
25
26
27
# File 'lib/fuubar.rb', line 23

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

#incrementObject



12
13
14
15
16
# File 'lib/fuubar.rb', line 12

def increment
  with_color do
    @progress_bar.increment
  end
end

#instafailObject



52
53
54
# File 'lib/fuubar.rb', line 52

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

#message(string) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/fuubar.rb', line 44

def message(string)
  if @progress_bar.respond_to? :log
    @progress_bar.log(string)
  else
    super
  end
end

#start(example_count) ⇒ Object



7
8
9
10
# File 'lib/fuubar.rb', line 7

def start(example_count)
  super
  @progress_bar   = ProgressBar.create(:format => ' %c/%C |%w>%i| %e ', :total => example_count, :output => output)
end

#stateObject



62
63
64
# File 'lib/fuubar.rb', line 62

def state
  @state ||= :green
end

#with_colorObject



56
57
58
59
60
# File 'lib/fuubar.rb', line 56

def with_color
  output.print "\e[#{colors[state]}m" if color_enabled?
  yield
  output.print "\e[0m" if color_enabled?
end