Class: InspecRspecJson

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

Direct Known Subclasses

InspecRspecCli

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from InspecRspecMiniJson

#stop

Constructor Details

#initialize(*args) ⇒ InspecRspecJson

Returns a new instance of InspecRspecJson.



78
79
80
81
82
# File 'lib/inspec/rspec_json_formatter.rb', line 78

def initialize(*args)
  super(*args)
  @profiles = []
  @backend = nil
end

Instance Attribute Details

#backend=(value) ⇒ Object (writeonly)

Sets the attribute backend

Parameters:

  • value

    the value to set the attribute backend to.



76
77
78
# File 'lib/inspec/rspec_json_formatter.rb', line 76

def backend=(value)
  @backend = value
end

Instance Method Details

#add_profile(profile) ⇒ Object



84
85
86
# File 'lib/inspec/rspec_json_formatter.rb', line 84

def add_profile(profile)
  @profiles.push(profile)
end

#dump_one_example(example, control) ⇒ Object



88
89
90
91
92
93
# File 'lib/inspec/rspec_json_formatter.rb', line 88

def dump_one_example(example, control)
  control[:results] ||= []
  example.delete(:id)
  example.delete(:profile_id)
  control[:results].push(example)
end

#dump_summary(summary) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/inspec/rspec_json_formatter.rb', line 100

def dump_summary(summary)
  super(summary)
  examples = @output_hash.delete(:controls)
  profiles = Hash[@profiles.map { |x| profile_info(x) }]
  missing = []

  examples.each do |example|
    control = example2control(example, profiles)
    next missing.push(example) if control.nil?
    dump_one_example(example, control)
  end

  @output_hash[:profiles] = profiles
  @output_hash[:other_checks] = missing
end

#profile_info(profile) ⇒ Object



95
96
97
98
# File 'lib/inspec/rspec_json_formatter.rb', line 95

def profile_info(profile)
  info = profile.info.dup
  [info[:name], info]
end