summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2014-11-06 07:33:35 -0800
committertyler-ball <tyleraball@gmail.com>2014-12-17 18:47:26 -0800
commit2bb912157470f55975f2e50e3792132478639a78 (patch)
tree717d21be119adb2e072146d6f7c2183a11d013d9 /lib/chef
parentb9b4d3bfd6ec6196cb78094e589c094edb61b501 (diff)
downloadchef-2bb912157470f55975f2e50e3792132478639a78.tar.gz
Preparing for demo - using rspec documentation formatter for output instead of the proxy
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/audit/audit_event_proxy.rb4
-rw-r--r--lib/chef/audit/chef_example_group.rb9
-rw-r--r--lib/chef/audit/control_group_data.rb1
-rw-r--r--lib/chef/audit/runner.rb18
-rw-r--r--lib/chef/dsl/audit.rb12
-rw-r--r--lib/chef/formatters/doc.rb6
6 files changed, 27 insertions, 23 deletions
diff --git a/lib/chef/audit/audit_event_proxy.rb b/lib/chef/audit/audit_event_proxy.rb
index 1052821946..d56c7f0ac5 100644
--- a/lib/chef/audit/audit_event_proxy.rb
+++ b/lib/chef/audit/audit_event_proxy.rb
@@ -16,10 +16,6 @@ class Chef
@@events
end
- def initialize(output)
- super
- end
-
def example_group_started(notification)
events.control_group_start(notification.group.description.strip)
end
diff --git a/lib/chef/audit/chef_example_group.rb b/lib/chef/audit/chef_example_group.rb
deleted file mode 100644
index 482647cd03..0000000000
--- a/lib/chef/audit/chef_example_group.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-
-class Chef
- class Audit
- class ChefExampleGroup < ::RSpec::Core::ExampleGroup
- # Can encompass tests in a `control` block or `describe` block
- define_example_group_method :control
- end
- end
-end
diff --git a/lib/chef/audit/control_group_data.rb b/lib/chef/audit/control_group_data.rb
index 93abfb3c21..fc758e45ba 100644
--- a/lib/chef/audit/control_group_data.rb
+++ b/lib/chef/audit/control_group_data.rb
@@ -15,6 +15,7 @@ class Chef
def example_success(opts={})
@number_success += 1
control = create_control(opts)
+ control.status = "success"
controls << control
control
end
diff --git a/lib/chef/audit/runner.rb b/lib/chef/audit/runner.rb
index 1408c67327..4a76b7e65b 100644
--- a/lib/chef/audit/runner.rb
+++ b/lib/chef/audit/runner.rb
@@ -18,6 +18,7 @@
require 'chef/audit'
require 'chef/audit/audit_event_proxy'
+require 'chef/audit/chef_json_formatter'
require 'chef/config'
class Chef
@@ -25,6 +26,7 @@ class Chef
class Runner
attr_reader :run_context
+ private :run_context
def initialize(run_context)
@run_context = run_context
@@ -48,11 +50,11 @@ class Chef
# RSpec configuration and world objects are heavy, so let's wait until
# we actually need them.
def configuration
- @configuration ||= RSpec::Core::Configuration.new
+ RSpec.configuration
end
def world
- @world ||= RSpec::Core::World.new(configuration)
+ RSpec.world
end
# Configure audits before run.
@@ -62,8 +64,14 @@ class Chef
def setup
# We're setting the output stream, but that will only be used for error situations
# Our formatter forwards events to the Chef event message bus
+ # TODO so some testing to see if these output to a log file - we probably need
+ # to register these before any formatters are added.
configuration.output_stream = Chef::Config[:log_location]
configuration.error_stream = Chef::Config[:log_location]
+ # TODO im pretty sure I only need this because im running locally in rvmsudo
+ configuration.backtrace_exclusion_patterns.push(Regexp.new("/Users".gsub("/", File::SEPARATOR)))
+ configuration.backtrace_exclusion_patterns.push(Regexp.new("(eval)"))
+ configuration.color = Chef::Config[:color]
add_formatters
disable_should_syntax
@@ -71,8 +79,10 @@ class Chef
end
def add_formatters
- configuration.add_formatter(Chef::Audit::AuditEventProxy)
- Chef::Audit::AuditEventProxy.events = run_context.events
+ configuration.add_formatter(RSpec::Core::Formatters::DocumentationFormatter)
+ configuration.add_formatter(Chef::Audit::ChefJsonFormatter)
+ #configuration.add_formatter(Chef::Audit::AuditEventProxy)
+ #Chef::Audit::AuditEventProxy.events = run_context.events
end
# Explicitly disable :should syntax.
diff --git a/lib/chef/dsl/audit.rb b/lib/chef/dsl/audit.rb
index 75a57c6bb4..42a1927efb 100644
--- a/lib/chef/dsl/audit.rb
+++ b/lib/chef/dsl/audit.rb
@@ -16,17 +16,21 @@
# limitations under the License.
#
-require 'chef/audit/chef_example_group'
+require 'rspec/core'
class Chef
module DSL
module Audit
+ # Can encompass tests in a `control` block or `describe` block
+ ::RSpec::Core::ExampleGroup.define_example_group_method :control
+ ::RSpec::Core::ExampleGroup.define_example_group_method :__controls__
+
# Adds the controls group and block (containing controls to execute) to the runner's list of pending examples
- def controls(group_name, &group_block)
- raise ::Chef::Exceptions::NoAuditsProvided unless group_block
+ def controls(*args, &block)
+ raise ::Chef::Exceptions::NoAuditsProvided unless block
- run_context.controls_groups << ::Chef::Audit::ChefExampleGroup.describe(group_name, &group_block)
+ run_context.controls_groups << ::RSpec::Core::ExampleGroup.__controls__(*args, &block)
end
end
diff --git a/lib/chef/formatters/doc.rb b/lib/chef/formatters/doc.rb
index 96ca283b9f..d9c9124713 100644
--- a/lib/chef/formatters/doc.rb
+++ b/lib/chef/formatters/doc.rb
@@ -164,18 +164,20 @@ class Chef
# Called before audit phase starts
def audit_phase_start(run_context)
puts_line ""
- puts_line "Audit phase starting"
+ puts_line "++ Audit phase starting ++"
end
# Called when audit phase successfully finishes
def audit_phase_complete
- puts_line "Audit phase ended"
+ puts_line ""
+ puts_line "++ Audit phase ended ++ "
end
# Called if there is an uncaught exception during the audit phase. The audit runner should
# be catching and handling errors from the examples, so this is only uncaught errors (like
# bugs in our handling code)
def audit_phase_failed(error)
+ puts_line ""
puts_line "Audit phase exception:"
indent
# TODO error_mapper ?