diff --git a/lib/resources/group_policy.rb b/lib/resources/group_policy.rb index 4b4169495..52a9e0d4f 100644 --- a/lib/resources/group_policy.rb +++ b/lib/resources/group_policy.rb @@ -1,3 +1,7 @@ +# encoding: utf-8 +# copyright: 2015, Dominik Richter +# license: All rights reserved + require 'json' # Group Policy diff --git a/lib/resources/registry_key.rb b/lib/resources/registry_key.rb index 646a0cd88..a4465d2da 100644 --- a/lib/resources/registry_key.rb +++ b/lib/resources/registry_key.rb @@ -1,3 +1,7 @@ +# encoding: utf-8 +# copyright: 2015, Dominik Richter +# license: All rights reserved + require 'json' # Registry Key Helper diff --git a/lib/vulcano.rb b/lib/vulcano.rb index 6acbf2544..c3ba0c6ed 100644 --- a/lib/vulcano.rb +++ b/lib/vulcano.rb @@ -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 diff --git a/lib/vulcano/rspec_json_formatter.rb b/lib/vulcano/rspec_json_formatter.rb new file mode 100644 index 000000000..ecdfe1d6e --- /dev/null +++ b/lib/vulcano/rspec_json_formatter.rb @@ -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 \ No newline at end of file diff --git a/lib/vulcano/rule.rb b/lib/vulcano/rule.rb new file mode 100644 index 000000000..d2aa6dabb --- /dev/null +++ b/lib/vulcano/rule.rb @@ -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