diff options
author | Ryan Cragun <me@ryan.ec> | 2014-05-20 17:03:04 -0700 |
---|---|---|
committer | Ryan Cragun <me@ryan.ec> | 2014-05-20 17:03:04 -0700 |
commit | 385867028f19b9b4f23d66787837444b8c3c47d2 (patch) | |
tree | 90967ab940d2d8229c4fdcbbf2f61833cd851b5e | |
parent | 681d6e6d984f2caaf169b872a3cb3d6ef727b2c0 (diff) | |
download | chef-385867028f19b9b4f23d66787837444b8c3c47d2.tar.gz |
[CHEF-5314] Add unit specs
-rw-r--r-- | chef/spec/unit/shef/shef_session_spec.rb | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/chef/spec/unit/shef/shef_session_spec.rb b/chef/spec/unit/shef/shef_session_spec.rb index c994b451f1..9c8945fea5 100644 --- a/chef/spec/unit/shef/shef_session_spec.rb +++ b/chef/spec/unit/shef/shef_session_spec.rb @@ -48,20 +48,39 @@ describe Shef::ShefSession do end describe Shef::ClientSession do - it "builds the node's run_context with the proper environment" do + before do + Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] } @session = Shef::ClientSession.instance @node = Chef::Node.build("foo") @session.node = @node - @session.instance_variable_set(:@client, stub(:sync_cookbooks => {})) + @client = double("Chef::Client.new", + :run_ohai => true, + :load_node => true, + :build_node => true, + :register => true, + :sync_cookbooks => {}) + end + + it "builds the node's run_context with the proper environment" do + @session.instance_variable_set(:@client, @client) + + @expansion = Chef::RunList::RunListExpansion.new(@node.chef_environment, []) @node.run_list.should_receive(:expand).with(@node.chef_environment).and_return(@expansion) @session.rebuild_context end + + it "passes the shell CLI args to the client" do + Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) + @session.send(:rebuild_node) + end + end describe Shef::StandAloneSession do before do + Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] } @session = Shef::StandAloneSession.instance @node = @session.node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @@ -97,10 +116,22 @@ describe Shef::StandAloneSession do @recipe.run_chef.should == :converged end + it "passes the shell CLI args to the client" do + @client = double("Chef::Client.new", + :run_ohai => true, + :load_node => true, + :build_node => true, + :register => true, + :sync_cookbooks => {}) + Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) + @session.send(:rebuild_node) + end + end describe Shef::SoloSession do before do + Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] } Chef::Config[:shef_solo] = true @session = Shef::SoloSession.instance @node = Chef::Node.new @@ -151,4 +182,15 @@ describe Shef::SoloSession do @recipe.run_chef.should == :converged end + it "passes the shell CLI args to the client" do + @client = double("Chef::Client.new", + :run_ohai => true, + :load_node => true, + :build_node => true, + :register => true, + :sync_cookbooks => {}) + Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) + @session.send(:rebuild_node) + end + end |