Class: InspecRspecCli

Inherits:
InspecRspecJson show all
Defined in:
lib/inspec/rspec_json_formatter.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

STATUS_TYPES =
{
  'unknown'  => -3,
  'passed'   => -2,
  'skipped'  => -1,
  'minor'    => 1,
  'major'    => 2,
  'failed'   => 2.5,
  'critical' => 3,
}.freeze
COLORS =
{
  'critical' => "\033[31;1m",
  'major'    => "\033[31m",
  'minor'    => "\033[33m",
  'failed'   => "\033[31m",
  'passed'   => "\033[32m",
  'skipped'  => "\033[37m",
  'reset'    => "\033[0m",
}.freeze
INDICATORS =
{
  'critical' => '',
  'major'    => '',
  'minor'    => '',
  'failed'   => '',
  'skipped'  => '',
  'passed'   => '',
  'unknown'  => '  ?  ',
  'empty'    => '     ',
  'small'    => '   ',
}.freeze
MULTI_TEST_CONTROL_SUMMARY_MAX_LEN =
60

Instance Attribute Summary

Attributes inherited from InspecRspecJson

#backend

Instance Method Summary collapse

Methods inherited from InspecRspecJson

#add_profile, #controls_summary, #dump_one_example, #start, #stop, #tests_summary

Methods inherited from InspecRspecMiniJson

#dump_summary, #stop

Constructor Details

#initialize(*args) ⇒ InspecRspecCli

Returns a new instance of InspecRspecCli.



280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/inspec/rspec_json_formatter.rb', line 280

def initialize(*args)
  @colors = COLORS
  @indicators = INDICATORS

  @format = '%color%indicator%id%summary'
  @current_control = nil
  @current_profile = nil
  @missing_controls = []
  @anonymous_tests = []
  @control_tests = []
  @profile_printed = false
  super(*args)
end

Instance Method Details

#close(_notification) ⇒ Object

rubocop:disable Metrics/AbcSize



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/inspec/rspec_json_formatter.rb', line 294

def close(_notification) # rubocop:disable Metrics/AbcSize
  flush_current_control
  output.puts('') unless @current_control.nil?
  print_tests
  output.puts('')

  print_profiles_info if !@profile_printed
  controls_res = controls_summary
  tests_res = tests_summary

  s = format('Profile Summary: %s%d successful%s, %s%d failures%s, %s%d skipped%s',
             COLORS['passed'], controls_res['passed'], COLORS['reset'],
             COLORS['failed'], controls_res['failed']['total'], COLORS['reset'],
             COLORS['skipped'], controls_res['skipped'], COLORS['reset'])
  output.puts(s) if controls_res['total'] > 0

  s = format('Test Summary: %s%d successful%s, %s%d failures%s, %s%d skipped%s',
             COLORS['passed'], tests_res['passed'], COLORS['reset'],
             COLORS['failed'], tests_res['failed'], COLORS['reset'],
             COLORS['skipped'], tests_res['skipped'], COLORS['reset'])
  output.puts(s) if !@anonymous_tests.empty? || @current_control.nil?
end