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/cookbook_loader_spec.rb | |
parent | b92c309b0f1aa0837f76ab89d6c81c36076ceca9 (diff) | |
download | chef-5fed7a65a2f024d964ecf2de1bcf2911cf8a600c.tar.gz |
Update to RSpec 3.
Diffstat (limited to 'spec/unit/cookbook_loader_spec.rb')
-rw-r--r-- | spec/unit/cookbook_loader_spec.rb | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb index deaf393d7a..51532778e4 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/spec/unit/cookbook_loader_spec.rb @@ -20,7 +20,7 @@ require 'spec_helper' describe Chef::CookbookLoader do before do - Chef::Platform.stub(:windows?) {false} + allow(Chef::Platform).to receive(:windows?) {false} end let(:repo_paths) do [ @@ -40,7 +40,7 @@ describe Chef::CookbookLoader do cookbook_paths.delete_if { |path| File.basename(path) == "chefignore" } cookbook_paths.each do |cookbook_path| - Chef::Cookbook::CookbookVersionLoader.should_receive(:new). + expect(Chef::Cookbook::CookbookVersionLoader).to receive(:new). with(cookbook_path, anything). once. and_call_original @@ -56,19 +56,19 @@ describe Chef::CookbookLoader do describe "[]" do it "should return cookbook objects with []" do - cookbook_loader[:openldap].should be_a_kind_of(Chef::CookbookVersion) + expect(cookbook_loader[:openldap]).to be_a_kind_of(Chef::CookbookVersion) end it "should raise an exception if it cannot find a cookbook with []" do - lambda { cookbook_loader[:monkeypoop] }.should raise_error(Chef::Exceptions::CookbookNotFoundInRepo) + expect { cookbook_loader[:monkeypoop] }.to raise_error(Chef::Exceptions::CookbookNotFoundInRepo) end it "should allow you to look up available cookbooks with [] and a symbol" do - cookbook_loader[:openldap].name.should eql(:openldap) + expect(cookbook_loader[:openldap].name).to eql(:openldap) end it "should allow you to look up available cookbooks with [] and a string" do - cookbook_loader["openldap"].name.should eql(:openldap) + expect(cookbook_loader["openldap"].name).to eql(:openldap) end end @@ -78,8 +78,8 @@ describe Chef::CookbookLoader do cookbook_loader.each do |cookbook_name, cookbook| seen[cookbook_name] = true end - seen.should have_key("openldap") - seen.should have_key("apache2") + expect(seen).to have_key("openldap") + expect(seen).to have_key("apache2") end it "should iterate in alphabetical order" do @@ -87,86 +87,86 @@ describe Chef::CookbookLoader do cookbook_loader.each do |cookbook_name, cookbook| seen << cookbook_name end - seen[0].should == "angrybash" - seen[1].should == "apache2" - seen[2].should == "borken" - seen[3].should == "ignorken" - seen[4].should == "java" - seen[5].should == "name-mismatch" - seen[6].should == "openldap" + expect(seen[0]).to eq("angrybash") + expect(seen[1]).to eq("apache2") + expect(seen[2]).to eq("borken") + expect(seen[3]).to eq("ignorken") + expect(seen[4]).to eq("java") + expect(seen[5]).to eq("name-mismatch") + expect(seen[6]).to eq("openldap") end end describe "referencing cookbook files" do it "should find all the cookbooks in the cookbook path" do cookbook_loader.load_cookbooks - cookbook_loader.should have_key(:openldap) - cookbook_loader.should have_key(:apache2) + expect(cookbook_loader).to have_key(:openldap) + expect(cookbook_loader).to have_key(:apache2) end it "should allow you to override an attribute file via cookbook_path" do - cookbook_loader[:openldap].attribute_filenames.detect { |f| + expect(cookbook_loader[:openldap].attribute_filenames.detect { |f| f =~ /cookbooks\/openldap\/attributes\/default.rb/ - }.should_not eql(nil) - cookbook_loader[:openldap].attribute_filenames.detect { |f| + }).not_to eql(nil) + expect(cookbook_loader[:openldap].attribute_filenames.detect { |f| f =~ /kitchen\/openldap\/attributes\/default.rb/ - }.should eql(nil) + }).to eql(nil) end it "should load different attribute files from deeper paths" do - cookbook_loader[:openldap].attribute_filenames.detect { |f| + expect(cookbook_loader[:openldap].attribute_filenames.detect { |f| f =~ /kitchen\/openldap\/attributes\/robinson.rb/ - }.should_not eql(nil) + }).not_to eql(nil) end it "should allow you to override a definition file via cookbook_path" do - cookbook_loader[:openldap].definition_filenames.detect { |f| + expect(cookbook_loader[:openldap].definition_filenames.detect { |f| f =~ /cookbooks\/openldap\/definitions\/client.rb/ - }.should_not eql(nil) - cookbook_loader[:openldap].definition_filenames.detect { |f| + }).not_to eql(nil) + expect(cookbook_loader[:openldap].definition_filenames.detect { |f| f =~ /kitchen\/openldap\/definitions\/client.rb/ - }.should eql(nil) + }).to eql(nil) end it "should load definition files from deeper paths" do - cookbook_loader[:openldap].definition_filenames.detect { |f| + expect(cookbook_loader[:openldap].definition_filenames.detect { |f| f =~ /kitchen\/openldap\/definitions\/drewbarrymore.rb/ - }.should_not eql(nil) + }).not_to eql(nil) end it "should allow you to override a recipe file via cookbook_path" do - cookbook_loader[:openldap].recipe_filenames.detect { |f| + expect(cookbook_loader[:openldap].recipe_filenames.detect { |f| f =~ /cookbooks\/openldap\/recipes\/gigantor.rb/ - }.should_not eql(nil) - cookbook_loader[:openldap].recipe_filenames.detect { |f| + }).not_to eql(nil) + expect(cookbook_loader[:openldap].recipe_filenames.detect { |f| f =~ /kitchen\/openldap\/recipes\/gigantor.rb/ - }.should eql(nil) + }).to eql(nil) end it "should load recipe files from deeper paths" do - cookbook_loader[:openldap].recipe_filenames.detect { |f| + expect(cookbook_loader[:openldap].recipe_filenames.detect { |f| f =~ /kitchen\/openldap\/recipes\/woot.rb/ - }.should_not eql(nil) + }).not_to eql(nil) end it "should allow you to have an 'ignore' file, which skips loading files in later cookbooks" do - cookbook_loader[:openldap].recipe_filenames.detect { |f| + expect(cookbook_loader[:openldap].recipe_filenames.detect { |f| f =~ /kitchen\/openldap\/recipes\/ignoreme.rb/ - }.should eql(nil) + }).to eql(nil) end it "should find files that start with a ." do - cookbook_loader[:openldap].file_filenames.detect { |f| + expect(cookbook_loader[:openldap].file_filenames.detect { |f| f =~ /\.dotfile$/ - }.should =~ /\.dotfile$/ - cookbook_loader[:openldap].file_filenames.detect { |f| + }).to match(/\.dotfile$/) + expect(cookbook_loader[:openldap].file_filenames.detect { |f| f =~ /\.ssh\/id_rsa$/ - }.should =~ /\.ssh\/id_rsa$/ + }).to match(/\.ssh\/id_rsa$/) end it "should load the metadata for the cookbook" do - cookbook_loader.metadata[:openldap].name.to_s.should == "openldap" - cookbook_loader.metadata[:openldap].should be_a_kind_of(Chef::Cookbook::Metadata) + expect(cookbook_loader.metadata[:openldap].name.to_s).to eq("openldap") + expect(cookbook_loader.metadata[:openldap]).to be_a_kind_of(Chef::Cookbook::Metadata) end end # referencing cookbook files @@ -199,27 +199,27 @@ describe Chef::CookbookLoader do cookbook_loader.each do |cookbook_name, cookbook| seen[cookbook_name] = true end - seen.should have_key("openldap") + expect(seen).to have_key("openldap") end it "should not duplicate keys when serialized to JSON" do # Chef JSON serialization will generate duplicate keys if given # a Hash containing matching string and symbol keys. See CHEF-4571. aa = cookbook_loader["openldap"] - aa.to_hash["metadata"].recipes.keys.should_not include(:openldap) - aa.to_hash["metadata"].recipes.keys.should include("openldap") + expect(aa.to_hash["metadata"].recipes.keys).not_to include(:openldap) + expect(aa.to_hash["metadata"].recipes.keys).to include("openldap") expected_desc = "Main Open LDAP configuration" - aa.to_hash["metadata"].recipes["openldap"].should == expected_desc + expect(aa.to_hash["metadata"].recipes["openldap"]).to eq(expected_desc) raw = Chef::JSONCompat.to_json(aa.to_hash["metadata"].recipes) search_str = "\"openldap\":\"" key_idx = raw.index(search_str) - key_idx.should be > 0 + expect(key_idx).to be > 0 dup_idx = raw[(key_idx + 1)..-1].index(search_str) - dup_idx.should be_nil + expect(dup_idx).to be_nil end it "should not load the cookbook again when accessed" do - cookbook_loader.should_not_receive('load_cookbook') + expect(cookbook_loader).not_to receive('load_cookbook') cookbook_loader["openldap"] end @@ -228,11 +228,11 @@ describe Chef::CookbookLoader do cookbook_loader.each do |cookbook_name, cookbook| seen[cookbook_name] = true end - seen.should_not have_key("apache2") + expect(seen).not_to have_key("apache2") end it "should load another cookbook lazily with []" do - cookbook_loader["apache2"].should be_a_kind_of(Chef::CookbookVersion) + expect(cookbook_loader["apache2"]).to be_a_kind_of(Chef::CookbookVersion) end context "when an unrelated cookbook has invalid metadata" do @@ -265,8 +265,8 @@ describe Chef::CookbookLoader do cookbook_loader.each do |cookbook_name, cookbook| seen[cookbook_name] = true end - seen.should have_key("openldap") - seen.should have_key("apache2") + expect(seen).to have_key("openldap") + expect(seen).to have_key("apache2") end end end # loading only one cookbook @@ -279,8 +279,8 @@ describe Chef::CookbookLoader do it "loads the correct cookbook" do cookbook_version = cookbook_loader["name-mismatch"] - cookbook_version.should be_a_kind_of(Chef::CookbookVersion) - cookbook_version.name.should == :"name-mismatch" + expect(cookbook_version).to be_a_kind_of(Chef::CookbookVersion) + expect(cookbook_version.name).to eq(:"name-mismatch") end end |