spec/unit/berkshelf/location_spec.rb in berkshelf-0.4.0 vs spec/unit/berkshelf/location_spec.rb in berkshelf-0.5.0.rc1

- old
+ new

@@ -5,48 +5,65 @@ Class.new do include Location end end - describe "::location_key" do + describe "::set_location_key" do before(:each) do @original = CookbookSource.class_variable_get :@@location_keys CookbookSource.class_variable_set :@@location_keys, {} end after(:each) do CookbookSource.class_variable_set :@@location_keys, @original end it "adds the given location key with the includer's Class to CookbookSource.location_keys" do - subject.location_key(:reset) + subject.set_location_key(:reset) CookbookSource.location_keys.should have(1).item CookbookSource.location_keys.should include(:reset) CookbookSource.location_keys[:reset].should eql(subject) end end - describe "::valid_options" do + describe "::location_key" do before(:each) do + @original = CookbookSource.class_variable_get :@@location_keys + CookbookSource.class_variable_set :@@location_keys, {} + end + + after(:each) do + CookbookSource.class_variable_set :@@location_keys, @original + end + + it "returns the class' registered location key" do + subject.set_location_key(:reset) + + subject.location_key.should eql(:reset) + end + end + + describe "::set_valid_options" do + before(:each) do @original = CookbookSource.class_variable_get :@@valid_options CookbookSource.class_variable_set :@@valid_options, [] end after(:each) do CookbookSource.class_variable_set :@@valid_options, @original end it "adds the given symbol to the list of valid options on CookbookSource" do - subject.valid_options(:mundo) + subject.set_valid_options(:mundo) CookbookSource.valid_options.should have(1).item CookbookSource.valid_options.should include(:mundo) end it "adds parameters to the list of valid options on the CookbookSource" do - subject.valid_options(:riot, :arenanet) + subject.set_valid_options(:riot, :arenanet) CookbookSource.valid_options.should have(2).items CookbookSource.valid_options.should include(:riot) CookbookSource.valid_options.should include(:arenanet) end @@ -148,23 +165,43 @@ }.should raise_error(AbstractFunction) end end describe "#validate_cached" do - let(:cached) { double('cached-cb', version: "0.1.0") } + let(:cached) { double('cached-cb', cookbook_name: name, version: "0.1.0") } it "raises a ConstraintNotSatisfied error if the version constraint does not satisfy the cached version" do constraint.should_receive(:satisfies?).with(cached.version).and_return(false) lambda { subject.validate_cached(cached) }.should raise_error(ConstraintNotSatisfied) end - it "returns true if the version constraint satisfies the cached version" do + it "returns true if cached_cookbooks satisfies the version constraint" do constraint.should_receive(:satisfies?).with(cached.version).and_return(true) subject.validate_cached(cached).should be_true + end + + context "when the cached_cookbooks satisfies the version constraint" do + it "returns true if the name of the cached_cookbook matches the name of the location" do + constraint.should_receive(:satisfies?).with(cached.version).and_return(true) + cached.stub(:name) { name } + + subject.validate_cached(cached).should be_true + end + + it "raises an AmbiguousCookbookName error if the cached_cookbook's name does not match the location's" do + pending "Implement when Opscode makes the 'name' a required attribute in Cookbook metadata" + + constraint.should_receive(:satisfies?).with(cached.version).and_return(true) + cached.stub(:cookbook_name) { "artifact" } + + lambda { + subject.validate_cached(cached) + }.should raise_error(AmbiguousCookbookName) + end end end end end