diff options
author | Claire McQuin <claire@getchef.com> | 2014-10-29 15:14:22 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-10-29 15:59:04 -0700 |
commit | 5fed7a65a2f024d964ecf2de1bcf2911cf8a600c (patch) | |
tree | 14cc6968e4fe4fd2485c0211088b25c645a80a4b /spec/unit/recipe_spec.rb | |
parent | b92c309b0f1aa0837f76ab89d6c81c36076ceca9 (diff) | |
download | chef-5fed7a65a2f024d964ecf2de1bcf2911cf8a600c.tar.gz |
Update to RSpec 3.
Diffstat (limited to 'spec/unit/recipe_spec.rb')
-rw-r--r-- | spec/unit/recipe_spec.rb | 165 |
1 files changed, 83 insertions, 82 deletions
diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 0e660dc0cc..1b7506d965 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -52,50 +52,50 @@ describe Chef::Recipe do describe "method_missing" do describe "resources" do it "should load a two word (zen_master) resource" do - lambda do + expect do recipe.zen_master "monkey" do peace true end - end.should_not raise_error + end.not_to raise_error end it "should load a one word (cat) resource" do - lambda do + expect do recipe.cat "loulou" do pretty_kitty true end - end.should_not raise_error + end.not_to raise_error end it "should load a four word (one_two_three_four) resource" do - lambda do + expect do recipe.one_two_three_four "numbers" do i_can_count true end - end.should_not raise_error + end.not_to raise_error end it "should throw an error if you access a resource that we can't find" do - lambda { recipe.not_home("not_home_resource") }.should raise_error(NameError) + expect { recipe.not_home("not_home_resource") }.to raise_error(NameError) end it "should require a name argument" do - lambda { + expect { recipe.cat - }.should raise_error(ArgumentError, "You must supply a name when declaring a cat resource") + }.to raise_error(ArgumentError, "You must supply a name when declaring a cat resource") end it "should allow regular errors (not NameErrors) to pass unchanged" do - lambda { + expect { recipe.cat("felix") { raise ArgumentError, "You Suck" } - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should add our zen_master to the collection" do recipe.zen_master "monkey" do peace true end - run_context.resource_collection.lookup("zen_master[monkey]").name.should eql("monkey") + expect(run_context.resource_collection.lookup("zen_master[monkey]").name).to eql("monkey") end it "should add our zen masters to the collection in the order they appear" do @@ -105,15 +105,15 @@ describe Chef::Recipe do end end - run_context.resource_collection.map{|r| r.name}.should eql(["monkey", "dog", "cat"]) + expect(run_context.resource_collection.map{|r| r.name}).to eql(["monkey", "dog", "cat"]) end it "should return the new resource after creating it" do res = recipe.zen_master "makoto" do peace true end - res.resource_name.should eql(:zen_master) - res.name.should eql("makoto") + expect(res.resource_name).to eql(:zen_master) + expect(res.name).to eql("makoto") end describe "should locate platform mapped resources" do @@ -124,7 +124,7 @@ describe Chef::Recipe do node.automatic[:platform] = "television" node.automatic[:platform_version] = "123" res = recipe.laughter "timmy" - res.name.should eql("timmy") + expect(res.name).to eql("timmy") res.kind_of?(ShaunTheSheep) end @@ -132,7 +132,7 @@ describe Chef::Recipe do YourMom = Class.new(Chef::Resource) YourMom.provides :love_and_caring res = recipe.love_and_caring "mommy" - res.name.should eql("mommy") + expect(res.name).to eql("mommy") res.kind_of?(YourMom) end @@ -147,13 +147,13 @@ describe Chef::Recipe do end it "applies attributes from the block to the resource" do - zm_resource.something.should == "bvb" + expect(zm_resource.something).to eq("bvb") end it "sets contextual attributes on the resource" do - zm_resource.recipe_name.should == "test" - zm_resource.cookbook_name.should == "hjk" - zm_resource.source_line.should include(__FILE__) + expect(zm_resource.recipe_name).to eq("test") + expect(zm_resource.cookbook_name).to eq("hjk") + expect(zm_resource.source_line).to include(__FILE__) end it "does not add the resource to the resource collection" do @@ -171,18 +171,18 @@ describe Chef::Recipe do end it "applies attributes from the block to the resource" do - zm_resource.something.should == "bvb" + expect(zm_resource.something).to eq("bvb") end it "sets contextual attributes on the resource" do - zm_resource.recipe_name.should == "test" - zm_resource.cookbook_name.should == "hjk" - zm_resource.source_line.should include(__FILE__) + expect(zm_resource.recipe_name).to eq("test") + expect(zm_resource.cookbook_name).to eq("hjk") + expect(zm_resource.source_line).to include(__FILE__) end it "adds the resource to the resource collection" do zm_resource # force let binding evaluation - run_context.resource_collection.resources(:zen_master => "klopp").should == zm_resource + expect(run_context.resource_collection.resources(:zen_master => "klopp")).to eq(zm_resource) end end @@ -201,7 +201,7 @@ describe Chef::Recipe do it "defines the resource using the declaration name with short name" do resource_follower - run_context.resource_collection.lookup("follower[srst]").should_not be_nil + expect(run_context.resource_collection.lookup("follower[srst]")).not_to be_nil end end @@ -215,25 +215,25 @@ describe Chef::Recipe do it "defines the resource using the declaration name with long name" do resource_zn_follower - run_context.resource_collection.lookup("zen_follower[srst]").should_not be_nil + expect(run_context.resource_collection.lookup("zen_follower[srst]")).not_to be_nil end end describe "when attempting to create a resource of an invalid type" do it "gives a sane error message when using method_missing" do - lambda do + expect do recipe.no_such_resource("foo") - end.should raise_error(NoMethodError, %q[No resource or method named `no_such_resource' for `Chef::Recipe "test"']) + end.to raise_error(NoMethodError, %q[No resource or method named `no_such_resource' for `Chef::Recipe "test"']) end it "gives a sane error message when using method_missing 'bare'" do - lambda do + expect do recipe.instance_eval do # Giving an argument will change this from NameError to NoMethodError no_such_resource end - end.should raise_error(NameError, %q[No resource, method, or local variable named `no_such_resource' for `Chef::Recipe "test"']) + end.to raise_error(NameError, %q[No resource, method, or local variable named `no_such_resource' for `Chef::Recipe "test"']) end it "gives a sane error message when using build_resource" do @@ -249,11 +249,11 @@ describe Chef::Recipe do describe "when creating a resource that contains an error in the attributes block" do it "does not obfuscate the error source" do - lambda do + expect do recipe.zen_master("klopp") do this_method_doesnt_exist end - end.should raise_error(NoMethodError, "undefined method `this_method_doesnt_exist' for Chef::Resource::ZenMaster") + end.to raise_error(NoMethodError, "undefined method `this_method_doesnt_exist' for Chef::Resource::ZenMaster") end @@ -280,28 +280,28 @@ describe Chef::Recipe do end it "copies attributes from the first resource" do - duplicated_resource.something.should == "bvb09" + expect(duplicated_resource.something).to eq("bvb09") end it "does not copy the action from the first resource" do - original_resource.action.should == [:score] - duplicated_resource.action.should == :nothing + expect(original_resource.action).to eq([:score]) + expect(duplicated_resource.action).to eq(:nothing) end it "does not copy the source location of the first resource" do # sanity check source location: - original_resource.source_line.should include(__FILE__) - duplicated_resource.source_line.should include(__FILE__) + expect(original_resource.source_line).to include(__FILE__) + expect(duplicated_resource.source_line).to include(__FILE__) # actual test: - original_resource.source_line.should_not == duplicated_resource.source_line + expect(original_resource.source_line).not_to eq(duplicated_resource.source_line) end it "sets the cookbook name on the cloned resource to that resource's cookbook" do - duplicated_resource.cookbook_name.should == "second_cb" + expect(duplicated_resource.cookbook_name).to eq("second_cb") end it "sets the recipe name on the cloned resource to that resoure's recipe" do - duplicated_resource.recipe_name.should == "second_recipe" + expect(duplicated_resource.recipe_name).to eq("second_recipe") end end @@ -319,8 +319,8 @@ describe Chef::Recipe do recipe.crow "mine" do peace true end - run_context.resource_collection.resources(:zen_master => "lao tzu").name.should eql("lao tzu") - run_context.resource_collection.resources(:zen_master => "lao tzu").something.should eql(true) + expect(run_context.resource_collection.resources(:zen_master => "lao tzu").name).to eql("lao tzu") + expect(run_context.resource_collection.resources(:zen_master => "lao tzu").something).to eql(true) end it "should set the node on defined resources" do @@ -336,7 +336,7 @@ describe Chef::Recipe do recipe.crow "mine" do something node[:foo] end - recipe.resources(:zen_master => "lao tzu").something.should eql(false) + expect(recipe.resources(:zen_master => "lao tzu").something).to eql(false) end it "should return the last statement in the definition as the retval" do @@ -345,9 +345,10 @@ describe Chef::Recipe do "the return val" end run_context.definitions[:crow] = crow_define - recipe.crow "mine" do + crow_block = recipe.crow "mine" do peace true - end.should eql("the return val") + end + expect(crow_block).to eql("the return val") end end @@ -360,8 +361,8 @@ describe Chef::Recipe do peace = true end CODE - lambda { recipe.instance_eval(code) }.should_not raise_error - recipe.resources(:zen_master => "gnome").name.should eql("gnome") + expect { recipe.instance_eval(code) }.not_to raise_error + expect(recipe.resources(:zen_master => "gnome").name).to eql("gnome") end end @@ -370,7 +371,7 @@ describe Chef::Recipe do code = <<-CODE exec 'do_not_try_to_exec' CODE - lambda { recipe.instance_eval(code) }.should raise_error(Chef::Exceptions::ResourceNotFound) + expect { recipe.instance_eval(code) }.to raise_error(Chef::Exceptions::ResourceNotFound) end end @@ -378,50 +379,50 @@ describe Chef::Recipe do it "should load a resource from a ruby file" do recipe.from_file(File.join(CHEF_SPEC_DATA, "recipes", "test.rb")) res = recipe.resources(:file => "/etc/nsswitch.conf") - res.name.should eql("/etc/nsswitch.conf") - res.action.should eql([:create]) - res.owner.should eql("root") - res.group.should eql("root") - res.mode.should eql(0644) + expect(res.name).to eql("/etc/nsswitch.conf") + expect(res.action).to eql([:create]) + expect(res.owner).to eql("root") + expect(res.group).to eql("root") + expect(res.mode).to eql(0644) end it "should raise an exception if the file cannot be found or read" do - lambda { recipe.from_file("/tmp/monkeydiving") }.should raise_error(IOError) + expect { recipe.from_file("/tmp/monkeydiving") }.to raise_error(IOError) end end describe "include_recipe" do it "should evaluate another recipe with include_recipe" do - node.should_receive(:loaded_recipe).with(:openldap, "gigantor") - run_context.stub(:unreachable_cookbook?).with(:openldap).and_return(false) + expect(node).to receive(:loaded_recipe).with(:openldap, "gigantor") + allow(run_context).to receive(:unreachable_cookbook?).with(:openldap).and_return(false) run_context.include_recipe "openldap::gigantor" res = run_context.resource_collection.resources(:cat => "blanket") - res.name.should eql("blanket") - res.pretty_kitty.should eql(false) + expect(res.name).to eql("blanket") + expect(res.pretty_kitty).to eql(false) end it "should load the default recipe for a cookbook if include_recipe is called without a ::" do - node.should_receive(:loaded_recipe).with(:openldap, "default") - run_context.stub(:unreachable_cookbook?).with(:openldap).and_return(false) + expect(node).to receive(:loaded_recipe).with(:openldap, "default") + allow(run_context).to receive(:unreachable_cookbook?).with(:openldap).and_return(false) run_context.include_recipe "openldap" res = run_context.resource_collection.resources(:cat => "blanket") - res.name.should eql("blanket") - res.pretty_kitty.should eql(true) + expect(res.name).to eql("blanket") + expect(res.pretty_kitty).to eql(true) end it "should store that it has seen a recipe in the run_context" do - node.should_receive(:loaded_recipe).with(:openldap, "default") - run_context.stub(:unreachable_cookbook?).with(:openldap).and_return(false) + expect(node).to receive(:loaded_recipe).with(:openldap, "default") + allow(run_context).to receive(:unreachable_cookbook?).with(:openldap).and_return(false) run_context.include_recipe "openldap" - run_context.loaded_recipe?("openldap").should be_true + expect(run_context.loaded_recipe?("openldap")).to be_truthy end it "should not include the same recipe twice" do - node.should_receive(:loaded_recipe).with(:openldap, "default").exactly(:once) - run_context.stub(:unreachable_cookbook?).with(:openldap).and_return(false) - cookbook_collection[:openldap].should_receive(:load_recipe).with("default", run_context) + expect(node).to receive(:loaded_recipe).with(:openldap, "default").exactly(:once) + allow(run_context).to receive(:unreachable_cookbook?).with(:openldap).and_return(false) + expect(cookbook_collection[:openldap]).to receive(:load_recipe).with("default", run_context) recipe.include_recipe "openldap" - cookbook_collection[:openldap].should_not_receive(:load_recipe).with("default", run_context) + expect(cookbook_collection[:openldap]).not_to receive(:load_recipe).with("default", run_context) recipe.include_recipe "openldap" end end @@ -431,55 +432,55 @@ describe Chef::Recipe do let(:node) { Chef::Node.new } it "should return false for any tags" do - recipe.tagged?("foo").should be(false) + expect(recipe.tagged?("foo")).to be(false) end end it "should set tags via tag" do recipe.tag "foo" - node[:tags].should include("foo") + expect(node[:tags]).to include("foo") end it "should set multiple tags via tag" do recipe.tag "foo", "bar" - node[:tags].should include("foo") - node[:tags].should include("bar") + expect(node[:tags]).to include("foo") + expect(node[:tags]).to include("bar") end it "should not set the same tag twice via tag" do recipe.tag "foo" recipe.tag "foo" - node[:tags].should eql([ "foo" ]) + expect(node[:tags]).to eql([ "foo" ]) end it "should return the current list of tags from tag with no arguments" do recipe.tag "foo" - recipe.tag.should eql([ "foo" ]) + expect(recipe.tag).to eql([ "foo" ]) end it "should return true from tagged? if node is tagged" do recipe.tag "foo" - recipe.tagged?("foo").should be(true) + expect(recipe.tagged?("foo")).to be(true) end it "should return false from tagged? if node is not tagged" do - recipe.tagged?("foo").should be(false) + expect(recipe.tagged?("foo")).to be(false) end it "should return false from tagged? if node is not tagged" do - recipe.tagged?("foo").should be(false) + expect(recipe.tagged?("foo")).to be(false) end it "should remove a tag from the tag list via untag" do recipe.tag "foo" recipe.untag "foo" - node[:tags].should eql([]) + expect(node[:tags]).to eql([]) end it "should remove multiple tags from the tag list via untag" do recipe.tag "foo", "bar" recipe.untag "bar", "foo" - node[:tags].should eql([]) + expect(node[:tags]).to eql([]) end end end |