diff options
author | Thom May <tmay@expedia.com> | 2014-03-04 11:18:05 +0000 |
---|---|---|
committer | Thom May <tmay@expedia.com> | 2014-03-04 11:18:05 +0000 |
commit | 423651d9ca1d20855fac93ca374a0f555bc70a85 (patch) | |
tree | 1b260a1b84e24de5b3a0223c6afa916451af220f /spec/unit/node_spec.rb | |
parent | ac7fcb41da4bbed8b2d02ae872b40639dfeb53c4 (diff) | |
parent | ad6abcc84a0bd9bd47b636f7004588510615c188 (diff) | |
download | chef-423651d9ca1d20855fac93ca374a0f555bc70a85.tar.gz |
Merge remote-tracking branch 'origin/master' into save-right-run-list
Conflicts:
lib/chef/client.rb
Diffstat (limited to 'spec/unit/node_spec.rb')
-rw-r--r-- | spec/unit/node_spec.rb | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 20f750279f..832e10f645 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -46,12 +46,12 @@ describe Chef::Node do before do response = OpenStruct.new(:code => '404') exception = Net::HTTPServerException.new("404 not found", response) - Chef::Node.stub!(:load).and_raise(exception) + Chef::Node.stub(:load).and_raise(exception) node.name("created-node") end it "creates a new node for find_or_create" do - Chef::Node.stub!(:new).and_return(node) + Chef::Node.stub(:new).and_return(node) node.should_receive(:create).and_return(node) node = Chef::Node.find_or_create("created-node") node.name.should == 'created-node' @@ -62,7 +62,7 @@ describe Chef::Node do describe "when the node exists on the server" do before do node.name('existing-node') - Chef::Node.stub!(:load).and_return(node) + Chef::Node.stub(:load).and_return(node) end it "loads the node via the REST API for find_or_create" do @@ -204,6 +204,11 @@ describe Chef::Node do node.fuu.bahrr.baz.should == "qux" end + it "should let you use tag as a convience method for the tags attribute" do + node.normal['tags'] = ['one', 'two'] + node.tag('three', 'four') + node['tags'].should == ['one', 'two', 'three', 'four'] + end end describe "default attributes" do @@ -400,7 +405,7 @@ describe Chef::Node do it "saves non-runlist json attrs for later" do expansion = Chef::RunList::RunListExpansion.new('_default', []) - node.run_list.stub!(:expand).and_return(expansion) + node.run_list.stub(:expand).and_return(expansion) node.consume_external_attrs(@ohai_data, {"foo" => "bar"}) node.expand! node.normal_attrs.should == {"foo" => "bar", "tags" => []} @@ -418,7 +423,7 @@ describe Chef::Node do Chef::Environment.should_receive(:load).with("rspec_env").and_return(@environment) @expansion = Chef::RunList::RunListExpansion.new("rspec_env", []) node.chef_environment("rspec_env") - node.run_list.stub!(:expand).and_return(@expansion) + node.run_list.stub(:expand).and_return(@expansion) end it "sets the 'recipes' automatic attribute to the recipes in the expanded run_list" do @@ -456,6 +461,22 @@ describe Chef::Node do end end + describe "loaded_recipe" do + it "should not add a recipe that is already in the recipes list" do + node.automatic_attrs[:recipes] = [ "nginx::module" ] + node.loaded_recipe(:nginx, "module") + expect(node.automatic_attrs[:recipes].length).to eq(1) + end + + it "should add a recipe that is not already in the recipes list" do + node.automatic_attrs[:recipes] = [ "nginx::other_module" ] + node.loaded_recipe(:nginx, "module") + expect(node.automatic_attrs[:recipes].length).to eq(2) + expect(node.recipe?("nginx::module")).to be_true + expect(node.recipe?("nginx::other_module")).to be_true + end + end + describe "when querying for recipes in the run list" do context "when a recipe is in the top level run list" do before do @@ -519,7 +540,7 @@ describe Chef::Node do @environment = Chef::Environment.new @environment.default_attributes = {:default => "from env", :d_env => "env only" } @environment.override_attributes = {:override => "from env", :o_env => "env only"} - Chef::Environment.stub!(:load).and_return(@environment) + Chef::Environment.stub(:load).and_return(@environment) node.apply_expansion_attributes(@expansion) end @@ -752,16 +773,16 @@ describe Chef::Node do describe "api model" do before(:each) do - @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@rest) - @query = mock("Chef::Search::Query") - Chef::Search::Query.stub!(:new).and_return(@query) + @rest = double("Chef::REST") + Chef::REST.stub(:new).and_return(@rest) + @query = double("Chef::Search::Query") + Chef::Search::Query.stub(:new).and_return(@query) end describe "list" do describe "inflated" do it "should return a hash of node names and objects" do - n1 = mock("Chef::Node", :name => "one") + n1 = double("Chef::Node", :name => "one") @query.should_receive(:search).with(:node).and_yield(n1) r = Chef::Node.list(true) r["one"].should == n1 @@ -806,7 +827,7 @@ describe Chef::Node do it "should create if it cannot update" do node.name("monkey") - exception = mock("404 error", :code => "404") + exception = double("404 error", :code => "404") @rest.should_receive(:put_rest).and_raise(Net::HTTPServerException.new("foo", exception)) @rest.should_receive(:post_rest).with("nodes", node) node.save |