Class: Inspec::Formatters::Base
- Inherits:
- 
      RSpec::Core::Formatters::BaseFormatter
      
        - Object
- RSpec::Core::Formatters::BaseFormatter
- Inspec::Formatters::Base
 
- Defined in:
- lib/inspec/formatters/base.rb
Instance Attribute Summary collapse
- 
  
    
      #backend  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute backend. 
- 
  
    
      #run_data  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute run_data. 
Instance Method Summary collapse
- 
  
    
      #add_profile(profile)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Add the current profile to the list of executed profiles. 
- 
  
    
      #dump_summary(summary)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    RSpec Override: #dump_summary. 
- 
  
    
      #initialize(output)  ⇒ Base 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Base. 
- 
  
    
      #results  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return all the collected output to the caller. 
- 
  
    
      #stop(notification)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    RSpec Override: #stop. 
Constructor Details
#initialize(output) ⇒ Base
Returns a new instance of Base.
| 10 11 12 13 14 15 16 17 | # File 'lib/inspec/formatters/base.rb', line 10 def initialize(output) super(output) @run_data = {} @profiles = [] @profiles_info = nil @backend = nil end | 
Instance Attribute Details
#backend ⇒ Object
Returns the value of attribute backend.
| 8 9 10 | # File 'lib/inspec/formatters/base.rb', line 8 def backend @backend end | 
#run_data ⇒ Object
Returns the value of attribute run_data.
| 8 9 10 | # File 'lib/inspec/formatters/base.rb', line 8 def run_data @run_data end | 
Instance Method Details
#add_profile(profile) ⇒ Object
Add the current profile to the list of executed profiles. Called by the runner during example collection.
| 78 79 80 | # File 'lib/inspec/formatters/base.rb', line 78 def add_profile(profile) @profiles.push(profile) end | 
#dump_summary(summary) ⇒ Object
RSpec Override: #dump_summary
Supply run summary data, such as the InSpec version and the total duration.
| 22 23 24 25 26 27 28 | # File 'lib/inspec/formatters/base.rb', line 22 def dump_summary(summary) run_data[:version] = Inspec::VERSION run_data[:statistics] = { duration: summary.duration, controls: statistics, } end | 
#results ⇒ Object
Return all the collected output to the caller
| 83 84 85 | # File 'lib/inspec/formatters/base.rb', line 83 def results run_data end | 
#stop(notification) ⇒ Object
RSpec Override: #stop
Called at the end of a complete RSpec run. We use this to map tests to controls and flesh out the rest of the run_data hash to include details about the run, the platform, etc.
| 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # File 'lib/inspec/formatters/base.rb', line 35 def stop(notification) # This might be a bit confusing. The results are not actually organized # by control. It is organized by test. So if a control has 3 tests, the # output will have 3 control entries, each one with the same control id # and different test results. An rspec example maps to an inspec test. run_data[:controls] = notification.examples.map do |example| format_example(example).tap do |hash| e = example.exception next unless e if example.[:sensitive] hash[:message] = "*** sensitive output suppressed ***" else hash[:message] = (e) end next if e.is_a? RSpec::Expectations::ExpectationNotMetError hash[:exception] = e.class.name hash[:backtrace] = e.backtrace end end # include any tests that were run that were not part of a control run_data[:other_checks] = examples_without_controls examples_with_controls.each do |example| control = example2control(example) move_example_into_control(example, control) end # flesh out the profiles key with additional profile information run_data[:profiles] = profiles_info # add the platform information for this particular target run_data[:platform] = { name: platform(:name), release: platform(:release), target: backend_target, } end |