feature: add rules with IDs

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-06-07 17:09:02 +02:00
parent 483c12edc7
commit 64d90c326f
5 changed files with 80 additions and 0 deletions

View file

@ -1,3 +1,7 @@
# encoding: utf-8
# copyright: 2015, Dominik Richter
# license: All rights reserved
require 'json'
# Group Policy

View file

@ -1,3 +1,7 @@
# encoding: utf-8
# copyright: 2015, Dominik Richter
# license: All rights reserved
require 'json'
# Registry Key Helper

View file

@ -14,6 +14,8 @@ require 'resources/processes'
require 'resources/registry_key'
require 'resources/security_policy'
require 'resources/ssh_conf'
require 'vulcano/rule'
require 'vulcano/rspec_json_formatter'
# Dummy module for handling additional attributes
# which may be injected by the user. This covers data

View file

@ -0,0 +1,22 @@
require 'rspec/core'
# Extend the basic RSpec JSON Formatter
# to give us an ID in its output
# TODO: remove once RSpec has IDs in stable (probably v3.3/v4.0)
module RSpec::Core::Formatters
class JsonFormatter
private
def format_example(example)
{
:description => example.description,
:full_description => example.full_description,
:status => example.execution_result.status.to_s,
:file_path => example.metadata[:file_path],
:line_number => example.metadata[:line_number],
:run_time => example.execution_result.run_time,
:pending_message => example.execution_result.pending_message,
:id => example.metadata[:id]
}
end
end
end

48
lib/vulcano/rule.rb Normal file
View file

@ -0,0 +1,48 @@
# encoding: utf-8
# copyright: 2015, Dominik Richter
# license: All rights reserved
class VulcanoRule
include Serverspec::Helper::Type
extend Serverspec::Helper::Type
include RSpec::Core::DSL
def initialize(id, &block)
@id = id
@impact = 1.0
@title = id
@desc = ""
self.instance_eval(&block)
end
def impact(v = nil)
@impact = v unless v.nil?
@impact
end
def title(v = nil)
@title = v unless v.nil?
@title
end
def desc(v = nil)
@desc = v unless v.nil?
@desc
end
def describe(sth, &block)
r = VulcanoRule.describe(sth, &block)
r.examples.each {|ex|
ex.metadata[:id] = @id
}
end
def method_missing(m, *a, &b)
VulcanoRule.__send__(m, *a, &b)
end
end
def rule id, &block
VulcanoRule.new(id, &block)
end