Class: Inferno::CLI::Execute::ConsoleOutputter
- Inherits:
-
Object
- Object
- Inferno::CLI::Execute::ConsoleOutputter
- Includes:
- Serialize
- Defined in:
- lib/inferno/apps/cli/execute/console_outputter.rb
Direct Known Subclasses
Constant Summary collapse
- CHECKMARK =
"\u2713".freeze
- BAR =
('=' * 80).freeze
Instance Method Summary collapse
- #color ⇒ Object
- #format_inputs(result) ⇒ Object
- #format_messages(result) ⇒ Object
- #format_outputs(result) ⇒ Object
- #format_requests(result) ⇒ Object
-
#format_result(result) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #format_session_data(result, attr) ⇒ Object
- #format_tag(result) ⇒ Object
- #format_tag_suffix(result) ⇒ Object
- #print_around_run(_options) ⇒ Object
- #print_end_message(options) ⇒ Object
- #print_error(_options, exception) ⇒ Object
- #print_results(options, results) ⇒ Object
- #print_start_message(options) ⇒ Object
-
#verbose_print(options) ⇒ Object
private.
- #verbose_print_json_results(options, results) ⇒ Object
- #verbose_puts(options, *args) ⇒ Object
Methods included from Serialize
Instance Method Details
#color ⇒ Object
58 59 60 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 58 def color @color ||= Pastel.new(enabled: $stdout.tty?) end |
#format_inputs(result) ⇒ Object
100 101 102 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 100 def format_inputs(result) format_session_data(result, :input_json) end |
#format_messages(result) ⇒ Object
79 80 81 82 83 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 79 def (result) result..map do || "\n\t\t#{message.type}: #{message.message}" end.join end |
#format_outputs(result) ⇒ Object
104 105 106 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 104 def format_outputs(result) format_session_data(result, :output_json) end |
#format_requests(result) ⇒ Object
85 86 87 88 89 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 85 def format_requests(result) result.requests.map do |req_res| "\n\t\t#{req_res.status} #{req_res.verb.upcase} #{req_res.url}" end.join end |
#format_result(result) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 108 def format_result(result) # rubocop:disable Metrics/CyclomaticComplexity case result.result when 'pass' color.bold.green(CHECKMARK, ' pass') when 'fail' color.bold.red 'X fail' when 'skip' color.yellow '* skip' when 'omit' color.blue '* omit' when 'error' color.magenta 'X error' when 'wait' color.bold '. wait' when 'cancel' color.red 'X cancel' when 'running' color.bold '- running' else raise StandardError.new, "Unrecognized result #{result.result}" end end |
#format_session_data(result, attr) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 91 def format_session_data(result, attr) json = result.send(attr) return '' if json.nil? JSON.parse(json).map do |hash| "\n\t\t#{hash['name']}: #{hash['value']}" end.join end |
#format_tag(result) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 67 def format_tag(result) if result.runnable.respond_to?(:short_id) "#{result.runnable.short_id} #{format_tag_suffix(result)}" else format_tag_suffix(result) end end |
#format_tag_suffix(result) ⇒ Object
75 76 77 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 75 def format_tag_suffix(result) result.runnable.short_title.presence || result.runnable.title.presence || result.runnable.id end |
#print_around_run(_options) ⇒ Object
24 25 26 27 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 24 def print_around_run() puts 'Running tests. This may take a while...' yield end |
#print_end_message(options) ⇒ Object
46 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 46 def (); end |
#print_error(_options, exception) ⇒ Object
48 49 50 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 48 def print_error(, exception) puts color.red "Error: #{exception.full_message}" end |
#print_results(options, results) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 29 def print_results(, results) verbose_print_json_results(, results) puts BAR puts 'Test Results:' puts BAR results.each do |result| print format_tag(result), ': ', format_result(result), "\n" verbose_puts(, "\tsummary: ", result.) verbose_puts(, "\tmessages: ", (result)) verbose_puts(, "\trequests: ", format_requests(result)) verbose_puts(, "\tinputs: ", format_inputs(result)) verbose_puts(, "\toutputs: ", format_outputs(result)) end puts BAR end |
#print_start_message(options) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 14 def () puts '' puts BAR puts "Testing #{options[:suite]}" verbose_puts , "Running Groups #{options[:groups]}" unless [:groups].blank? verbose_puts , "Running Tests #{options[:tests]}" unless [:tests].blank? verbose_puts , "Running Entities #{options[:short_ids]}" unless [:short_ids].blank? puts BAR end |
#verbose_print(options) ⇒ Object
private
54 55 56 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 54 def verbose_print(, *) print(color.dim(*)) if [:verbose] end |
#verbose_print_json_results(options, results) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 131 def verbose_print_json_results(, results) verbose_puts(, BAR) verbose_puts(, 'JSON Test Results:') verbose_puts(, BAR) verbose_puts(, serialize(results)) verbose_puts(, BAR) end |
#verbose_puts(options, *args) ⇒ Object
62 63 64 65 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 62 def verbose_puts(, *args) args.push("\n") verbose_print(, *args) end |