diff options
Diffstat (limited to 'spec/unit/cookbook_version_spec.rb')
-rw-r--r-- | spec/unit/cookbook_version_spec.rb | 338 |
1 files changed, 98 insertions, 240 deletions
diff --git a/spec/unit/cookbook_version_spec.rb b/spec/unit/cookbook_version_spec.rb index 8436e5c480..440dd9da6c 100644 --- a/spec/unit/cookbook_version_spec.rb +++ b/spec/unit/cookbook_version_spec.rb @@ -24,76 +24,54 @@ describe Chef::CookbookVersion do end it "has a name" do - @cookbook_version.name.should == 'tatft' + expect(@cookbook_version.name).to eq('tatft') end it "has no attribute files" do - @cookbook_version.attribute_filenames.should be_empty + expect(@cookbook_version.attribute_filenames).to be_empty end it "has no resource definition files" do - @cookbook_version.definition_filenames.should be_empty + expect(@cookbook_version.definition_filenames).to be_empty end it "has no cookbook files" do - @cookbook_version.file_filenames.should be_empty + expect(@cookbook_version.file_filenames).to be_empty end it "has no recipe files" do - @cookbook_version.recipe_filenames.should be_empty + expect(@cookbook_version.recipe_filenames).to be_empty end it "has no library files" do - @cookbook_version.library_filenames.should be_empty + expect(@cookbook_version.library_filenames).to be_empty end it "has no LWRP resource files" do - @cookbook_version.resource_filenames.should be_empty + expect(@cookbook_version.resource_filenames).to be_empty end it "has no LWRP provider files" do - @cookbook_version.provider_filenames.should be_empty + expect(@cookbook_version.provider_filenames).to be_empty end it "has no metadata files" do - @cookbook_version.metadata_filenames.should be_empty + expect(@cookbook_version.metadata_filenames).to be_empty end it "is not frozen" do - @cookbook_version.should_not be_frozen_version + expect(@cookbook_version).not_to be_frozen_version end it "can be frozen" do @cookbook_version.freeze_version - @cookbook_version.should be_frozen_version - end - - it "is \"ready\"" do - # WTF is this? what are the valid states? and why aren't they set with encapsulating methods? - # [Dan 15-Jul-2010] - @cookbook_version.status.should == :ready + expect(@cookbook_version).to be_frozen_version end it "has empty metadata" do - @cookbook_version.metadata.should == Chef::Cookbook::Metadata.new - end - - it "creates a manifest hash of its contents" do - expected = {"recipes"=>[], - "definitions"=>[], - "libraries"=>[], - "attributes"=>[], - "files"=>[], - "templates"=>[], - "resources"=>[], - "providers"=>[], - "root_files"=>[], - "cookbook_name"=>"tatft", - "metadata"=>Chef::Cookbook::Metadata.new, - "version"=>"0.0.0", - "name"=>"tatft-0.0.0"} - @cookbook_version.manifest.should == expected + expect(@cookbook_version.metadata).to eq(Chef::Cookbook::Metadata.new) end + end describe "with a cookbook directory named tatft" do @@ -141,93 +119,14 @@ describe Chef::CookbookVersion do @node.name("testing") end - it "generates a manifest containing the cookbook's files" do - manifest = @cookbook_version.manifest - - manifest["metadata"].should == Chef::Cookbook::Metadata.new - manifest["cookbook_name"].should == "tatft" - - manifest["recipes"].should have(1).recipe_file - - recipe = manifest["recipes"].first - recipe["name"].should == "default.rb" - recipe["path"].should == "recipes/default.rb" - recipe["checksum"].should match(MD5) - recipe["specificity"].should == "default" - - manifest["definitions"].should have(1).definition_file - - definition = manifest["definitions"].first - definition["name"].should == "runit_service.rb" - definition["path"].should == "definitions/runit_service.rb" - definition["checksum"].should match(MD5) - definition["specificity"].should == "default" - - manifest["libraries"].should have(1).library_file - - library = manifest["libraries"].first - library["name"].should == "ownage.rb" - library["path"].should == "libraries/ownage.rb" - library["checksum"].should match(MD5) - library["specificity"].should == "default" - - manifest["attributes"].should have(1).attribute_file - - attribute_file = manifest["attributes"].first - attribute_file["name"].should == "default.rb" - attribute_file["path"].should == "attributes/default.rb" - attribute_file["checksum"].should match(MD5) - attribute_file["specificity"].should == "default" - - manifest["files"].should have(1).cookbook_file - - cookbook_file = manifest["files"].first - cookbook_file["name"].should == "giant_blob.tgz" - cookbook_file["path"].should == "files/default/giant_blob.tgz" - cookbook_file["checksum"].should match(MD5) - cookbook_file["specificity"].should == "default" - - manifest["templates"].should have(1).template - - template = manifest["templates"].first - template["name"].should == "configuration.erb" - template["path"].should == "templates/default/configuration.erb" - template["checksum"].should match(MD5) - template["specificity"].should == "default" - - manifest["resources"].should have(1).lwr - - lwr = manifest["resources"].first - lwr["name"].should == "lwr.rb" - lwr["path"].should == "resources/lwr.rb" - lwr["checksum"].should match(MD5) - lwr["specificity"].should == "default" - - manifest["providers"].should have(1).lwp - - lwp = manifest["providers"].first - lwp["name"].should == "lwp.rb" - lwp["path"].should == "providers/lwp.rb" - lwp["checksum"].should match(MD5) - lwp["specificity"].should == "default" - - manifest["root_files"].should have(1).file_in_the_cookbook_root - - readme = manifest["root_files"].first - readme["name"].should == "README.rdoc" - readme["path"].should == "README.rdoc" - readme["checksum"].should match(MD5) - readme["specificity"].should == "default" - end - it "determines whether a template is available for a given node" do - @cookbook_version.should have_template_for_node(@node, "configuration.erb") - @cookbook_version.should_not have_template_for_node(@node, "missing.erb") + expect(@cookbook_version).to have_template_for_node(@node, "configuration.erb") + expect(@cookbook_version).not_to have_template_for_node(@node, "missing.erb") end it "determines whether a cookbook_file is available for a given node" do - @cookbook_version.should have_cookbook_file_for_node(@node, "giant_blob.tgz") - @cookbook_version.should_not have_cookbook_file_for_node(@node, "missing.txt") + expect(@cookbook_version).to have_cookbook_file_for_node(@node, "giant_blob.tgz") + expect(@cookbook_version).not_to have_cookbook_file_for_node(@node, "missing.txt") end describe "raises an error when attempting to load a missing cookbook_file and" do @@ -243,112 +142,16 @@ describe Chef::CookbookVersion do it "describes the cookbook and version" do useful_explanation = Regexp.new(Regexp.escape("Cookbook 'tatft' (0.0.0) does not contain")) - @attempt_to_load_file.should raise_error(Chef::Exceptions::FileNotFound, useful_explanation) + expect(@attempt_to_load_file).to raise_error(Chef::Exceptions::FileNotFound, useful_explanation) end it "lists suggested places to look" do useful_explanation = Regexp.new(Regexp.escape("files/default/no-such-thing.txt")) - @attempt_to_load_file.should raise_error(Chef::Exceptions::FileNotFound, useful_explanation) + expect(@attempt_to_load_file).to raise_error(Chef::Exceptions::FileNotFound, useful_explanation) end end end - describe "and a cookbook_version with a different name" do - before do - # Currently the cookbook loader finds all the files then tells CookbookVersion - # where they are. - @cookbook_version = Chef::CookbookVersion.new("blarghle", @cookbook_root) - @cookbook_version.attribute_filenames = @cookbook[:attribute_filenames] - @cookbook_version.definition_filenames = @cookbook[:definition_filenames] - @cookbook_version.recipe_filenames = @cookbook[:recipe_filenames] - @cookbook_version.template_filenames = @cookbook[:template_filenames] - @cookbook_version.file_filenames = @cookbook[:file_filenames] - @cookbook_version.library_filenames = @cookbook[:library_filenames] - @cookbook_version.resource_filenames = @cookbook[:resource_filenames] - @cookbook_version.provider_filenames = @cookbook[:provider_filenames] - @cookbook_version.root_filenames = @cookbook[:root_filenames] - @cookbook_version.metadata_filenames = @cookbook[:metadata_filenames] - end - - it "generates a manifest containing the cookbook's files" do - manifest = @cookbook_version.manifest - - manifest["metadata"].should == Chef::Cookbook::Metadata.new - manifest["cookbook_name"].should == "blarghle" - - manifest["recipes"].should have(1).recipe_file - - recipe = manifest["recipes"].first - recipe["name"].should == "default.rb" - recipe["path"].should == "recipes/default.rb" - recipe["checksum"].should match(MD5) - recipe["specificity"].should == "default" - - manifest["definitions"].should have(1).definition_file - - definition = manifest["definitions"].first - definition["name"].should == "runit_service.rb" - definition["path"].should == "definitions/runit_service.rb" - definition["checksum"].should match(MD5) - definition["specificity"].should == "default" - - manifest["libraries"].should have(1).library_file - - library = manifest["libraries"].first - library["name"].should == "ownage.rb" - library["path"].should == "libraries/ownage.rb" - library["checksum"].should match(MD5) - library["specificity"].should == "default" - - manifest["attributes"].should have(1).attribute_file - - attribute_file = manifest["attributes"].first - attribute_file["name"].should == "default.rb" - attribute_file["path"].should == "attributes/default.rb" - attribute_file["checksum"].should match(MD5) - attribute_file["specificity"].should == "default" - - manifest["files"].should have(1).cookbook_file - - cookbook_file = manifest["files"].first - cookbook_file["name"].should == "giant_blob.tgz" - cookbook_file["path"].should == "files/default/giant_blob.tgz" - cookbook_file["checksum"].should match(MD5) - cookbook_file["specificity"].should == "default" - - manifest["templates"].should have(1).template - - template = manifest["templates"].first - template["name"].should == "configuration.erb" - template["path"].should == "templates/default/configuration.erb" - template["checksum"].should match(MD5) - template["specificity"].should == "default" - - manifest["resources"].should have(1).lwr - - lwr = manifest["resources"].first - lwr["name"].should == "lwr.rb" - lwr["path"].should == "resources/lwr.rb" - lwr["checksum"].should match(MD5) - lwr["specificity"].should == "default" - - manifest["providers"].should have(1).lwp - - lwp = manifest["providers"].first - lwp["name"].should == "lwp.rb" - lwp["path"].should == "providers/lwp.rb" - lwp["checksum"].should match(MD5) - lwp["specificity"].should == "default" - - manifest["root_files"].should have(1).file_in_the_cookbook_root - - readme = manifest["root_files"].first - readme["name"].should == "README.rdoc" - readme["path"].should == "README.rdoc" - readme["checksum"].should match(MD5) - readme["specificity"].should == "default" - end - end end describe 'with a cookbook directory named cookbook2 that has unscoped files' do @@ -389,43 +192,43 @@ describe Chef::CookbookVersion do end it "should see a template" do - @cookbook_version.should have_template_for_node(@node, "test.erb") + expect(@cookbook_version).to have_template_for_node(@node, "test.erb") end it "should see a template using an array lookup" do - @cookbook_version.should have_template_for_node(@node, ["test.erb"]) + expect(@cookbook_version).to have_template_for_node(@node, ["test.erb"]) end - it "should see a template using an array lookup with non-existant elements" do - @cookbook_version.should have_template_for_node(@node, ["missing.txt", "test.erb"]) + it "should see a template using an array lookup with non-existent elements" do + expect(@cookbook_version).to have_template_for_node(@node, ["missing.txt", "test.erb"]) end it "should see a file" do - @cookbook_version.should have_cookbook_file_for_node(@node, "test.txt") + expect(@cookbook_version).to have_cookbook_file_for_node(@node, "test.txt") end it "should see a file using an array lookup" do - @cookbook_version.should have_cookbook_file_for_node(@node, ["test.txt"]) + expect(@cookbook_version).to have_cookbook_file_for_node(@node, ["test.txt"]) end - it "should see a file using an array lookup with non-existant elements" do - @cookbook_version.should have_cookbook_file_for_node(@node, ["missing.txt", "test.txt"]) + it "should see a file using an array lookup with non-existent elements" do + expect(@cookbook_version).to have_cookbook_file_for_node(@node, ["missing.txt", "test.txt"]) end - it "should not see a non-existant template" do - @cookbook_version.should_not have_template_for_node(@node, "missing.erb") + it "should not see a non-existent template" do + expect(@cookbook_version).not_to have_template_for_node(@node, "missing.erb") end - it "should not see a non-existant template using an array lookup" do - @cookbook_version.should_not have_template_for_node(@node, ["missing.erb"]) + it "should not see a non-existent template using an array lookup" do + expect(@cookbook_version).not_to have_template_for_node(@node, ["missing.erb"]) end - it "should not see a non-existant file" do - @cookbook_version.should_not have_cookbook_file_for_node(@node, "missing.txt") + it "should not see a non-existent file" do + expect(@cookbook_version).not_to have_cookbook_file_for_node(@node, "missing.txt") end - it "should not see a non-existant file using an array lookup" do - @cookbook_version.should_not have_cookbook_file_for_node(@node, ["missing.txt"]) + it "should not see a non-existent file using an array lookup" do + expect(@cookbook_version).not_to have_cookbook_file_for_node(@node, ["missing.txt"]) end end @@ -453,9 +256,9 @@ describe Chef::CookbookVersion do lg = Chef::CookbookVersion.new("foo", '/tmp/blah') sm.version = smaller lg.version = larger - sm.should be < lg - lg.should be > sm - sm.should_not == lg + expect(sm).to be < lg + expect(lg).to be > sm + expect(sm).not_to eq(lg) end end @@ -464,7 +267,7 @@ describe Chef::CookbookVersion do b = Chef::CookbookVersion.new("foo", '/tmp/blah') a.version = "1.2" b.version = "1.2.0" - a.should == b + expect(a).to eq(b) end @@ -473,7 +276,7 @@ describe Chef::CookbookVersion do apt.version = "1.0" god = Chef::CookbookVersion.new "god", '/tmp/blah' god.version = "2.0" - lambda {apt <=> god}.should raise_error(Chef::Exceptions::CookbookVersionNameMismatch) + expect {apt <=> god}.to raise_error(Chef::Exceptions::CookbookVersionNameMismatch) end end @@ -493,14 +296,69 @@ describe Chef::CookbookVersion do "1 2 3", "1-2-3", "1_2_3", "1.2_3", "1.2-3"] the_error = Chef::Exceptions::InvalidCookbookVersion bad_versions.each do |v| - lambda {@cbv.version = v}.should raise_error(the_error) + expect {@cbv.version = v}.to raise_error(the_error) end end end - include_examples "to_json equalivent to Chef::JSONCompat.to_json" do - let(:jsonable) { Chef::CookbookVersion.new("tatft", '/tmp/blah') } + describe "when deprecation warnings are errors" do + + subject(:cbv) { Chef::CookbookVersion.new("version validation", '/tmp/blah') } + + describe "HTTP Resource behaviors", pending: "will be deprected when CookbookManifest API is stablized" do + + it "errors on #save_url" do + expect { cbv.save_url }.to raise_error(Chef::Exceptions::DeprecatedFeatureError) + end + + it "errors on #force_save_url" do + expect { cbv.force_save_url }.to raise_error(Chef::Exceptions::DeprecatedFeatureError) + end + + it "errors on #to_hash" do + expect { cbv.to_hash }.to raise_error(Chef::Exceptions::DeprecatedFeatureError) + end + + it "errors on #to_json" do + expect { cbv.to_json }.to raise_error(Chef::Exceptions::DeprecatedFeatureError) + end + + end + + it "errors on #status and #status=" do + expect { cbv.status = :wat }.to raise_error(Chef::Exceptions::DeprecatedFeatureError) + expect { cbv.status }.to raise_error(Chef::Exceptions::DeprecatedFeatureError) + end + end + describe "deprecated features" do + + subject(:cbv) { Chef::CookbookVersion.new("tatft", '/tmp/blah').tap { |c| c.version = "1.2.3" } } + + before do + Chef::Config[:treat_deprecation_warnings_as_errors] = false + end + + it "gives a save URL for the standard cookbook API" do + expect(cbv.save_url).to eq("cookbooks/tatft/1.2.3") + end + + it "gives a force save URL for the standard cookbook API" do + expect(cbv.force_save_url).to eq("cookbooks/tatft/1.2.3?force=true") + end + + it "is \"ready\"" do + # WTF is this? what are the valid states? and why aren't they set with encapsulating methods? + # [Dan 15-Jul-2010] + expect(cbv.status).to eq(:ready) + end + + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { Chef::CookbookVersion.new("tatft", '/tmp/blah') } + end + + end end |