Class: Inferno::CLI::Execute::ConsoleOutputter
- Inherits:
-
Object
- Object
- Inferno::CLI::Execute::ConsoleOutputter
- Defined in:
- lib/inferno/apps/cli/execute/console_outputter.rb
Constant Summary collapse
- COLOR =
Pastel.new
- CHECKMARK =
"\u2713".freeze
- BAR =
('=' * 80).freeze
Instance Method Summary collapse
- #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
- #serialize(entity) ⇒ Object
-
#verbose_print(options, *args) ⇒ Object
private.
- #verbose_print_json_results(options, results) ⇒ Object
- #verbose_puts(options, *args) ⇒ Object
Instance Method Details
#format_inputs(result) ⇒ Object
98 99 100 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 98 def format_inputs(result) format_session_data(result, :input_json) end |
#format_messages(result) ⇒ Object
77 78 79 80 81 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 77 def (result) result..map do || "\n\t\t#{.type}: #{.}" end.join end |
#format_outputs(result) ⇒ Object
102 103 104 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 102 def format_outputs(result) format_session_data(result, :output_json) end |
#format_requests(result) ⇒ Object
83 84 85 86 87 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 83 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
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 106 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
89 90 91 92 93 94 95 96 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 89 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
65 66 67 68 69 70 71 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 65 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
73 74 75 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 73 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 28 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 24 def print_around_run() puts 'Running tests. This may take a while...' # TODO: spinner/progress bar yield end |
#print_end_message(options) ⇒ Object
47 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 47 def (); end |
#print_error(options, exception) ⇒ Object
49 50 51 52 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 49 def print_error(, exception) puts COLOR.red "Error: #{exception.}" verbose_print(, exception.backtrace&.join('\n')) end |
#print_results(options, results) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 30 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 #{[:suite]}" verbose_puts , "Running Groups #{[:groups]}" unless [:groups].blank? verbose_puts , "Running Tests #{[:tests]}" unless [:tests].blank? verbose_puts , "Running Entities #{[:short_ids]}" unless [:short_ids].blank? puts BAR end |
#serialize(entity) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 137 def serialize(entity) case entity.class.to_s when 'Array' JSON.pretty_generate(entity.map { |item| JSON.parse serialize(item) }) when lambda { |x| defined?(x.constantize) && defined?("Inferno::Web::Serializers::#{x.split('::').last}".constantize) } "Inferno::Web::Serializers::#{entity.class.to_s.split('::').last}".constantize.render(entity) else raise StandardError, "CLI does not know how to serialize #{entity.class}" end end |
#verbose_print(options, *args) ⇒ Object
private
56 57 58 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 56 def verbose_print(, *args) print(COLOR.dim(*args)) if [:verbose] end |
#verbose_print_json_results(options, results) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 129 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
60 61 62 63 |
# File 'lib/inferno/apps/cli/execute/console_outputter.rb', line 60 def verbose_puts(, *args) args.push("\n") verbose_print(, *args) end |