Class: RSpec::RSpecOscalFormatter::SpecMetaDataParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_oscal_formatter/parse_spec_metadata.rb

Overview

Tiny helper class to provide easy access to the metadata attributes in the spec.

Constant Summary collapse

STATUS_MAP =
{
  passed: 'pass',
  failed: 'fail',
  pending: 'other',
}

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ SpecMetaDataParser

Returns a new instance of SpecMetaDataParser.



25
26
27
28
29
30
31
32
33
34
# File 'lib/rspec_oscal_formatter/parse_spec_metadata.rb', line 25

def initialize(example)
  validate_contents(example.) # TODO: - figure out a way to dump out if metadata isn't complete
  @output_directory = example.[:output_directory]
  @assessment_plan_uuid = example.[:assessment_plan_uuid]
  @control_id = example.[:control_id]
  @description = example.[:description]
  @statement_id = example.[:statement_id]
  @reason = STATUS_MAP[example.execution_result.status]
  @state = @reason == 'pass' ? 'satisfied' : 'not-satisfied'
end

Instance Method Details

#validate_contents(metadata) ⇒ Object



18
19
20
21
22
23
# File 'lib/rspec_oscal_formatter/parse_spec_metadata.rb', line 18

def validate_contents()
  # Make sure required attributes are present
  METADATA.each do |attribute|
    raise IndexError if attribute.nil?
  end
end