summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2014-12-15 14:44:36 -0800
committertyler-ball <tyleraball@gmail.com>2014-12-17 18:52:24 -0800
commit0587f48b65a0a5f6ed8803cf1bd0d4b78e68c8a8 (patch)
tree037b99cfc2ccc2634af50514a113a05cc96ac7aa
parent44fc2faadb2d63c77fb1bfacb973be615a842c42 (diff)
downloadchef-0587f48b65a0a5f6ed8803cf1bd0d4b78e68c8a8.tar.gz
Fixing unit test adding Serverspec DSL
-rw-r--r--Gemfile2
-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.rb100
-rw-r--r--spec/unit/audit/runner_spec.rb33
5 files changed, 72 insertions, 69 deletions
diff --git a/Gemfile b/Gemfile
index 069719ffe2..1418235ebc 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 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..89c62ae2e8 100644
--- a/spec/functional/audit/runner_spec.rb
+++ b/spec/functional/audit/runner_spec.rb
@@ -36,72 +36,70 @@ 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 }
-
- 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 ca6f51f9eb..67590fecf9 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 @@ describe Chef::Audit::Runner do
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 @@ describe Chef::Audit::Runner do
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")