Class: RSpec::RSpecOscalFormatter::Formatter

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

Overview

Core class for the formatter

Constant Summary collapse

OUTPUT_DIRECTORY =

TODO: should be a property

Pathname.new('/tmp/oscal_outputs').freeze

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Formatter

Returns a new instance of Formatter.



20
21
22
# File 'lib/rspec_oscal_formatter.rb', line 20

def initialize(output)
  @output = output
end

Instance Method Details

#create_output_directoryObject

Generate a timestamped directory to save the file



25
26
27
28
29
30
# File 'lib/rspec_oscal_formatter.rb', line 25

def create_output_directory
  example_out_dir = OUTPUT_DIRECTORY.join(DateTime.now.iso8601)
  # We should raise an exception here if we can't create the directory
  example_out_dir.mkpath unless example_out_dir.exist? && example_out_dir.directory?
  example_out_dir
end

#example_finished(notification) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rspec_oscal_formatter.rb', line 32

def example_finished(notification)
   = SpecMetaDataParser.new(notification.example)

  out_dir = create_output_directory

  out_dir.join("#{.control_id}-assessment-plan.json").open('w').write(
    CreateAssessmentPlan.new().to_json,
  )

  out_dir.join("#{.control_id}-assessment-result.json").open('w').write(
    CreateAssessmentResult.new().to_json,
  )
end