Class: Crspec::Formatters::ProgressFormatter
- Inherits:
-
Object
- Object
- Crspec::Formatters::ProgressFormatter
- Defined in:
- lib/crspec/formatters/progress_formatter.rb
Constant Summary collapse
- FLUSH_THRESHOLD =
64- FLUSH_INTERVAL =
0.2
Instance Method Summary collapse
- #example_failed(_example) ⇒ Object
- #example_passed(_example) ⇒ Object
- #example_pending(_example) ⇒ Object
- #finish ⇒ Object
-
#initialize(output = $stdout, color: output.respond_to?(:tty?) && output.tty?) ⇒ ProgressFormatter
constructor
A new instance of ProgressFormatter.
- #start ⇒ Object
Constructor Details
#initialize(output = $stdout, color: output.respond_to?(:tty?) && output.tty?) ⇒ ProgressFormatter
Returns a new instance of ProgressFormatter.
9 10 11 12 13 14 15 |
# File 'lib/crspec/formatters/progress_formatter.rb', line 9 def initialize(output = $stdout, color: output.respond_to?(:tty?) && output.tty?) @output = output @color = color @mutex = Mutex.new @buffer = +"" @last_flush = Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
Instance Method Details
#example_failed(_example) ⇒ Object
21 22 23 |
# File 'lib/crspec/formatters/progress_formatter.rb', line 21 def example_failed(_example) record(@color ? "\e[31mF\e[0m" : "F") end |
#example_passed(_example) ⇒ Object
17 18 19 |
# File 'lib/crspec/formatters/progress_formatter.rb', line 17 def example_passed(_example) record(@color ? "\e[32m.\e[0m" : ".") end |
#example_pending(_example) ⇒ Object
25 26 27 |
# File 'lib/crspec/formatters/progress_formatter.rb', line 25 def example_pending(_example) record(@color ? "\e[33m*\e[0m" : "*") end |
#finish ⇒ Object
33 34 35 36 37 38 |
# File 'lib/crspec/formatters/progress_formatter.rb', line 33 def finish chunk = @mutex.synchronize { swap_buffer } @output.print(chunk) unless chunk.empty? @output.puts @output.flush end |
#start ⇒ Object
29 30 31 |
# File 'lib/crspec/formatters/progress_formatter.rb', line 29 def start @last_flush = Process.clock_gettime(Process::CLOCK_MONOTONIC) end |