Class: Fuubar

Inherits:
Spec::Runner::Formatter::BaseTextFormatter
  • Object
show all
Defined in:
lib/fuubar.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#example_countObject (readonly)

Returns the value of attribute example_count.



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

def example_count
  @example_count
end

#finished_countObject (readonly)

Returns the value of attribute finished_count.



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

def finished_count
  @finished_count
end

Instance Method Details

#dump_failuresObject



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

def dump_failures
  # don't!
end

#example_failed(example, counter, message) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/fuubar.rb', line 36

def example_failed(example, counter, message)
  super
  @state = :red

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

  increment
end

#example_passed(example) ⇒ Object



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

def example_passed(example)
  super
  increment
end

#example_pending(example, message) ⇒ Object



30
31
32
33
34
# File 'lib/fuubar.rb', line 30

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

#incrementObject



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

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

#instafailObject



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

def instafail
  @instafail ||= RSpec::Instafail.new(@options, output)
  #since instafail won't be able to get the current example_group it must be
  #updated every time
  @instafail.example_group_started(example_group)
  @instafail
end

#start(example_count) ⇒ Object



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

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

#start_dumpObject



47
48
49
# File 'lib/fuubar.rb', line 47

def start_dump
  with_color { @progress_bar.finish }
end

#stateObject



69
70
71
# File 'lib/fuubar.rb', line 69

def state
  @state ||= :green
end

#with_colorObject



63
64
65
66
67
# File 'lib/fuubar.rb', line 63

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