summaryrefslogtreecommitdiff
path: root/spec/unit/client_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/client_spec.rb')
-rw-r--r--spec/unit/client_spec.rb172
1 files changed, 86 insertions, 86 deletions
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index e03773ae03..10958d628c 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
@@ -204,11 +204,11 @@ 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?)
+ expect(File).to receive(:exists?).with(Chef::Config[:client_key]).exactly(1).times.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,59 +216,59 @@ 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).
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)
# --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)
+ expect_any_instance_of(Chef::ResourceReporter).to receive(:run_completed)
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)
end
before do
@@ -291,8 +291,8 @@ describe Chef::Client do
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
@@ -321,23 +321,23 @@ 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
@@ -354,9 +354,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 +364,12 @@ 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
@@ -381,23 +381,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 +405,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 +446,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 +525,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