Module: Bacon::SpecDoxOutput
- Defined in:
- lib/pretty_bacon/spec_dox_output.rb
Overview
Overrides the SpecDoxzRtput to provide colored output by default
Based on github.com/zen-cms/Zen-Core and subsequently modified which is available under the MIT License. Thanks YorickPeterse!
Instance Method Summary collapse
-
#handle_requirement(description, disabled = false) ⇒ Object
:nodoc:.
- #handle_specification(name) ⇒ Object
-
#handle_summary ⇒ Object
:nodoc:.
-
#spaces ⇒ Object
:nodoc:.
Instance Method Details
#handle_requirement(description, disabled = false) ⇒ Object
:nodoc:
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pretty_bacon/spec_dox_output.rb', line 28 def handle_requirement(description, disabled = false) start_time = Time.now.to_f error = yield elapsed_time = ((Time.now.to_f - start_time) * 1000).round if !error.empty? puts PrettyBacon.color(:red, "#{spaces}- #{description} [FAILED]") elsif disabled puts PrettyBacon.color(:yellow, "#{spaces}- #{description} [DISABLED]") else time_color = case elapsed_time when 0..200 :none when 200..500 :yellow else :red end if elapsed_time <= 1 elapsed_time_string = '' elsif elapsed_time >= 1000 elapsed_time_string = "(#{'%.1f' % (elapsed_time/1000.0)} s)" else elapsed_time_string = "(#{elapsed_time} ms)" end elapsed_time_string = PrettyBacon.color(time_color, " #{elapsed_time_string}") unless elapsed_time_string == '' puts PrettyBacon.color(:green, "#{spaces}✓ ") + "#{description}" + elapsed_time_string end end |
#handle_specification(name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pretty_bacon/spec_dox_output.rb', line 12 def handle_specification(name) if @needs_first_put @needs_first_put = false puts end @specs_depth = @specs_depth || 0 puts spaces + name @specs_depth += 1 yield @specs_depth -= 1 puts if @specs_depth.zero? end |
#handle_summary ⇒ Object
:nodoc:
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pretty_bacon/spec_dox_output.rb', line 62 def handle_summary print ErrorLog if Backtraces unless Counter[:disabled].zero? puts PrettyBacon.color(:yellow, "#{Counter[:disabled]} disabled specifications\n") end result = "%d specifications (%d requirements), %d failures, %d errors" % Counter.values_at(:specifications, :requirements, :failed, :errors) if Counter[:failed].zero? && Counter[:errors].zero? puts PrettyBacon.color(:green, result) else puts PrettyBacon.color(:red, result) end end |
#spaces ⇒ Object
:nodoc:
77 78 79 |
# File 'lib/pretty_bacon/spec_dox_output.rb', line 77 def spaces return ' ' * @specs_depth end |