Module: Elasticsearch::Tests::Printer
- Included in:
- CodeRunner
- Defined in:
- lib/elasticsearch/tests/printer.rb
Overview
Functions to print out test results, errors, summary, etc.
Class Method Summary collapse
Instance Method Summary collapse
- #print_error(error) ⇒ Object
- #print_failure(action, response) ⇒ Object
- #print_match_failure(action) ⇒ Object
- #print_success ⇒ Object
Class Method Details
.display_errors(errors) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/elasticsearch/tests/printer.rb', line 73 def self.display_errors(errors) puts "+++ โ Errors/Failures: #{errors.count}" errors.map do |error| puts "๐งช Test: #{error[:file]}" puts "โถ Action: #{error[:action].first}" if error[:action] puts "๐ฌ #{error.class} - #{error[:error].}" pp error[:error].backtrace.join("$/\n") if ENV['DEBUG'] puts end end |
.display_summary(tests_count, errors_count, start_time) ⇒ Object
84 85 86 87 88 |
# File 'lib/elasticsearch/tests/printer.rb', line 84 def self.display_summary(tests_count, errors_count, start_time) puts puts "--- ๐งช Tests: #{tests_count} | Passed: #{tests_count - errors_count} | Failed: #{errors_count}" puts "--- โฒ Elapsed time: #{Time.at(Time.now - start_time).utc.strftime("%H:%M:%S")}" end |
Instance Method Details
#print_error(error) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/elasticsearch/tests/printer.rb', line 65 def print_error(error) puts "โ ERROR: #{@short_name} #{@title} failed\n" logger.error error.display backtrace = error.backtrace.join("\n") logger.error "#{backtrace}\n" raise error end |
#print_failure(action, response) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elasticsearch/tests/printer.rb', line 38 def print_failure(action, response) puts "๐ด #{@short_name} #{@title} failed" puts "Expected result: #{action}" # TODO: Show match/length differently if defined?(ElasticsearchServerless) && response.is_a?(ElasticsearchServerless::API::Response) || defined?(Elasticsearch::API) && response.is_a?(Elasticsearch::API::Response) puts 'Response:' pp response.body else pp response end raise Elasticsearch::Tests::ActionError.new(response.body, @short_name, action) end |
#print_match_failure(action) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/elasticsearch/tests/printer.rb', line 52 def print_match_failure(action) keys = action['match'].keys.first value = action['match'].values.first = <<~MSG ๐ด #{@short_name} #{@title} failed Expected: { #{keys}: #{value} } Actual : { #{keys}: #{search_in_response(action['match'].keys.first)} } Response: #{@response} MSG raise Elasticsearch::Tests::TestFailure.new() end |
#print_success ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/elasticsearch/tests/printer.rb', line 25 def print_success response = if [true, false].include? @response @response else @response.status end if ENV['QUIET'] == 'true' print '๐ข ' else puts "๐ข #{@short_name} #{@title} passed. Response: #{response}" end end |