Class: Spectre::Logging::Console
- Defined in:
- lib/spectre/logging/console.rb
Instance Method Summary collapse
- #end_context(context) ⇒ Object
- #end_group(desc) ⇒ Object
- #end_spec(_spec, _data) ⇒ Object
-
#initialize(config) ⇒ Console
constructor
A new instance of Console.
- #log_debug(message) ⇒ Object
- #log_error(_spec, exception) ⇒ Object
- #log_info(message) ⇒ Object
- #log_process(desc) ⇒ Object
- #log_separator(desc) ⇒ Object
- #log_skipped(_spec, message = nil) ⇒ Object
- #log_status(_desc, status, annotation = nil) ⇒ Object
- #start_context(context) ⇒ Object
- #start_group(desc) ⇒ Object
- #start_spec(spec, data = nil) ⇒ Object
- #start_subject(subject) ⇒ Object
Constructor Details
#initialize(config) ⇒ Console
Returns a new instance of Console.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/spectre/logging/console.rb', line 6 def initialize config @indent = 2 @width = 80 if config.key? 'log_format' @config = config['log_format']['console'] || {} @indent = @config['indent'] || @indent @width = @config['width'] || @width @fmt_end_context = @config['end_context'] @fmt_sep = @config['separator'] @fmt_start_group = @config['start_group'] @fmt_end_group = @config['end_group'] end @process = nil @level = 0 end |
Instance Method Details
#end_context(context) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/spectre/logging/console.rb', line 35 def end_context context return unless context.__desc @level -= 1 puts (' ' * indent) + @fmt_end_context.gsub('<desc>', context.__desc).magenta if @fmt_end_context end |
#end_group(desc) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/spectre/logging/console.rb', line 69 def end_group desc if desc and @fmt_start_group desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group puts (' ' * indent) + desc.blue end @level -= 1 end |
#end_spec(_spec, _data) ⇒ Object
50 51 52 |
# File 'lib/spectre/logging/console.rb', line 50 def end_spec _spec, _data @level -= 1 end |
#log_debug(message) ⇒ Object
110 111 112 |
# File 'lib/spectre/logging/console.rb', line 110 def log_debug print_line(, Status::DEBUG.grey) end |
#log_error(_spec, exception) ⇒ Object
114 115 116 117 |
# File 'lib/spectre/logging/console.rb', line 114 def log_error _spec, exception txt = (Status::ERROR + ' - ' + exception.class.name).red print_line('', txt) end |
#log_info(message) ⇒ Object
106 107 108 |
# File 'lib/spectre/logging/console.rb', line 106 def log_info print_line(, Status::INFO.blue) end |
#log_process(desc) ⇒ Object
78 79 80 81 82 |
# File 'lib/spectre/logging/console.rb', line 78 def log_process desc print_line(desc) @process = desc @level += 1 end |
#log_separator(desc) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/spectre/logging/console.rb', line 54 def log_separator desc if desc desc = @fmt_sep.gsub('<indent>', ' ' * indent).gsub('<desc>', desc) if @fmt_sep puts desc.blue else puts end end |
#log_skipped(_spec, message = nil) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/spectre/logging/console.rb', line 119 def log_skipped _spec, =nil txt = Status::SKIPPED unless .nil? txt += ' - ' + end print_line('', txt.grey) end |
#log_status(_desc, status, annotation = nil) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/spectre/logging/console.rb', line 84 def log_status _desc, status, annotation=nil status = status.green if status == Status::OK status = status.blue if status == Status::INFO status = status.grey if status == Status::DEBUG status = status.red if status == Status::FAILED status = status.red if status == Status::ERROR status = status.grey if status == Status::SKIPPED txt = status txt += ' ' + annotation if annotation @level -= 1 if @process puts txt else print_line('', status) end @process = nil end |
#start_context(context) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/spectre/logging/console.rb', line 28 def start_context context return unless context.__desc puts (' ' * indent) + context.__desc.magenta @level += 1 end |
#start_group(desc) ⇒ Object
63 64 65 66 67 |
# File 'lib/spectre/logging/console.rb', line 63 def start_group desc desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group puts (' ' * indent) + desc.blue @level += 1 end |
#start_spec(spec, data = nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/spectre/logging/console.rb', line 42 def start_spec spec, data=nil text = spec.desc text += " with #{data}" if data puts (' ' * indent) + text.cyan @level += 1 end |
#start_subject(subject) ⇒ Object
24 25 26 |
# File 'lib/spectre/logging/console.rb', line 24 def start_subject subject puts subject.desc.blue end |