Class: SelfieFormatter
- Inherits:
-
Object
show all
- Includes:
- Selfie
- Defined in:
- lib/selfie_formatter.rb
Constant Summary
collapse
- DEFAULT_COLUMNS =
80
Constants included
from Selfie
Selfie::Error, Selfie::VERSION
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(output, options = {}) ⇒ SelfieFormatter
Returns a new instance of SelfieFormatter.
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/selfie_formatter.rb', line 26
def initialize(output, options = {})
raise ArgumentError, "can only render to a terminal" unless output.tty?
@output = output
@options = options
@cursor = Cursor.new(@output)
@camera = Camera.new(photo_dir)
@columns = `stty size 2>/dev/null`.split(" ").last.to_i
@columns = DEFAULT_COLUMNS if @columns == 0
@offset = 1
@spec_count = 0
@failed = {}
@pending = {}
@main_img_height = nil
@main_img_width = nil
end
|
Class Method Details
.output_directory ⇒ Object
18
19
20
|
# File 'lib/selfie_formatter.rb', line 18
def self.output_directory
@output_directory ||= RSpec.configuration.selfie_output_directory || File.join(Dir.pwd, "selfies")
end
|
.output_directory=(path) ⇒ Object
22
23
24
|
# File 'lib/selfie_formatter.rb', line 22
def self.output_directory=(path)
@output_directory = path
end
|
Instance Method Details
#close(n) ⇒ Object
66
67
68
69
|
# File 'lib/selfie_formatter.rb', line 66
def close(n)
@cursor.show
@output.flush
end
|
#dump_failures(notification) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/selfie_formatter.rb', line 99
def dump_failures(notification)
if notification.failure_notifications.any?
@output << "\nFailures:\n"
dump_notifications(notification.failure_notifications, @failed)
end
end
|
#dump_pending(notification) ⇒ Object
92
93
94
95
96
97
|
# File 'lib/selfie_formatter.rb', line 92
def dump_pending(notification)
if notification.pending_notifications.any?
@output << "\nPending:\n"
dump_notifications(notification.pending_notifications, @pending)
end
end
|
#dump_summary(summary) ⇒ Object
106
107
108
|
# File 'lib/selfie_formatter.rb', line 106
def dump_summary(summary)
@output.puts summary.fully_formatted
end
|
#example_failed(notification) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/selfie_formatter.rb', line 76
def example_failed(notification)
image = capture("red")
return unless image
@failed[notification.example] = image
display_progess(image)
end
|
#example_passed(notification) ⇒ Object
71
72
73
74
|
# File 'lib/selfie_formatter.rb', line 71
def example_passed(notification)
image = capture("green")
display_progess(image) if image
end
|
#example_pending(notification) ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/selfie_formatter.rb', line 84
def example_pending(notification)
image = capture("yellow")
return unless image
@pending[notification.example] = image
display_progess(image)
end
|
#start(notification) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/selfie_formatter.rb', line 47
def start(notification)
@camera.on
@cursor.hide
@cursor.clear_screen
@cursor.move_to(0, 0)
end
|
#stop(notification) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/selfie_formatter.rb', line 54
def stop(notification)
@camera.off
pos = @cursor.position
if pos && pos[1] != 1
@cursor.down(@main_img_height)
end
@output << "\n\n"
end
|