diff --git a/Gemfile b/Gemfile index 069719ffe25..1418235ebcc 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,6 @@ source "https://rubygems.org" gemspec :name => "chef" gem "activesupport", "< 4.0.0", :group => :compat_testing, :platform => "ruby" -# TODO after serverspec stops including their top level DSL we can remove this -gem "serverspec", :git => "https://github.com/tyler-ball/serverspec/" group(:docgen) do gem "yard" diff --git a/lib/chef/audit/audit_event_proxy.rb b/lib/chef/audit/audit_event_proxy.rb index ff97fb2dd01..2512b8bfe22 100644 --- a/lib/chef/audit/audit_event_proxy.rb +++ b/lib/chef/audit/audit_event_proxy.rb @@ -1,6 +1,5 @@ # -# Auther:: Tyler Ball () -# +# Author:: Tyler Ball () # 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 4c4b239d348..074a11bed31 100644 --- a/lib/chef/audit/rspec_formatter.rb +++ b/lib/chef/audit/rspec_formatter.rb @@ -1,6 +1,5 @@ # -# Auther:: Tyler Ball () -# +# Author:: Serdar Sutay () # 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 8fab332167a..89c62ae2e87 100644 --- a/spec/functional/audit/runner_spec.rb +++ b/spec/functional/audit/runner_spec.rb @@ -36,72 +36,70 @@ # 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 } - - around(:each) do |ex| - Sandboxing.sandboxed { ex.run } - 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 - - 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 + 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 + + before do + Chef::Config[:log_location] = stdout + end + + describe "#run" do + + 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 + 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 ca6f51f9eb0..67590fecf98 100644 --- a/spec/unit/audit/runner_spec.rb +++ b/spec/unit/audit/runner_spec.rb @@ -19,8 +19,12 @@ require 'spec_helper' require 'spec/support/audit_helper' require 'chef/audit/runner' +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) } @@ -48,23 +52,27 @@ end it "sets all the config values" do - runner.send(:setup) + # 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) - 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) + expect(Specinfra.configuration.backend).to eq(:exec) + end end end @@ -88,6 +96,7 @@ expect(RSpec.world.example_groups.size).to eq(1) # For whatever reason, `kind_of` is not working + # expect(RSpec.world.example_groups).to include(kind_of(RSpec::Core::ExampleGroup)) => FAIL g = RSpec.world.example_groups[0] expect(g.ancestors).to include(RSpec::Core::ExampleGroup) expect(g.description).to eq("group_name")