summaryrefslogtreecommitdiff
path: root/spec/unit/client_spec.rb
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-02-19 15:17:05 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2015-02-19 15:17:05 -0800
commit864f9ac95063c7833235c8ed50dcb89653eda03f (patch)
tree93da186fd522bdfc5de6414d011f4c0dd49aeb40 /spec/unit/client_spec.rb
parent194f49bdb7737e0591271ba95021997e90379c5d (diff)
parenta7f5c92960aedf8d5bfc71abbce430ab075e016a (diff)
downloadchef-jdm/merge-into-12-stable.tar.gz
Merge remote-tracking branch 'origin/master' into HEADjdm/merge-into-12-stable
* origin/master: (642 commits) Remove Chef 12 release notes Update Changelog for Chef 12.1.0 Chef 12.1.0.rc.0 Group spec needs to respond to shell_out fix dpkg regression fix Lint/BlockAlignment whitespaces fixes fix Lint/AmbiguousRegexpLiteral fix Lint/LiteralInCondition fix Lint/Loop style Make tests pass on Windows remove unreachable code Fix unit specs for PR #2934 dont raise exceptions in load_current_resource when checking current status update changelog fix typo in msi provider Added spec for #2914 fix virtual package logic in check_package_state use scalar pkg not array package convert is_virtual_package to hash ... Conflicts: .travis.yml CHANGELOG.md DOC_CHANGES.md RELEASE_NOTES.md appveyor.yml lib/chef/application.rb lib/chef/dsl/recipe.rb lib/chef/knife/bootstrap.rb lib/chef/knife/core/bootstrap_context.rb lib/chef/node/attribute.rb lib/chef/node/attribute_collections.rb lib/chef/node/immutable_collections.rb lib/chef/resource.rb lib/chef/run_context.rb lib/chef/version.rb spec/functional/dsl/reboot_pending_spec.rb spec/functional/event_loggers/windows_eventlog_spec.rb spec/functional/resource/link_spec.rb spec/support/platform_helpers.rb spec/unit/knife_spec.rb spec/unit/mixin/deep_merge_spec.rb spec/unit/mixin/shell_out_spec.rb spec/unit/node/attribute_spec.rb spec/unit/node_spec.rb spec/unit/provider/package/apt_spec.rb spec/unit/provider/service/systemd_service_spec.rb spec/unit/provider_resolver_spec.rb spec/unit/recipe_spec.rb spec/unit/resource/resource_notification_spec.rb spec/unit/run_context_spec.rb
Diffstat (limited to 'spec/unit/client_spec.rb')
-rw-r--r--spec/unit/client_spec.rb360
1 files changed, 263 insertions, 97 deletions
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index e03773ae03..2ec32b32ac 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -44,7 +44,7 @@ describe Chef::Client do
ohai_system = double( "Ohai::System",
:all_plugins => true,
:data => ohai_data)
- ohai_system.stub(:[]) do |key|
+ allow(ohai_system).to receive(:[]) do |key|
ohai_data[key]
end
ohai_system
@@ -72,7 +72,7 @@ describe Chef::Client do
# Node/Ohai data
#Chef::Config[:node_name] = fqdn
- Ohai::System.stub(:new).and_return(ohai_system)
+ allow(Ohai::System).to receive(:new).and_return(ohai_system)
end
describe "authentication protocol selection" do
@@ -85,7 +85,7 @@ describe Chef::Client do
Chef::Config[:node_name] = ("f" * 90)
# ugly that this happens as a side effect of a getter :(
client.node_name
- Chef::Config[:authentication_protocol_version].should == "1.0"
+ expect(Chef::Config[:authentication_protocol_version]).to eq("1.0")
end
end
@@ -94,7 +94,7 @@ describe Chef::Client do
Chef::Config[:node_name] = ("f" * 91)
# ugly that this happens as a side effect of a getter :(
client.node_name
- Chef::Config[:authentication_protocol_version].should == "1.1"
+ expect(Chef::Config[:authentication_protocol_version]).to eq("1.1")
end
end
end
@@ -104,11 +104,11 @@ describe Chef::Client do
context "and STDOUT is a TTY" do
before do
- STDOUT.stub(:tty?).and_return(true)
+ allow(STDOUT).to receive(:tty?).and_return(true)
end
it "configures the :doc formatter" do
- client.formatters_for_run.should == [[:doc]]
+ expect(client.formatters_for_run).to eq([[:doc]])
end
context "and force_logger is set" do
@@ -117,8 +117,8 @@ describe Chef::Client do
end
it "configures the :null formatter" do
- Chef::Config[:force_logger].should be_true
- client.formatters_for_run.should == [[:null]]
+ expect(Chef::Config[:force_logger]).to be_truthy
+ expect(client.formatters_for_run).to eq([[:null]])
end
end
@@ -127,11 +127,11 @@ describe Chef::Client do
context "and STDOUT is not a TTY" do
before do
- STDOUT.stub(:tty?).and_return(false)
+ allow(STDOUT).to receive(:tty?).and_return(false)
end
it "configures the :null formatter" do
- client.formatters_for_run.should == [[:null]]
+ expect(client.formatters_for_run).to eq([[:null]])
end
context "and force_formatter is set" do
@@ -139,7 +139,7 @@ describe Chef::Client do
Chef::Config[:force_formatter] = true
end
it "it configures the :doc formatter" do
- client.formatters_for_run.should == [[:doc]]
+ expect(client.formatters_for_run).to eq([[:doc]])
end
end
end
@@ -153,14 +153,14 @@ describe Chef::Client do
end
it "does not configure a default formatter" do
- client.formatters_for_run.should == [[:min, nil]]
+ expect(client.formatters_for_run).to eq([[:min, nil]])
end
it "configures the formatter for STDOUT/STDERR" do
configured_formatters = client.configure_formatters
min_formatter = configured_formatters[0]
- min_formatter.output.out.should == STDOUT
- min_formatter.output.err.should == STDERR
+ expect(min_formatter.output.out).to eq(STDOUT)
+ expect(min_formatter.output.err).to eq(STDERR)
end
end
@@ -178,8 +178,8 @@ describe Chef::Client do
it "configures the formatter for the file path" do
configured_formatters = client.configure_formatters
min_formatter = configured_formatters[0]
- min_formatter.output.out.path.should == @tmpout.path
- min_formatter.output.err.path.should == @tmpout.path
+ expect(min_formatter.output.out.path).to eq(@tmpout.path)
+ expect(min_formatter.output.err.path).to eq(@tmpout.path)
end
end
@@ -187,11 +187,12 @@ describe Chef::Client do
end
describe "a full client run" do
- shared_examples_for "a successful client run" do
+ shared_context "a client run" do
let(:http_node_load) { double("Chef::REST (node)") }
let(:http_cookbook_sync) { double("Chef::REST (cookbook sync)") }
let(:http_node_save) { double("Chef::REST (node save)") }
let(:runner) { double("Chef::Runner") }
+ let(:audit_runner) { instance_double("Chef::Audit::Runner", :failed? => false) }
let(:api_client_exists?) { false }
@@ -204,11 +205,15 @@ describe Chef::Client do
# --Client.register
# Make sure Client#register thinks the client key doesn't
# exist, so it tries to register and create one.
- File.should_receive(:exists?).with(Chef::Config[:client_key]).exactly(1).times.and_return(api_client_exists?)
+ allow(File).to receive(:exists?).and_call_original
+ expect(File).to receive(:exists?).
+ with(Chef::Config[:client_key]).
+ exactly(:once).
+ and_return(api_client_exists?)
unless api_client_exists?
# Client.register will register with the validation client name.
- Chef::ApiClient::Registration.any_instance.should_receive(:run)
+ expect_any_instance_of(Chef::ApiClient::Registration).to receive(:run)
end
end
@@ -216,64 +221,76 @@ describe Chef::Client do
# Client.register will then turn around create another
# Chef::REST object, this time with the client key it got from the
# previous step.
- Chef::REST.should_receive(:new).
+ expect(Chef::REST).to receive(:new).
with(Chef::Config[:chef_server_url], fqdn, Chef::Config[:client_key]).
- exactly(1).
+ exactly(:once).
and_return(http_node_load)
# --Client#build_node
# looks up the node, which we will return, then later saves it.
- Chef::Node.should_receive(:find_or_create).with(fqdn).and_return(node)
+ expect(Chef::Node).to receive(:find_or_create).with(fqdn).and_return(node)
# --ResourceReporter#node_load_completed
# gets a run id from the server for storing resource history
# (has its own tests, so stubbing it here.)
- Chef::ResourceReporter.any_instance.should_receive(:node_load_completed)
+ expect_any_instance_of(Chef::ResourceReporter).to receive(:node_load_completed)
end
def stub_for_sync_cookbooks
# --Client#setup_run_context
# ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
#
- Chef::CookbookSynchronizer.any_instance.should_receive(:sync_cookbooks)
- Chef::REST.should_receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
- http_cookbook_sync.should_receive(:post).
+ expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
+ expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
+ expect(http_cookbook_sync).to receive(:post).
with("environments/_default/cookbook_versions", {:run_list => []}).
and_return({})
end
def stub_for_converge
# --Client#converge
- Chef::Runner.should_receive(:new).and_return(runner)
- runner.should_receive(:converge).and_return(true)
+ expect(Chef::Runner).to receive(:new).and_return(runner)
+ expect(runner).to receive(:converge).and_return(true)
+ end
- # --ResourceReporter#run_completed
- # updates the server with the resource history
- # (has its own tests, so stubbing it here.)
- Chef::ResourceReporter.any_instance.should_receive(:run_completed)
+ def stub_for_audit
+ # -- Client#run_audits
+ expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
+ expect(audit_runner).to receive(:run).and_return(true)
end
def stub_for_node_save
- node.stub(:data_for_save).and_return(node.for_json)
+ allow(node).to receive(:data_for_save).and_return(node.for_json)
# --Client#save_updated_node
- Chef::REST.should_receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_node_save)
- http_node_save.should_receive(:put_rest).with("nodes/#{fqdn}", node.for_json).and_return(true)
+ expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_node_save)
+ expect(http_node_save).to receive(:put_rest).with("nodes/#{fqdn}", node.for_json).and_return(true)
end
def stub_for_run
- Chef::RunLock.any_instance.should_receive(:acquire)
- Chef::RunLock.any_instance.should_receive(:save_pid)
- Chef::RunLock.any_instance.should_receive(:release)
+ expect_any_instance_of(Chef::RunLock).to receive(:acquire)
+ expect_any_instance_of(Chef::RunLock).to receive(:save_pid)
+ expect_any_instance_of(Chef::RunLock).to receive(:release)
# Post conditions: check that node has been filled in correctly
- client.should_receive(:run_started)
- client.should_receive(:run_completed_successfully)
+ expect(client).to receive(:run_started)
+ expect(client).to receive(:run_completed_successfully)
+
+ # --ResourceReporter#run_completed
+ # updates the server with the resource history
+ # (has its own tests, so stubbing it here.)
+ expect_any_instance_of(Chef::ResourceReporter).to receive(:run_completed)
+ # --AuditReporter#run_completed
+ # posts the audit data to server.
+ # (has its own tests, so stubbing it here.)
+ expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_completed)
end
before do
Chef::Config[:client_fork] = enable_fork
Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
+ Chef::Config[:why_run] = false
+ Chef::Config[:audit_mode] = :enabled
stub_const("Chef::Client::STDOUT_FD", stdout)
stub_const("Chef::Client::STDERR_FD", stderr)
@@ -282,30 +299,31 @@ describe Chef::Client do
stub_for_node_load
stub_for_sync_cookbooks
stub_for_converge
+ stub_for_audit
stub_for_node_save
stub_for_run
end
+ end
- it "runs ohai, sets up authentication, loads node state, synchronizes policy, and converges" do
+ shared_examples_for "a successful client run" do
+ include_context "a client run"
+
+ it "runs ohai, sets up authentication, loads node state, synchronizes policy, converges, and runs audits" do
# This is what we're testing.
client.run
# fork is stubbed, so we can see the outcome of the run
- node.automatic_attrs[:platform].should == "example-platform"
- node.automatic_attrs[:platform_version].should == "example-platform-1.0"
+ expect(node.automatic_attrs[:platform]).to eq("example-platform")
+ expect(node.automatic_attrs[:platform_version]).to eq("example-platform-1.0")
end
end
-
describe "when running chef-client without fork" do
-
include_examples "a successful client run"
end
describe "when the client key already exists" do
-
let(:api_client_exists?) { true }
-
include_examples "a successful client run"
end
@@ -321,30 +339,29 @@ describe Chef::Client do
before do
# Client will try to compile and run override_recipe
- Chef::RunContext::CookbookCompiler.any_instance.should_receive(:compile)
+ expect_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile)
end
def stub_for_sync_cookbooks
# --Client#setup_run_context
# ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
#
- Chef::CookbookSynchronizer.any_instance.should_receive(:sync_cookbooks)
- Chef::REST.should_receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
- http_cookbook_sync.should_receive(:post).
+ expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
+ expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
+ expect(http_cookbook_sync).to receive(:post).
with("environments/_default/cookbook_versions", {:run_list => ["override_recipe"]}).
and_return({})
end
def stub_for_node_save
# Expect NO node save
- node.should_not_receive(:save)
+ expect(node).not_to receive(:save)
end
end
end
end
describe "when a permanent run list is passed as an option" do
-
include_examples "a successful client run" do
let(:new_runlist) { "recipe[new_run_list_recipe]" }
@@ -354,9 +371,9 @@ describe Chef::Client do
# --Client#setup_run_context
# ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
#
- Chef::CookbookSynchronizer.any_instance.should_receive(:sync_cookbooks)
- Chef::REST.should_receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
- http_cookbook_sync.should_receive(:post).
+ expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
+ expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
+ expect(http_cookbook_sync).to receive(:post).
with("environments/_default/cookbook_versions", {:run_list => ["new_run_list_recipe"]}).
and_return({})
end
@@ -364,12 +381,161 @@ describe Chef::Client do
before do
# Client will try to compile and run the new_run_list_recipe, but we
# do not create a fixture for this.
- Chef::RunContext::CookbookCompiler.any_instance.should_receive(:compile)
+ expect_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile)
end
it "sets the new run list on the node" do
client.run
- node.run_list.should == Chef::RunList.new(new_runlist)
+ expect(node.run_list).to eq(Chef::RunList.new(new_runlist))
+ end
+ end
+ end
+
+ describe "when converge fails" do
+ include_context "a client run" do
+ let(:e) { Exception.new }
+ def stub_for_converge
+ expect(Chef::Runner).to receive(:new).and_return(runner)
+ expect(runner).to receive(:converge).and_raise(e)
+ expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError)
+ end
+
+ def stub_for_node_save
+ expect(client).to_not receive(:save_updated_node)
+ end
+
+ def stub_for_run
+ expect_any_instance_of(Chef::RunLock).to receive(:acquire)
+ expect_any_instance_of(Chef::RunLock).to receive(:save_pid)
+ expect_any_instance_of(Chef::RunLock).to receive(:release)
+
+ # Post conditions: check that node has been filled in correctly
+ expect(client).to receive(:run_started)
+ expect(client).to receive(:run_failed)
+
+ expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed)
+ expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_failed)
+ end
+ end
+
+ it "runs the audits and raises the error" do
+ expect{ client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error|
+ expect(error.wrapped_errors.size).to eq(1)
+ expect(error.wrapped_errors[0]).to eq(e)
+ end
+ end
+ end
+
+ describe "when the audit phase fails" do
+ context "with an exception" do
+ include_context "a client run" do
+ let(:e) { Exception.new }
+ def stub_for_audit
+ expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
+ expect(audit_runner).to receive(:run).and_raise(e)
+ expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError)
+ end
+
+ def stub_for_run
+ expect_any_instance_of(Chef::RunLock).to receive(:acquire)
+ expect_any_instance_of(Chef::RunLock).to receive(:save_pid)
+ expect_any_instance_of(Chef::RunLock).to receive(:release)
+
+ # Post conditions: check that node has been filled in correctly
+ expect(client).to receive(:run_started)
+ expect(client).to receive(:run_failed)
+
+ expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed)
+ expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_failed)
+ end
+ end
+
+ it "should save the node after converge and raise exception" do
+ expect{ client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error|
+ expect(error.wrapped_errors.size).to eq(1)
+ expect(error.wrapped_errors[0]).to eq(e)
+ end
+ end
+ end
+
+ context "with failed audits" do
+ include_context "a client run" do
+ let(:audit_runner) do
+ instance_double("Chef::Audit::Runner", :run => true, :failed? => true, :num_failed => 1, :num_total => 1)
+ end
+
+ def stub_for_audit
+ expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
+ expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError)
+ end
+
+ def stub_for_run
+ expect_any_instance_of(Chef::RunLock).to receive(:acquire)
+ expect_any_instance_of(Chef::RunLock).to receive(:save_pid)
+ expect_any_instance_of(Chef::RunLock).to receive(:release)
+
+ # Post conditions: check that node has been filled in correctly
+ expect(client).to receive(:run_started)
+ expect(client).to receive(:run_failed)
+
+ expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed)
+ expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_failed)
+ end
+ end
+
+ it "should save the node after converge and raise exception" do
+ expect{ client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error|
+ expect(error.wrapped_errors.size).to eq(1)
+ expect(error.wrapped_errors[0]).to be_instance_of(Chef::Exceptions::AuditsFailed)
+ end
+ end
+ end
+ end
+
+ describe "when why_run mode is enabled" do
+ include_context "a client run" do
+
+ before do
+ Chef::Config[:why_run] = true
+ end
+
+ def stub_for_audit
+ expect(Chef::Audit::Runner).to_not receive(:new)
+ end
+
+ def stub_for_node_save
+ # This is how we should be mocking external calls - not letting it fall all the way through to the
+ # REST call
+ expect(node).to receive(:save)
+ end
+
+ it "runs successfully without enabling the audit runner" do
+ client.run
+
+ # fork is stubbed, so we can see the outcome of the run
+ expect(node.automatic_attrs[:platform]).to eq("example-platform")
+ expect(node.automatic_attrs[:platform_version]).to eq("example-platform-1.0")
+ end
+ end
+ end
+
+ describe "when audits are disabled" do
+ include_context "a client run" do
+
+ before do
+ Chef::Config[:audit_mode] = :disabled
+ end
+
+ def stub_for_audit
+ expect(Chef::Audit::Runner).to_not receive(:new)
+ end
+
+ it "runs successfully without enabling the audit runner" do
+ client.run
+
+ # fork is stubbed, so we can see the outcome of the run
+ expect(node.automatic_attrs[:platform]).to eq("example-platform")
+ expect(node.automatic_attrs[:platform_version]).to eq("example-platform-1.0")
end
end
end
@@ -381,23 +547,23 @@ describe Chef::Client do
it "should remove the run_lock on failure of #load_node" do
@run_lock = double("Chef::RunLock", :acquire => true)
- Chef::RunLock.stub(:new).and_return(@run_lock)
+ allow(Chef::RunLock).to receive(:new).and_return(@run_lock)
@events = double("Chef::EventDispatch::Dispatcher").as_null_object
- Chef::EventDispatch::Dispatcher.stub(:new).and_return(@events)
+ allow(Chef::EventDispatch::Dispatcher).to receive(:new).and_return(@events)
# @events is created on Chef::Client.new, so we need to recreate it after mocking
client = Chef::Client.new
- client.stub(:load_node).and_raise(Exception)
- @run_lock.should_receive(:release)
- lambda { client.run }.should raise_error(Exception)
+ allow(client).to receive(:load_node).and_raise(Exception)
+ expect(@run_lock).to receive(:release)
+ expect { client.run }.to raise_error(Exception)
end
end
describe "when notifying other objects of the status of the chef run" do
before do
Chef::Client.clear_notifications
- Chef::Node.stub(:find_or_create).and_return(node)
- node.stub(:save)
+ allow(Chef::Node).to receive(:find_or_create).and_return(node)
+ allow(node).to receive(:save)
client.load_node
client.build_node
end
@@ -405,34 +571,34 @@ describe Chef::Client do
it "notifies observers that the run has started" do
notified = false
Chef::Client.when_run_starts do |run_status|
- run_status.node.should == node
+ expect(run_status.node).to eq(node)
notified = true
end
client.run_started
- notified.should be_true
+ expect(notified).to be_truthy
end
it "notifies observers that the run has completed successfully" do
notified = false
Chef::Client.when_run_completes_successfully do |run_status|
- run_status.node.should == node
+ expect(run_status.node).to eq(node)
notified = true
end
client.run_completed_successfully
- notified.should be_true
+ expect(notified).to be_truthy
end
it "notifies observers that the run failed" do
notified = false
Chef::Client.when_run_fails do |run_status|
- run_status.node.should == node
+ expect(run_status.node).to eq(node)
notified = true
end
client.run_failed
- notified.should be_true
+ expect(notified).to be_truthy
end
end
@@ -446,73 +612,73 @@ describe Chef::Client do
# build_node will call Node#expand! with server, which will
# eventually hit the server to expand the included role.
mock_chef_rest = double("Chef::REST")
- mock_chef_rest.should_receive(:get_rest).with("roles/role_containing_cookbook1").and_return(role_containing_cookbook1)
- Chef::REST.should_receive(:new).and_return(mock_chef_rest)
+ expect(mock_chef_rest).to receive(:get_rest).with("roles/role_containing_cookbook1").and_return(role_containing_cookbook1)
+ expect(Chef::REST).to receive(:new).and_return(mock_chef_rest)
# check pre-conditions.
- node[:roles].should be_nil
- node[:recipes].should be_nil
+ expect(node[:roles]).to be_nil
+ expect(node[:recipes]).to be_nil
- client.policy_builder.stub(:node).and_return(node)
+ allow(client.policy_builder).to receive(:node).and_return(node)
# chefspec and possibly others use the return value of this method
- client.build_node.should == node
+ expect(client.build_node).to eq(node)
# check post-conditions.
- node[:roles].should_not be_nil
- node[:roles].length.should == 1
- node[:roles].should include("role_containing_cookbook1")
- node[:recipes].should_not be_nil
- node[:recipes].length.should == 1
- node[:recipes].should include("cookbook1")
+ expect(node[:roles]).not_to be_nil
+ expect(node[:roles].length).to eq(1)
+ expect(node[:roles]).to include("role_containing_cookbook1")
+ expect(node[:recipes]).not_to be_nil
+ expect(node[:recipes].length).to eq(1)
+ expect(node[:recipes]).to include("cookbook1")
end
it "should set the environment from the specified configuration value" do
- node.chef_environment.should == "_default"
+ expect(node.chef_environment).to eq("_default")
Chef::Config[:environment] = "A"
test_env = Chef::Environment.new
test_env.name("A")
mock_chef_rest = double("Chef::REST")
- mock_chef_rest.should_receive(:get_rest).with("environments/A").and_return(test_env)
- Chef::REST.should_receive(:new).and_return(mock_chef_rest)
- client.policy_builder.stub(:node).and_return(node)
- client.build_node.should == node
+ expect(mock_chef_rest).to receive(:get_rest).with("environments/A").and_return(test_env)
+ expect(Chef::REST).to receive(:new).and_return(mock_chef_rest)
+ allow(client.policy_builder).to receive(:node).and_return(node)
+ expect(client.build_node).to eq(node)
- node.chef_environment.should == "A"
+ expect(node.chef_environment).to eq("A")
end
end
describe "windows_admin_check" do
context "platform is not windows" do
before do
- Chef::Platform.stub(:windows?).and_return(false)
+ allow(Chef::Platform).to receive(:windows?).and_return(false)
end
it "shouldn't be called" do
- client.should_not_receive(:has_admin_privileges?)
+ expect(client).not_to receive(:has_admin_privileges?)
client.do_windows_admin_check
end
end
context "platform is windows" do
before do
- Chef::Platform.stub(:windows?).and_return(true)
+ allow(Chef::Platform).to receive(:windows?).and_return(true)
end
it "should be called" do
- client.should_receive(:has_admin_privileges?)
+ expect(client).to receive(:has_admin_privileges?)
client.do_windows_admin_check
end
context "admin privileges exist" do
before do
- client.should_receive(:has_admin_privileges?).and_return(true)
+ expect(client).to receive(:has_admin_privileges?).and_return(true)
end
it "should not log a warning message" do
- Chef::Log.should_not_receive(:warn)
+ expect(Chef::Log).not_to receive(:warn)
client.do_windows_admin_check
end
@@ -525,11 +691,11 @@ describe Chef::Client do
context "admin privileges doesn't exist" do
before do
- client.should_receive(:has_admin_privileges?).and_return(false)
+ expect(client).to receive(:has_admin_privileges?).and_return(false)
end
it "should log a warning message" do
- Chef::Log.should_receive(:warn)
+ expect(Chef::Log).to receive(:warn)
client.do_windows_admin_check
end