Class: RSpec::Core::Formatters::Dots

Inherits:
BaseTextFormatter
  • Object
show all
Defined in:
lib/dots_formatter/dots.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#debugObject

Returns the value of attribute debug.



11
12
13
# File 'lib/dots_formatter/dots.rb', line 11

def debug
  @debug
end

#example_startObject

Returns the value of attribute example_start.



11
12
13
# File 'lib/dots_formatter/dots.rb', line 11

def example_start
  @example_start
end

#failsObject

Returns the value of attribute fails.



11
12
13
# File 'lib/dots_formatter/dots.rb', line 11

def fails
  @fails
end

#passesObject

Returns the value of attribute passes.



11
12
13
# File 'lib/dots_formatter/dots.rb', line 11

def passes
  @passes
end

#pendingsObject

Returns the value of attribute pendings.



11
12
13
# File 'lib/dots_formatter/dots.rb', line 11

def pendings
  @pendings
end

#runsObject

Returns the value of attribute runs.



11
12
13
# File 'lib/dots_formatter/dots.rb', line 11

def runs
  @runs
end

#screen_widthObject

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_timeObject

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


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