Class: RSpec::Core::Formatters::Dots
- Inherits:
-
BaseTextFormatter
- Object
- BaseTextFormatter
- RSpec::Core::Formatters::Dots
- Defined in:
- lib/dots_formatter/dots.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#example_start ⇒ Object
Returns the value of attribute example_start.
-
#fails ⇒ Object
Returns the value of attribute fails.
-
#passes ⇒ Object
Returns the value of attribute passes.
-
#pendings ⇒ Object
Returns the value of attribute pendings.
-
#runs ⇒ Object
Returns the value of attribute runs.
-
#screen_width ⇒ Object
Returns the value of attribute screen_width.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
- #dump_failures(notification) ⇒ Object
- #dump_summary(summary) ⇒ Object
- #example_failed(example) ⇒ Object
- #example_passed(example) ⇒ Object
- #example_pending(example) ⇒ Object
- #example_started(example) ⇒ Object
-
#initialize(output) ⇒ Dots
constructor
A new instance of Dots.
- #print_progress(example, finish = false) ⇒ Object
- #start(notification) ⇒ Object
Constructor Details
#initialize(output) ⇒ Dots
Returns a new instance of Dots.
13 14 15 16 17 18 19 20 21 |
# File 'lib/dots_formatter/dots.rb', line 13 def initialize(output) @passes = 0 @fails = 0 @runs = 0 @pendings = 0 @screen_width = `tput cols`.to_i - 1 @debug = false super(output) end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
11 12 13 |
# File 'lib/dots_formatter/dots.rb', line 11 def debug @debug end |
#example_start ⇒ Object
Returns the value of attribute example_start.
11 12 13 |
# File 'lib/dots_formatter/dots.rb', line 11 def example_start @example_start end |
#fails ⇒ Object
Returns the value of attribute fails.
11 12 13 |
# File 'lib/dots_formatter/dots.rb', line 11 def fails @fails end |
#passes ⇒ Object
Returns the value of attribute passes.
11 12 13 |
# File 'lib/dots_formatter/dots.rb', line 11 def passes @passes end |
#pendings ⇒ Object
Returns the value of attribute pendings.
11 12 13 |
# File 'lib/dots_formatter/dots.rb', line 11 def pendings @pendings end |
#runs ⇒ Object
Returns the value of attribute runs.
11 12 13 |
# File 'lib/dots_formatter/dots.rb', line 11 def runs @runs end |
#screen_width ⇒ Object
Returns the value of attribute screen_width.
11 12 13 |
# File 'lib/dots_formatter/dots.rb', line 11 def screen_width @screen_width end |
#start_time ⇒ Object
Returns the value of attribute start_time.
11 12 13 |
# File 'lib/dots_formatter/dots.rb', line 11 def start_time @start_time end |
Instance Method Details
#dump_failures(notification) ⇒ Object
70 71 72 73 |
# File 'lib/dots_formatter/dots.rb', line 70 def dump_failures(notification) output.puts output.puts notification.fully_formatted_failed_examples if @fails > 0 end |
#dump_summary(summary) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dots_formatter/dots.rb', line 56 def dump_summary(summary) output.puts output.puts colour = (@fails == 0)? :success : :failure output.puts ConsoleCodes.wrap("┌" + "-".ljust(50,"-") + "┐", colour) output.puts ConsoleCodes.wrap("│ #{summary.example_count} test#{summary.example_count == 1? '' : 's'}".ljust(50) + " |", colour) output.puts ConsoleCodes.wrap("| #{@fails} failure#{@fails == 1? '' : 's'}".ljust(50) + " |", colour) output.puts ConsoleCodes.wrap("| Ran in #{Helpers.format_duration summary.duration}".ljust(50) + " |", colour) output.puts ConsoleCodes.wrap("└" + "-".ljust(50,"-") + "┘", colour) output.puts output.puts summary.colorized_rerun_commands if @fails > 0 end |
#example_failed(example) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/dots_formatter/dots.rb', line 46 def example_failed(example) @fails += 1 @runs += 1 failure = ConsoleCodes.wrap("\r Failed example: ", :failure) + ConsoleCodes.wrap(example.example.full_description, :white) output.puts failure[0..@screen_width].ljust(@screen_width) unless @debug print_progress(example, true) end |
#example_passed(example) ⇒ Object
40 41 42 43 44 |
# File 'lib/dots_formatter/dots.rb', line 40 def example_passed(example) @runs += 1 @passes += 1 print_progress(example, true) end |
#example_pending(example) ⇒ Object
34 35 36 37 38 |
# File 'lib/dots_formatter/dots.rb', line 34 def example_pending(example) @runs += 1 @pendings += 1 print_progress(example, true) end |
#example_started(example) ⇒ Object
29 30 31 32 |
# File 'lib/dots_formatter/dots.rb', line 29 def example_started(example) @example_start = Time.now print_progress(example) end |
#print_progress(example, finish = false) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/dots_formatter/dots.rb', line 75 def print_progress(example, finish = false) tot = ConsoleCodes.wrap("#{@example_count}", :white) fls = ConsoleCodes.wrap("#{fails}", :failure) suc = ConsoleCodes.wrap("#{@runs - @fails}", :success) png = ConsoleCodes.wrap("#{@pendings}", :pending) current_dur = Time.now - @start_time prev_dur = Time.now - @example_start tim = ConsoleCodes.wrap( "(Running #{Helpers.format_duration current_dur})", :cyan) dot = ConsoleCodes.wrap(" ● ", @fails == 0 ? :success : :failure) if @debug run = ConsoleCodes.wrap(" Just ran: #{example.example.description}, which took ", :cyan) tim2 = ConsoleCodes.wrap(Helpers.format_duration(prev_dur), :red) output.puts " #{dot}#{suc}:#{fls}:#{png}/#{tot}#{dot} #{run}#{tim2}" if finish else run = ConsoleCodes.wrap(" Now running: #{example.example.description}", :cyan) unless finish all = "\r #{dot}#{suc}:#{fls}:#{png} / #{tot}#{dot} #{tim} #{run}".ljust(@screen_width)+"\r" output.print all end end |
#start(notification) ⇒ Object
23 24 25 26 27 |
# File 'lib/dots_formatter/dots.rb', line 23 def start(notification) @start_time = Time.now @example_count = notification.count output.puts #new line end |