summaryrefslogtreecommitdiff
path: root/spec/unit/node_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/node_spec.rb')
-rw-r--r--spec/unit/node_spec.rb362
1 files changed, 181 insertions, 181 deletions
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index da7a67aec1..24209d367f 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -28,167 +28,167 @@ describe Chef::Node do
it "creates a node and assigns it a name" do
node = Chef::Node.build('solo-node')
- node.name.should == 'solo-node'
+ expect(node.name).to eq('solo-node')
end
it "should validate the name of the node" do
- lambda{Chef::Node.build('solo node')}.should raise_error(Chef::Exceptions::ValidationFailed)
+ expect{Chef::Node.build('solo node')}.to raise_error(Chef::Exceptions::ValidationFailed)
end
it "should be sortable" do
n1 = Chef::Node.build('alpha')
n2 = Chef::Node.build('beta')
n3 = Chef::Node.build('omega')
- [n3, n1, n2].sort.should == [n1, n2, n3]
+ expect([n3, n1, n2].sort).to eq([n1, n2, n3])
end
describe "when the node does not exist on the server" do
before do
response = OpenStruct.new(:code => '404')
exception = Net::HTTPServerException.new("404 not found", response)
- Chef::Node.stub(:load).and_raise(exception)
+ allow(Chef::Node).to receive(: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)
- node.should_receive(:create).and_return(node)
+ allow(Chef::Node).to receive(:new).and_return(node)
+ expect(node).to receive(:create).and_return(node)
node = Chef::Node.find_or_create("created-node")
- node.name.should == 'created-node'
- node.should equal(node)
+ expect(node.name).to eq('created-node')
+ expect(node).to equal(node)
end
end
describe "when the node exists on the server" do
before do
node.name('existing-node')
- Chef::Node.stub(:load).and_return(node)
+ allow(Chef::Node).to receive(:load).and_return(node)
end
it "loads the node via the REST API for find_or_create" do
- Chef::Node.find_or_create('existing-node').should equal(node)
+ expect(Chef::Node.find_or_create('existing-node')).to equal(node)
end
end
describe "run_state" do
it "is an empty hash" do
- node.run_state.should respond_to(:keys)
- node.run_state.should be_empty
+ expect(node.run_state).to respond_to(:keys)
+ expect(node.run_state).to be_empty
end
end
describe "initialize" do
it "should default to the '_default' chef_environment" do
n = Chef::Node.new
- n.chef_environment.should == '_default'
+ expect(n.chef_environment).to eq('_default')
end
end
describe "name" do
it "should allow you to set a name with name(something)" do
- lambda { node.name("latte") }.should_not raise_error
+ expect { node.name("latte") }.not_to raise_error
end
it "should return the name with name()" do
node.name("latte")
- node.name.should eql("latte")
+ expect(node.name).to eql("latte")
end
it "should always have a string for name" do
- lambda { node.name(Hash.new) }.should raise_error(ArgumentError)
+ expect { node.name(Hash.new) }.to raise_error(ArgumentError)
end
it "cannot be blank" do
- lambda { node.name("")}.should raise_error(Chef::Exceptions::ValidationFailed)
+ expect { node.name("")}.to raise_error(Chef::Exceptions::ValidationFailed)
end
it "should not accept name doesn't match /^[\-[:alnum:]_:.]+$/" do
- lambda { node.name("space in it")}.should raise_error(Chef::Exceptions::ValidationFailed)
+ expect { node.name("space in it")}.to raise_error(Chef::Exceptions::ValidationFailed)
end
end
describe "chef_environment" do
it "should set an environment with chef_environment(something)" do
- lambda { node.chef_environment("latte") }.should_not raise_error
+ expect { node.chef_environment("latte") }.not_to raise_error
end
it "should return the chef_environment with chef_environment()" do
node.chef_environment("latte")
- node.chef_environment.should == "latte"
+ expect(node.chef_environment).to eq("latte")
end
it "should disallow non-strings" do
- lambda { node.chef_environment(Hash.new) }.should raise_error(ArgumentError)
- lambda { node.chef_environment(42) }.should raise_error(ArgumentError)
+ expect { node.chef_environment(Hash.new) }.to raise_error(ArgumentError)
+ expect { node.chef_environment(42) }.to raise_error(ArgumentError)
end
it "cannot be blank" do
- lambda { node.chef_environment("")}.should raise_error(Chef::Exceptions::ValidationFailed)
+ expect { node.chef_environment("")}.to raise_error(Chef::Exceptions::ValidationFailed)
end
end
describe "attributes" do
it "should have attributes" do
- node.attribute.should be_a_kind_of(Hash)
+ expect(node.attribute).to be_a_kind_of(Hash)
end
it "should allow attributes to be accessed by name or symbol directly on node[]" do
node.default["locust"] = "something"
- node[:locust].should eql("something")
- node["locust"].should eql("something")
+ expect(node[:locust]).to eql("something")
+ expect(node["locust"]).to eql("something")
end
it "should return nil if it cannot find an attribute with node[]" do
- node["secret"].should eql(nil)
+ expect(node["secret"]).to eql(nil)
end
it "does not allow you to set an attribute via node[]=" do
- lambda { node["secret"] = "shush" }.should raise_error(Chef::Exceptions::ImmutableAttributeModification)
+ expect { node["secret"] = "shush" }.to raise_error(Chef::Exceptions::ImmutableAttributeModification)
end
it "should allow you to query whether an attribute exists with attribute?" do
node.default["locust"] = "something"
- node.attribute?("locust").should eql(true)
- node.attribute?("no dice").should eql(false)
+ expect(node.attribute?("locust")).to eql(true)
+ expect(node.attribute?("no dice")).to eql(false)
end
it "should let you go deep with attribute?" do
node.set["battles"]["people"]["wonkey"] = true
- node["battles"]["people"].attribute?("wonkey").should == true
- node["battles"]["people"].attribute?("snozzberry").should == false
+ expect(node["battles"]["people"].attribute?("wonkey")).to eq(true)
+ expect(node["battles"]["people"].attribute?("snozzberry")).to eq(false)
end
it "does not allow you to set an attribute via method_missing" do
- lambda { node.sunshine = "is bright"}.should raise_error(Chef::Exceptions::ImmutableAttributeModification)
+ expect { node.sunshine = "is bright"}.to raise_error(Chef::Exceptions::ImmutableAttributeModification)
end
it "should allow you get get an attribute via method_missing" do
node.default.sunshine = "is bright"
- node.sunshine.should eql("is bright")
+ expect(node.sunshine).to eql("is bright")
end
describe "normal attributes" do
it "should allow you to set an attribute with set, without pre-declaring a hash" do
node.set[:snoopy][:is_a_puppy] = true
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "should allow you to set an attribute with set_unless" do
node.set_unless[:snoopy][:is_a_puppy] = false
- node[:snoopy][:is_a_puppy].should == false
+ expect(node[:snoopy][:is_a_puppy]).to eq(false)
end
it "should not allow you to set an attribute with set_unless if it already exists" do
node.set[:snoopy][:is_a_puppy] = true
node.set_unless[:snoopy][:is_a_puppy] = false
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "should allow you to set a value after a set_unless" do
# this tests for set_unless_present state bleeding between statements CHEF-3806
node.set_unless[:snoopy][:is_a_puppy] = false
node.set[:snoopy][:is_a_puppy] = true
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "should let you set a value after a 'dangling' set_unless" do
@@ -196,43 +196,43 @@ describe Chef::Node do
node.set[:snoopy][:is_a_puppy] = "what"
node.set_unless[:snoopy][:is_a_puppy]
node.set[:snoopy][:is_a_puppy] = true
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "auto-vivifies attributes created via method syntax" do
node.set.fuu.bahrr.baz = "qux"
- node.fuu.bahrr.baz.should == "qux"
+ expect(node.fuu.bahrr.baz).to eq("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']
+ expect(node['tags']).to eq(['one', 'two', 'three', 'four'])
end
end
describe "default attributes" do
it "should be set with default, without pre-declaring a hash" do
node.default[:snoopy][:is_a_puppy] = true
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "should allow you to set with default_unless without pre-declaring a hash" do
node.default_unless[:snoopy][:is_a_puppy] = false
- node[:snoopy][:is_a_puppy].should == false
+ expect(node[:snoopy][:is_a_puppy]).to eq(false)
end
it "should not allow you to set an attribute with default_unless if it already exists" do
node.default[:snoopy][:is_a_puppy] = true
node.default_unless[:snoopy][:is_a_puppy] = false
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "should allow you to set a value after a default_unless" do
# this tests for set_unless_present state bleeding between statements CHEF-3806
node.default_unless[:snoopy][:is_a_puppy] = false
node.default[:snoopy][:is_a_puppy] = true
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "should allow you to set a value after a 'dangling' default_unless" do
@@ -240,18 +240,18 @@ describe Chef::Node do
node.default[:snoopy][:is_a_puppy] = "what"
node.default_unless[:snoopy][:is_a_puppy]
node.default[:snoopy][:is_a_puppy] = true
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "auto-vivifies attributes created via method syntax" do
node.default.fuu.bahrr.baz = "qux"
- node.fuu.bahrr.baz.should == "qux"
+ expect(node.fuu.bahrr.baz).to eq("qux")
end
it "accesses force defaults via default!" do
node.default![:foo] = "wet bar"
node.default[:foo] = "bar"
- node[:foo].should == "wet bar"
+ expect(node[:foo]).to eq("wet bar")
end
end
@@ -259,25 +259,25 @@ describe Chef::Node do
describe "override attributes" do
it "should be set with override, without pre-declaring a hash" do
node.override[:snoopy][:is_a_puppy] = true
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "should allow you to set with override_unless without pre-declaring a hash" do
node.override_unless[:snoopy][:is_a_puppy] = false
- node[:snoopy][:is_a_puppy].should == false
+ expect(node[:snoopy][:is_a_puppy]).to eq(false)
end
it "should not allow you to set an attribute with override_unless if it already exists" do
node.override[:snoopy][:is_a_puppy] = true
node.override_unless[:snoopy][:is_a_puppy] = false
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "should allow you to set a value after an override_unless" do
# this tests for set_unless_present state bleeding between statements CHEF-3806
node.override_unless[:snoopy][:is_a_puppy] = false
node.override[:snoopy][:is_a_puppy] = true
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "should allow you to set a value after a 'dangling' override_unless" do
@@ -285,24 +285,24 @@ describe Chef::Node do
node.override_unless[:snoopy][:is_a_puppy] = "what"
node.override_unless[:snoopy][:is_a_puppy]
node.override[:snoopy][:is_a_puppy] = true
- node[:snoopy][:is_a_puppy].should == true
+ expect(node[:snoopy][:is_a_puppy]).to eq(true)
end
it "auto-vivifies attributes created via method syntax" do
node.override.fuu.bahrr.baz = "qux"
- node.fuu.bahrr.baz.should == "qux"
+ expect(node.fuu.bahrr.baz).to eq("qux")
end
it "sets force_overrides via override!" do
node.override![:foo] = "wet bar"
node.override[:foo] = "bar"
- node[:foo].should == "wet bar"
+ expect(node[:foo]).to eq("wet bar")
end
end
it "should raise an ArgumentError if you ask for an attribute that doesn't exist via method_missing" do
- lambda { node.sunshine }.should raise_error(NoMethodError)
+ expect { node.sunshine }.to raise_error(NoMethodError)
end
it "should allow you to iterate over attributes with each_attribute" do
@@ -312,10 +312,10 @@ describe Chef::Node do
node.each_attribute do |a,v|
seen_attributes[a] = v
end
- seen_attributes.should have_key("sunshine")
- seen_attributes.should have_key("canada")
- seen_attributes["sunshine"].should == "is bright"
- seen_attributes["canada"].should == "is a nice place"
+ expect(seen_attributes).to have_key("sunshine")
+ expect(seen_attributes).to have_key("canada")
+ expect(seen_attributes["sunshine"]).to eq("is bright")
+ expect(seen_attributes["canada"]).to eq("is a nice place")
end
end
@@ -327,62 +327,62 @@ describe Chef::Node do
it "consumes the run list portion of a collection of attributes and returns the remainder" do
attrs = {"run_list" => [ "role[base]", "recipe[chef::server]" ], "foo" => "bar"}
- node.consume_run_list(attrs).should == {"foo" => "bar"}
- node.run_list.should == [ "role[base]", "recipe[chef::server]" ]
+ expect(node.consume_run_list(attrs)).to eq({"foo" => "bar"})
+ expect(node.run_list).to eq([ "role[base]", "recipe[chef::server]" ])
end
it "should overwrites the run list with the run list it consumes" do
node.consume_run_list "recipes" => [ "one", "two" ]
node.consume_run_list "recipes" => [ "three" ]
- node.run_list.should == [ "three" ]
+ expect(node.run_list).to eq([ "three" ])
end
it "should not add duplicate recipes from the json attributes" do
node.run_list << "one"
node.consume_run_list "recipes" => [ "one", "two", "three" ]
- node.run_list.should == [ "one", "two", "three" ]
+ expect(node.run_list).to eq([ "one", "two", "three" ])
end
it "doesn't change the run list if no run_list is specified in the json" do
node.run_list << "role[database]"
node.consume_run_list "foo" => "bar"
- node.run_list.should == ["role[database]"]
+ expect(node.run_list).to eq(["role[database]"])
end
it "raises an exception if you provide both recipe and run_list attributes, since this is ambiguous" do
- lambda { node.consume_run_list "recipes" => "stuff", "run_list" => "other_stuff" }.should raise_error(Chef::Exceptions::AmbiguousRunlistSpecification)
+ expect { node.consume_run_list "recipes" => "stuff", "run_list" => "other_stuff" }.to raise_error(Chef::Exceptions::AmbiguousRunlistSpecification)
end
it "should add json attributes to the node" do
node.consume_external_attrs(@ohai_data, {"one" => "two", "three" => "four"})
- node.one.should eql("two")
- node.three.should eql("four")
+ expect(node.one).to eql("two")
+ expect(node.three).to eql("four")
end
it "should set the tags attribute to an empty array if it is not already defined" do
node.consume_external_attrs(@ohai_data, {})
- node.tags.should eql([])
+ expect(node.tags).to eql([])
end
it "should not set the tags attribute to an empty array if it is already defined" do
node.normal[:tags] = [ "radiohead" ]
node.consume_external_attrs(@ohai_data, {})
- node.tags.should eql([ "radiohead" ])
+ expect(node.tags).to eql([ "radiohead" ])
end
it "deep merges attributes instead of overwriting them" do
node.consume_external_attrs(@ohai_data, "one" => {"two" => {"three" => "four"}})
- node.one.to_hash.should == {"two" => {"three" => "four"}}
+ expect(node.one.to_hash).to eq({"two" => {"three" => "four"}})
node.consume_external_attrs(@ohai_data, "one" => {"abc" => "123"})
node.consume_external_attrs(@ohai_data, "one" => {"two" => {"foo" => "bar"}})
- node.one.to_hash.should == {"two" => {"three" => "four", "foo" => "bar"}, "abc" => "123"}
+ expect(node.one.to_hash).to eq({"two" => {"three" => "four", "foo" => "bar"}, "abc" => "123"})
end
it "gives attributes from JSON priority when deep merging" do
node.consume_external_attrs(@ohai_data, "one" => {"two" => {"three" => "four"}})
- node.one.to_hash.should == {"two" => {"three" => "four"}}
+ expect(node.one.to_hash).to eq({"two" => {"three" => "four"}})
node.consume_external_attrs(@ohai_data, "one" => {"two" => {"three" => "forty-two"}})
- node.one.to_hash.should == {"two" => {"three" => "forty-two"}}
+ expect(node.one.to_hash).to eq({"two" => {"three" => "forty-two"}})
end
end
@@ -394,21 +394,21 @@ describe Chef::Node do
it "sets its platform according to platform detection" do
node.consume_external_attrs(@ohai_data, {})
- node.automatic_attrs[:platform].should == 'foobuntu'
- node.automatic_attrs[:platform_version].should == '23.42'
+ expect(node.automatic_attrs[:platform]).to eq('foobuntu')
+ expect(node.automatic_attrs[:platform_version]).to eq('23.42')
end
it "consumes the run list from provided json attributes" do
node.consume_external_attrs(@ohai_data, {"run_list" => ['recipe[unicorn]']})
- node.run_list.should == ['recipe[unicorn]']
+ expect(node.run_list).to eq(['recipe[unicorn]'])
end
it "saves non-runlist json attrs for later" do
expansion = Chef::RunList::RunListExpansion.new('_default', [])
- node.run_list.stub(:expand).and_return(expansion)
+ allow(node.run_list).to receive(:expand).and_return(expansion)
node.consume_external_attrs(@ohai_data, {"foo" => "bar"})
node.expand!
- node.normal_attrs.should == {"foo" => "bar", "tags" => []}
+ expect(node.normal_attrs).to eq({"foo" => "bar", "tags" => []})
end
end
@@ -420,44 +420,44 @@ describe Chef::Node do
e.default_attributes("env default key" => "env default value")
e.override_attributes("env override key" => "env override value")
end
- Chef::Environment.should_receive(:load).with("rspec_env").and_return(@environment)
+ expect(Chef::Environment).to 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)
+ allow(node.run_list).to receive(:expand).and_return(@expansion)
end
it "sets the 'recipes' automatic attribute to the recipes in the expanded run_list" do
@expansion.recipes << 'recipe[chef::client]' << 'recipe[nginx::default]'
node.expand!
- node.automatic_attrs[:recipes].should == ['recipe[chef::client]', 'recipe[nginx::default]']
+ expect(node.automatic_attrs[:recipes]).to eq(['recipe[chef::client]', 'recipe[nginx::default]'])
end
it "sets the 'roles' automatic attribute to the expanded role list" do
@expansion.instance_variable_set(:@applied_roles, {'arf' => nil, 'countersnark' => nil})
node.expand!
- node.automatic_attrs[:roles].sort.should == ['arf', 'countersnark']
+ expect(node.automatic_attrs[:roles].sort).to eq(['arf', 'countersnark'])
end
it "applies default attributes from the environment as environment defaults" do
node.expand!
- node.attributes.env_default["env default key"].should == "env default value"
+ expect(node.attributes.env_default["env default key"]).to eq("env default value")
end
it "applies override attributes from the environment as env overrides" do
node.expand!
- node.attributes.env_override["env override key"].should == "env override value"
+ expect(node.attributes.env_override["env override key"]).to eq("env override value")
end
it "applies default attributes from roles as role defaults" do
@expansion.default_attrs["role default key"] = "role default value"
node.expand!
- node.attributes.role_default["role default key"].should == "role default value"
+ expect(node.attributes.role_default["role default key"]).to eq("role default value")
end
it "applies override attributes from roles as role overrides" do
@expansion.override_attrs["role override key"] = "role override value"
node.expand!
- node.attributes.role_override["role override key"].should == "role override value"
+ expect(node.attributes.role_override["role override key"]).to eq("role override value")
end
end
@@ -472,8 +472,8 @@ describe Chef::Node 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
+ expect(node.recipe?("nginx::module")).to be_truthy
+ expect(node.recipe?("nginx::other_module")).to be_truthy
end
end
@@ -484,11 +484,11 @@ describe Chef::Node do
end
it "finds the recipe" do
- node.recipe?("nginx::module").should be_true
+ expect(node.recipe?("nginx::module")).to be_truthy
end
it "does not find a recipe not in the run list" do
- node.recipe?("nginx::other_module").should be_false
+ expect(node.recipe?("nginx::other_module")).to be_falsey
end
end
context "when a recipe is in the expanded run list only" do
@@ -498,11 +498,11 @@ describe Chef::Node do
end
it "finds a recipe in the expanded run list" do
- node.recipe?("nginx::module").should be_true
+ expect(node.recipe?("nginx::module")).to be_truthy
end
it "does not find a recipe that's not in the run list" do
- node.recipe?("nginx::other_module").should be_false
+ expect(node.recipe?("nginx::other_module")).to be_falsey
end
end
end
@@ -516,15 +516,15 @@ describe Chef::Node do
end
it "removes default attributes" do
- node.default.should be_empty
+ expect(node.default).to be_empty
end
it "removes override attributes" do
- node.override.should be_empty
+ expect(node.override).to be_empty
end
it "leaves normal level attributes untouched" do
- node[:foo].should == "normal"
+ expect(node[:foo]).to eq("normal")
end
end
@@ -540,32 +540,32 @@ 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)
+ allow(Chef::Environment).to receive(:load).and_return(@environment)
node.apply_expansion_attributes(@expansion)
end
it "does not nuke role-only default attrs" do
- node[:d_role].should == "role only"
+ expect(node[:d_role]).to eq("role only")
end
it "does not nuke role-only override attrs" do
- node[:o_role].should == "role only"
+ expect(node[:o_role]).to eq("role only")
end
it "does not nuke env-only default attrs" do
- node[:o_env].should == "env only"
+ expect(node[:o_env]).to eq("env only")
end
it "does not nuke role-only override attrs" do
- node[:o_env].should == "env only"
+ expect(node[:o_env]).to eq("env only")
end
it "gives role defaults precedence over env defaults" do
- node[:default].should == "from role"
+ expect(node[:default]).to eq("from role")
end
it "gives env overrides precedence over role overrides" do
- node[:override].should == "from env"
+ expect(node[:override]).to eq("from env")
end
end
@@ -585,60 +585,60 @@ describe Chef::Node do
end
it "sets attributes from the files" do
- node.ldap_server.should eql("ops1prod")
- node.ldap_basedn.should eql("dc=hjksolutions,dc=com")
- node.ldap_replication_password.should eql("forsure")
- node.smokey.should eql("robinson")
+ expect(node.ldap_server).to eql("ops1prod")
+ expect(node.ldap_basedn).to eql("dc=hjksolutions,dc=com")
+ expect(node.ldap_replication_password).to eql("forsure")
+ expect(node.smokey).to eql("robinson")
end
it "gives a sensible error when attempting to load a missing attributes file" do
- lambda { node.include_attribute("nope-this::doesnt-exist") }.should raise_error(Chef::Exceptions::CookbookNotFound)
+ expect { node.include_attribute("nope-this::doesnt-exist") }.to raise_error(Chef::Exceptions::CookbookNotFound)
end
end
describe "roles" do
it "should allow you to query whether or not it has a recipe applied with role?" do
node.run_list << "role[sunrise]"
- node.role?("sunrise").should eql(true)
- node.role?("not at home").should eql(false)
+ expect(node.role?("sunrise")).to eql(true)
+ expect(node.role?("not at home")).to eql(false)
end
it "should allow you to set roles with arguments" do
node.run_list << "role[one]"
node.run_list << "role[two]"
- node.role?("one").should eql(true)
- node.role?("two").should eql(true)
+ expect(node.role?("one")).to eql(true)
+ expect(node.role?("two")).to eql(true)
end
end
describe "run_list" do
it "should have a Chef::RunList of recipes and roles that should be applied" do
- node.run_list.should be_a_kind_of(Chef::RunList)
+ expect(node.run_list).to be_a_kind_of(Chef::RunList)
end
it "should allow you to query the run list with arguments" do
node.run_list "recipe[baz]"
- node.run_list?("recipe[baz]").should eql(true)
+ expect(node.run_list?("recipe[baz]")).to eql(true)
end
it "should allow you to set the run list with arguments" do
node.run_list "recipe[baz]", "role[foo]"
- node.run_list?("recipe[baz]").should eql(true)
- node.run_list?("role[foo]").should eql(true)
+ expect(node.run_list?("recipe[baz]")).to eql(true)
+ expect(node.run_list?("role[foo]")).to eql(true)
end
end
describe "from file" do
it "should load a node from a ruby file" do
node.from_file(File.expand_path(File.join(CHEF_SPEC_DATA, "nodes", "test.rb")))
- node.name.should eql("test.example.com-short")
- node.sunshine.should eql("in")
- node.something.should eql("else")
- node.run_list.should == ["operations-master", "operations-monitoring"]
+ expect(node.name).to eql("test.example.com-short")
+ expect(node.sunshine).to eql("in")
+ expect(node.something).to eql("else")
+ expect(node.run_list).to eq(["operations-master", "operations-monitoring"])
end
it "should raise an exception if the file cannot be found or read" do
- lambda { node.from_file("/tmp/monkeydiving") }.should raise_error(IOError)
+ expect { node.from_file("/tmp/monkeydiving") }.to raise_error(IOError)
end
end
@@ -666,16 +666,16 @@ describe Chef::Node do
it "allows update of everything except name" do
node.update_from!(@example)
- node.name.should == "orig"
- node.chef_environment.should == @example.chef_environment
- node.default_attrs.should == @example.default_attrs
- node.override_attrs.should == @example.override_attrs
- node.normal_attrs.should == @example.normal_attrs
- node.run_list.should == @example.run_list
+ expect(node.name).to eq("orig")
+ expect(node.chef_environment).to eq(@example.chef_environment)
+ expect(node.default_attrs).to eq(@example.default_attrs)
+ expect(node.override_attrs).to eq(@example.override_attrs)
+ expect(node.normal_attrs).to eq(@example.normal_attrs)
+ expect(node.run_list).to eq(@example.run_list)
end
it "should not update the name of the node" do
- node.should_not_receive(:name).with(@example.name)
+ expect(node).not_to receive(:name).with(@example.name)
node.update_from!(@example)
end
end
@@ -690,19 +690,19 @@ describe Chef::Node do
node.run_list << "role[leninist]"
node.run_list << "recipe[stalinist]"
h = node.to_hash
- h["one"]["two"].should == "three"
- h["one"]["four"].should == "six"
- h["one"]["eight"].should == "nine"
- h["role"].should be_include("marxist")
- h["role"].should be_include("leninist")
- h["run_list"].should be_include("role[marxist]")
- h["run_list"].should be_include("role[leninist]")
- h["run_list"].should be_include("recipe[stalinist]")
- h["chef_environment"].should == "dev"
+ expect(h["one"]["two"]).to eq("three")
+ expect(h["one"]["four"]).to eq("six")
+ expect(h["one"]["eight"]).to eq("nine")
+ expect(h["role"]).to be_include("marxist")
+ expect(h["role"]).to be_include("leninist")
+ expect(h["run_list"]).to be_include("role[marxist]")
+ expect(h["run_list"]).to be_include("role[leninist]")
+ expect(h["run_list"]).to be_include("recipe[stalinist]")
+ expect(h["chef_environment"]).to eq("dev")
end
it 'should return an empty array for empty run_list' do
- node.to_hash["run_list"].should == []
+ expect(node.to_hash["run_list"]).to eq([])
end
end
@@ -710,13 +710,13 @@ describe Chef::Node do
it "should serialize itself as json", :json => true do
node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
json = Chef::JSONCompat.to_json(node)
- json.should =~ /json_class/
- json.should =~ /name/
- json.should =~ /chef_environment/
- json.should =~ /normal/
- json.should =~ /default/
- json.should =~ /override/
- json.should =~ /run_list/
+ expect(json).to match(/json_class/)
+ expect(json).to match(/name/)
+ expect(json).to match(/chef_environment/)
+ expect(json).to match(/normal/)
+ expect(json).to match(/default/)
+ expect(json).to match(/override/)
+ expect(json).to match(/run_list/)
end
it 'should serialize valid json with a run list', :json => true do
@@ -725,32 +725,32 @@ describe Chef::Node do
node.run_list << {"type" => "role", "name" => 'Cthulu'}
node.run_list << {"type" => "role", "name" => 'Hastur'}
json = Chef::JSONCompat.to_json(node)
- json.should =~ /\"run_list\":\[\"role\[Cthulu\]\",\"role\[Hastur\]\"\]/
+ expect(json).to match(/\"run_list\":\[\"role\[Cthulu\]\",\"role\[Hastur\]\"\]/)
end
it "should serialize the correct run list", :json => true do
node.run_list << "role[marxist]"
node.run_list << "role[leninist]"
node.override_runlist << "role[stalinist]"
- node.run_list.should be_include("role[stalinist]")
+ expect(node.run_list).to be_include("role[stalinist]")
json = Chef::JSONCompat.to_json(node)
- json.should =~ /\"run_list\":\[\"role\[marxist\]\",\"role\[leninist\]\"\]/
+ expect(json).to match(/\"run_list\":\[\"role\[marxist\]\",\"role\[leninist\]\"\]/)
end
it "merges the override components into a combined override object" do
node.attributes.role_override["role override"] = "role override"
node.attributes.env_override["env override"] = "env override"
node_for_json = node.for_json
- node_for_json["override"]["role override"].should == "role override"
- node_for_json["override"]["env override"].should == "env override"
+ expect(node_for_json["override"]["role override"]).to eq("role override")
+ expect(node_for_json["override"]["env override"]).to eq("env override")
end
it "merges the default components into a combined default object" do
node.attributes.role_default["role default"] = "role default"
node.attributes.env_default["env default"] = "env default"
node_for_json = node.for_json
- node_for_json["default"]["role default"].should == "role default"
- node_for_json["default"]["env default"].should == "env default"
+ expect(node_for_json["default"]["role default"]).to eq("role default")
+ expect(node_for_json["default"]["env default"]).to eq("env default")
end
@@ -758,13 +758,13 @@ describe Chef::Node do
node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
json = Chef::JSONCompat.to_json(node)
serialized_node = Chef::JSONCompat.from_json(json)
- serialized_node.should be_a_kind_of(Chef::Node)
- serialized_node.name.should eql(node.name)
- serialized_node.chef_environment.should eql(node.chef_environment)
+ expect(serialized_node).to be_a_kind_of(Chef::Node)
+ expect(serialized_node.name).to eql(node.name)
+ expect(serialized_node.chef_environment).to eql(node.chef_environment)
node.each_attribute do |k,v|
- serialized_node[k].should eql(v)
+ expect(serialized_node[k]).to eql(v)
end
- serialized_node.run_list.should == node.run_list
+ expect(serialized_node.run_list).to eq(node.run_list)
end
include_examples "to_json equalivent to Chef::JSONCompat.to_json" do
@@ -778,45 +778,45 @@ describe Chef::Node do
describe "to_s" do
it "should turn into a string like node[name]" do
node.name("airplane")
- node.to_s.should eql("node[airplane]")
+ expect(node.to_s).to eql("node[airplane]")
end
end
describe "api model" do
before(:each) do
@rest = double("Chef::REST")
- Chef::REST.stub(:new).and_return(@rest)
+ allow(Chef::REST).to receive(:new).and_return(@rest)
@query = double("Chef::Search::Query")
- Chef::Search::Query.stub(:new).and_return(@query)
+ allow(Chef::Search::Query).to receive(:new).and_return(@query)
end
describe "list" do
describe "inflated" do
it "should return a hash of node names and objects" do
n1 = double("Chef::Node", :name => "one")
- @query.should_receive(:search).with(:node).and_yield(n1)
+ expect(@query).to receive(:search).with(:node).and_yield(n1)
r = Chef::Node.list(true)
- r["one"].should == n1
+ expect(r["one"]).to eq(n1)
end
end
it "should return a hash of node names and urls" do
- @rest.should_receive(:get_rest).and_return({ "one" => "http://foo" })
+ expect(@rest).to receive(:get_rest).and_return({ "one" => "http://foo" })
r = Chef::Node.list
- r["one"].should == "http://foo"
+ expect(r["one"]).to eq("http://foo")
end
end
describe "load" do
it "should load a node by name" do
- @rest.should_receive(:get_rest).with("nodes/monkey").and_return("foo")
- Chef::Node.load("monkey").should == "foo"
+ expect(@rest).to receive(:get_rest).with("nodes/monkey").and_return("foo")
+ expect(Chef::Node.load("monkey")).to eq("foo")
end
end
describe "destroy" do
it "should destroy a node" do
- @rest.should_receive(:delete_rest).with("nodes/monkey").and_return("foo")
+ expect(@rest).to receive(:delete_rest).with("nodes/monkey").and_return("foo")
node.name("monkey")
node.destroy
end
@@ -825,25 +825,25 @@ describe Chef::Node do
describe "save" do
it "should update a node if it already exists" do
node.name("monkey")
- node.stub(:data_for_save).and_return({})
- @rest.should_receive(:put_rest).with("nodes/monkey", {}).and_return("foo")
+ allow(node).to receive(:data_for_save).and_return({})
+ expect(@rest).to receive(:put_rest).with("nodes/monkey", {}).and_return("foo")
node.save
end
it "should not try and create if it can update" do
node.name("monkey")
- node.stub(:data_for_save).and_return({})
- @rest.should_receive(:put_rest).with("nodes/monkey", {}).and_return("foo")
- @rest.should_not_receive(:post_rest)
+ allow(node).to receive(:data_for_save).and_return({})
+ expect(@rest).to receive(:put_rest).with("nodes/monkey", {}).and_return("foo")
+ expect(@rest).not_to receive(:post_rest)
node.save
end
it "should create if it cannot update" do
node.name("monkey")
- node.stub(:data_for_save).and_return({})
+ allow(node).to receive(:data_for_save).and_return({})
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", {})
+ expect(@rest).to receive(:put_rest).and_raise(Net::HTTPServerException.new("foo", exception))
+ expect(@rest).to receive(:post_rest).with("nodes", {})
node.save
end
@@ -856,8 +856,8 @@ describe Chef::Node do
end
it "should not save" do
node.name("monkey")
- @rest.should_not_receive(:put_rest)
- @rest.should_not_receive(:post_rest)
+ expect(@rest).not_to receive(:put_rest)
+ expect(@rest).not_to receive(:post_rest)
node.save
end
end
@@ -900,8 +900,8 @@ describe Chef::Node do
}
node.name("picky-monkey")
- node.stub(:for_json).and_return(data)
- @rest.should_receive(:put_rest).with("nodes/picky-monkey", selected_data).and_return("foo")
+ allow(node).to receive(:for_json).and_return(data)
+ expect(@rest).to receive(:put_rest).with("nodes/picky-monkey", selected_data).and_return("foo")
node.save
end
@@ -923,8 +923,8 @@ describe Chef::Node do
}
node.name("picky-monkey")
- node.stub(:for_json).and_return(data)
- @rest.should_receive(:put_rest).with("nodes/picky-monkey", selected_data).and_return("foo")
+ allow(node).to receive(:for_json).and_return(data)
+ expect(@rest).to receive(:put_rest).with("nodes/picky-monkey", selected_data).and_return("foo")
node.save
end
end