summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2014-12-16 07:44:00 -0800
committertyler-ball <tyleraball@gmail.com>2014-12-16 09:58:55 -0800
commit3c25eeed8d893518ded06bf21ffc015f2ac45f1e (patch)
tree238ced34deedd5c147e22e78915b31a4910e941a
parent45920e69de15e0b3e107d73077e6ed3db884d8ce (diff)
downloadchef-3c25eeed8d893518ded06bf21ffc015f2ac45f1e.tar.gz
Resolving runtime includes loading unwanted files
-rw-r--r--lib/chef/audit/audit_event_proxy.rb3
-rw-r--r--lib/chef/audit/rspec_formatter.rb3
-rw-r--r--spec/functional/audit/runner_spec.rb92
-rw-r--r--spec/unit/audit/runner_spec.rb35
4 files changed, 66 insertions, 67 deletions
diff --git a/lib/chef/audit/audit_event_proxy.rb b/lib/chef/audit/audit_event_proxy.rb
index ff97fb2dd0..2512b8bfe2 100644
--- a/lib/chef/audit/audit_event_proxy.rb
+++ b/lib/chef/audit/audit_event_proxy.rb
@@ -1,6 +1,5 @@
#
-# Auther:: Tyler Ball (<tball@chef.io>)
-#
+# Author:: Tyler Ball (<tball@chef.io>)
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
diff --git a/lib/chef/audit/rspec_formatter.rb b/lib/chef/audit/rspec_formatter.rb
index 4c4b239d34..074a11bed3 100644
--- a/lib/chef/audit/rspec_formatter.rb
+++ b/lib/chef/audit/rspec_formatter.rb
@@ -1,6 +1,5 @@
#
-# Auther:: Tyler Ball (<tball@chef.io>)
-#
+# Author:: Serdar Sutay (<serdar@chef.io>)
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
diff --git a/spec/functional/audit/runner_spec.rb b/spec/functional/audit/runner_spec.rb
index 8fab332167..9990936499 100644
--- a/spec/functional/audit/runner_spec.rb
+++ b/spec/functional/audit/runner_spec.rb
@@ -36,72 +36,72 @@ describe Chef::Audit::Runner do
# Running in a sub_process means the serverspec libraries will only be included in a forked process, not the main one.
include RSpec::Support::InSubProcess
- let(:events) { double("events").as_null_object }
- let(:runner) { Chef::Audit::Runner.new(run_context) }
- let(:stdout) { StringIO.new }
+ let(:events) { double("events").as_null_object }
+ let(:runner) { Chef::Audit::Runner.new(run_context) }
+ let(:stdout) { StringIO.new }
- around(:each) do |ex|
- Sandboxing.sandboxed { ex.run }
- end
+ around(:each) do |ex|
+ Sandboxing.sandboxed { ex.run }
+ end
- before do
- Chef::Config[:log_location] = stdout
- end
+ before do
+ Chef::Config[:log_location] = stdout
+ end
- # When running these, because we are not mocking out any of the formatters we expect to get dual output on the
- # command line
- describe "#run" do
+ # When running these, because we are not mocking out any of the formatters we expect to get dual output on the
+ # command line
+ describe "#run" do
- let(:audits) { {} }
- let(:run_context) { instance_double(Chef::RunContext, :events => events, :audits => audits) }
- let(:controls_name) { "controls_name" }
+ let(:audits) { {} }
+ let(:run_context) { instance_double(Chef::RunContext, :events => events, :audits => audits) }
+ let(:controls_name) { "controls_name" }
- it "Correctly runs an empty controls block" do
- in_sub_process do
- runner.run
- end
+ it "Correctly runs an empty controls block" do
+ in_sub_process do
+ runner.run
end
+ end
- context "there is a single successful control" do
- let(:audits) do
- should_pass = lambda do
- it "should pass" do
- expect(2 - 2).to eq(0)
- end
+ context "there is a single successful control" do
+ let(:audits) do
+ should_pass = lambda do
+ it "should pass" do
+ expect(2 - 2).to eq(0)
end
- { controls_name => Struct.new(:args, :block).new([controls_name], should_pass)}
end
+ { controls_name => Struct.new(:args, :block).new([controls_name], should_pass)}
+ end
- it "correctly runs" do
- in_sub_process do
- runner.run
+ it "correctly runs" do
+ in_sub_process do
+ runner.run
- expect(stdout.string).to match(/1 example, 0 failures/)
- end
+ expect(stdout.string).to match(/1 example, 0 failures/)
end
end
+ end
- context "there is a single failing control" do
- let(:audits) do
- should_fail = lambda do
- it "should fail" do
- expect(2 - 1).to eq(0)
- end
+ context "there is a single failing control" do
+ let(:audits) do
+ should_fail = lambda do
+ it "should fail" do
+ expect(2 - 1).to eq(0)
end
- { controls_name => Struct.new(:args, :block).new([controls_name], should_fail)}
end
+ { controls_name => Struct.new(:args, :block).new([controls_name], should_fail)}
+ end
- it "correctly runs" do
- in_sub_process do
- runner.run
+ it "correctly runs" do
+ in_sub_process do
+ runner.run
- expect(stdout.string).to match(/Failure\/Error: expect\(2 - 1\)\.to eq\(0\)/)
- expect(stdout.string).to match(/1 example, 1 failure/)
- expect(stdout.string).to match(/# controls_name should fail/)
- end
+ expect(stdout.string).to match(/Failure\/Error: expect\(2 - 1\)\.to eq\(0\)/)
+ expect(stdout.string).to match(/1 example, 1 failure/)
+ expect(stdout.string).to match(/# controls_name should fail/)
end
end
-
end
+ end
+
end
diff --git a/spec/unit/audit/runner_spec.rb b/spec/unit/audit/runner_spec.rb
index 2490108c4e..612196d36d 100644
--- a/spec/unit/audit/runner_spec.rb
+++ b/spec/unit/audit/runner_spec.rb
@@ -19,11 +19,12 @@
require 'spec_helper'
require 'spec/support/audit_helper'
require 'chef/audit/runner'
-require 'specinfra'
require 'chef/audit/audit_event_proxy'
require 'chef/audit/rspec_formatter'
+require 'rspec/support/spec/in_sub_process'
describe Chef::Audit::Runner do
+ include RSpec::Support::InSubProcess
let(:events) { double("events") }
let(:run_context) { instance_double(Chef::RunContext, :events => events) }
@@ -51,27 +52,27 @@ describe Chef::Audit::Runner do
end
it "sets all the config values" do
- # Mock out the require_deps call because we don't want to include the Serverspec DSL to all
- # RSpec example groups
- expect(runner).to receive(:require_deps)
- # For some unknown reason, its having a lot of trouble configuring Specinfra
- expect(runner).to receive(:configure_specinfra)
+ # This runs the Serverspec includes - we don't want these hanging around in all subsequent tests so
+ # we run this in a forked process. Keeps Serverspec files from getting loaded into main process.
+ in_sub_process do
+ runner.send(:setup)
- runner.send(:setup)
+ expect(RSpec.configuration.output_stream).to eq(log_location)
+ expect(RSpec.configuration.error_stream).to eq(log_location)
- expect(RSpec.configuration.output_stream).to eq(log_location)
- expect(RSpec.configuration.error_stream).to eq(log_location)
+ expect(RSpec.configuration.formatters.size).to eq(2)
+ expect(RSpec.configuration.formatters).to include(instance_of(Chef::Audit::AuditEventProxy))
+ expect(RSpec.configuration.formatters).to include(instance_of(Chef::Audit::RspecFormatter))
+ expect(Chef::Audit::AuditEventProxy.class_variable_get(:@@events)).to eq(run_context.events)
- expect(RSpec.configuration.formatters.size).to eq(2)
- expect(RSpec.configuration.formatters).to include(instance_of(Chef::Audit::AuditEventProxy))
- expect(RSpec.configuration.formatters).to include(instance_of(Chef::Audit::RspecFormatter))
- expect(Chef::Audit::AuditEventProxy.class_variable_get(:@@events)).to eq(run_context.events)
+ expect(RSpec.configuration.expectation_frameworks).to eq([RSpec::Matchers])
+ expect(RSpec::Matchers.configuration.syntax).to eq([:expect])
- expect(RSpec.configuration.expectation_frameworks).to eq([RSpec::Matchers])
- expect(RSpec::Matchers.configuration.syntax).to eq([:expect])
+ expect(RSpec.configuration.color).to eq(color)
+ expect(RSpec.configuration.expose_dsl_globally?).to eq(false)
- expect(RSpec.configuration.color).to eq(color)
- expect(RSpec.configuration.expose_dsl_globally?).to eq(false)
+ expect(Specinfra.configuration.backend).to eq(:exec)
+ end
end
end