Class: Rbar::Bar

Inherits:
RSpec::Core::Formatters::BaseTextFormatter
  • Object
show all
Defined in:
lib/rbar/bar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#failed_barObject

Returns the value of attribute failed_bar.



131
132
133
# File 'lib/rbar/bar.rb', line 131

def failed_bar
  @failed_bar
end

#pass_barObject

Returns the value of attribute pass_bar.



131
132
133
# File 'lib/rbar/bar.rb', line 131

def pass_bar
  @pass_bar
end

#pending_barObject

Returns the value of attribute pending_bar.



131
132
133
# File 'lib/rbar/bar.rb', line 131

def pending_bar
  @pending_bar
end

Instance Method Details

#dump_failures(notifi) ⇒ Object



51
52
53
# File 'lib/rbar/bar.rb', line 51

def dump_failures(notifi)
  @failed = notifi.fully_formatted_failed_examples
end

#dump_pending(_notifi) ⇒ Object



55
# File 'lib/rbar/bar.rb', line 55

def dump_pending(_notifi); end

#dump_summary(notifi) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/rbar/bar.rb', line 91

def dump_summary(notifi)
  box = TTY::Box.frame(title: { top_left: " Seed #{@seed}" }, width: TTY::Screen.width, padding: 1) do
    string = @failed
    string << print_summary(notifi)
  end
  puts
  puts
  puts box
end

#example_failed(_notification) ⇒ Object



46
47
48
49
# File 'lib/rbar/bar.rb', line 46

def example_failed(_notification)
  failed_bar.increment
  print @string
end

#example_passed(_notification) ⇒ Object



36
37
38
39
# File 'lib/rbar/bar.rb', line 36

def example_passed(_notification)
  pass_bar.increment
  print @string
end

#example_pending(_notification) ⇒ Object



41
42
43
44
# File 'lib/rbar/bar.rb', line 41

def example_pending(_notification)
  pending_bar.increment
  print @string
end


70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rbar/bar.rb', line 70

def print_failures(failed_examples)
  failures = failed_examples.group_by { |failure| failure.example.example_group.description }

  formatted_failures = failures.transform_values do |group_failures|
    group_failures.map do |failure|
      { failure.description =>
        failure.message_lines.map(&:strip) }
    end
  end

  TTY::Tree.new(formatted_failures)
end


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rbar/bar.rb', line 57

def print_pending(pending_examples)
  pending = pending_examples.group_by { |pending| pending.example_group.description }

  formatted_pending = pending.transform_values do |group_pending|
    group_pending.map do |example|
      { example.description =>
      example.execution_result.pending_message }
    end
  end

  tree = TTY::Tree.new(formatted_pending)
end


101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rbar/bar.rb', line 101

def print_summary(notifi)
  table = TTY::Table.new(orientation: :horizontal, padding: 2) do |t|
    t << ['Examples', notifi.example_count]
    t << ['Failed', notifi.failure_count]
    t << ['Pending', notifi.pending_count]
  end

  table.render(:unicode, width: TTY::Screen.width) do |renderer|
    renderer.border.style = result_color
    renderer.border.separator = :each_row
    renderer.padding = 1
    renderer.render
  end
end

#progress_barObject



127
128
129
# File 'lib/rbar/bar.rb', line 127

def progress_bar
  @progress_bar ||= TTY::ProgressBar::Multi.new(width: width, clear: true)
end

#result_colorObject



116
117
118
119
120
121
# File 'lib/rbar/bar.rb', line 116

def result_color
  return :red if failed_bar.progress > 0
  return :yellow if pending_bar.progress > 0

  :green
end

#seed(notifi) ⇒ Object



83
84
85
# File 'lib/rbar/bar.rb', line 83

def seed(notifi)
  @seed = notifi.seed
end

#start(notification) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/rbar/bar.rb', line 28

def start(notification)
  super

  self.total = notification.count
  puts
  register_sub_bars
end

#stop(notifi) ⇒ Object



123
124
125
# File 'lib/rbar/bar.rb', line 123

def stop(notifi)
  @failure_notifications = notifi.failure_notifications
end

#widthObject



87
88
89
# File 'lib/rbar/bar.rb', line 87

def width
  TTY::Screen.width * 0.75
end