Class: Fuubar

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

Defined Under Namespace

Classes: Output

Constant Summary collapse

DEFAULT_PROGRESS_BAR_OPTIONS =
{ :format => ' %c/%C |%w>%i| %e ' }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Fuubar

Returns a new instance of Fuubar.



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

def initialize(*args)
  super

  self.example_tick_lock = Mutex.new
  self.progress = ProgressBar.create(
                    DEFAULT_PROGRESS_BAR_OPTIONS
                      .merge(:throttle_rate => continuous_integration? ? 1.0 : nil)
                      .merge(:total     => 0,
                             :output    => output,
                             :autostart => false)
  )
end

Instance Attribute Details

#example_tick_lockObject

Returns the value of attribute example_tick_lock.



22
23
24
# File 'lib/fuubar.rb', line 22

def example_tick_lock
  @example_tick_lock
end

#example_tick_threadObject

Returns the value of attribute example_tick_thread.



22
23
24
# File 'lib/fuubar.rb', line 22

def example_tick_thread
  @example_tick_thread
end

#failed_countObject

Returns the value of attribute failed_count.



22
23
24
# File 'lib/fuubar.rb', line 22

def failed_count
  @failed_count
end

#passed_countObject

Returns the value of attribute passed_count.



22
23
24
# File 'lib/fuubar.rb', line 22

def passed_count
  @passed_count
end

#pending_countObject

Returns the value of attribute pending_count.



22
23
24
# File 'lib/fuubar.rb', line 22

def pending_count
  @pending_count
end

#progressObject

Returns the value of attribute progress.



22
23
24
# File 'lib/fuubar.rb', line 22

def progress
  @progress
end

Instance Method Details

#close(_notification) ⇒ Object



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

def close(_notification)
  example_tick_thread.kill
end

#dump_failures(_notification) ⇒ Object



111
112
113
114
115
116
# File 'lib/fuubar.rb', line 111

def dump_failures(_notification)
  #
  # We output each failure as it happens so we don't need to output them en
  # masse at the end of the run.
  #
end

#example_failed(notification) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/fuubar.rb', line 86

def example_failed(notification)
  self.failed_count += 1

  progress.clear

  output.puts notification.fully_formatted(failed_count)
  output.puts

  increment
end

#example_passed(_notification) ⇒ Object



74
75
76
77
78
# File 'lib/fuubar.rb', line 74

def example_passed(_notification)
  self.passed_count += 1

  increment
end

#example_pending(_notification) ⇒ Object



80
81
82
83
84
# File 'lib/fuubar.rb', line 80

def example_pending(_notification)
  self.pending_count += 1

  increment
end

#example_tick(_notification) ⇒ Object



97
98
99
100
101
# File 'lib/fuubar.rb', line 97

def example_tick(_notification)
  example_tick_lock.synchronize do
    refresh
  end
end

#message(notification) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/fuubar.rb', line 103

def message(notification)
  if progress.respond_to? :log
    progress.log(notification.message)
  else
    super
  end
end

#outputObject



118
119
120
# File 'lib/fuubar.rb', line 118

def output
  @fuubar_output ||= Fuubar::Output.new(super, configuration.tty?)
end

#start(notification) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fuubar.rb', line 42

def start(notification)
  progress_bar_options = DEFAULT_PROGRESS_BAR_OPTIONS
                           .merge(:throttle_rate => continuous_integration? ? 1.0 : nil)
                           .merge(configuration.fuubar_progress_bar_options)
                           .merge(:total     => notification.count,
                                  :output    => output,
                                  :autostart => false)

  self.progress            = ProgressBar.create(progress_bar_options)
  self.passed_count        = 0
  self.pending_count       = 0
  self.failed_count        = 0
  self.example_tick_thread = start_tick_thread(notification)

  if Object.const_defined?('Pry')
    Pry
      .config
      .hooks
      .add_hook(:when_started, :fuubar_kill_refresh) do |_target, _opt, _|
        example_tick_thread.kill
      end
  end

  super

  with_current_color { progress.start }
end