spec/unit/berkshelf/dependency_spec.rb in berkshelf-3.0.0.beta7 vs spec/unit/berkshelf/dependency_spec.rb in berkshelf-3.0.0.beta8

- old
+ new

@@ -55,36 +55,14 @@ it 'initializes a PathLocation for location' do expect(location).to be_a(Berkshelf::PathLocation) end it 'points to the specified path' do - expect(location.path).to eq(path) + expect(location.options[:path]).to eq(path) end end - context 'given an invalid option' do - it 'raises BerkshelfError with a friendly message' do - expect { - described_class.new(berksfile, cookbook_name, invalid_opt: 'thisisnotvalid') - }.to raise_error(Berkshelf::BerkshelfError, "Invalid options for dependency: 'invalid_opt'.") - end - - it 'raises BerkshelfError with a messaging containing all of the invalid options' do - expect { - described_class.new(berksfile, cookbook_name, invalid_one: 'one', invalid_two: 'two') - }.to raise_error(Berkshelf::BerkshelfError, "Invalid options for dependency: 'invalid_one', 'invalid_two'.") - end - end - - context 'given multiple location options' do - it 'raises with an Berkshelf::BerkshelfError' do - expect { - described_class.new(berksfile, cookbook_name, path: '/something', git: 'something') - }.to raise_error(Berkshelf::BerkshelfError) - end - end - context 'given a group option containing a single group' do let(:group) { :production } let(:source) { described_class.new(berksfile, cookbook_name, group: group) } it 'assigns the single group to the groups attribute' do @@ -108,62 +86,10 @@ expect(source.groups).to include(:default) end end end end - - describe "::add_valid_option" do - before do - @original = described_class.class_variable_get :@@valid_options - described_class.class_variable_set :@@valid_options, [] - end - - after do - described_class.class_variable_set :@@valid_options, @original - end - - it 'adds an option to the list of valid options' do - described_class.add_valid_option(:one) - - expect(described_class.valid_options).to have(1).item - expect(described_class.valid_options).to include(:one) - end - - it 'does not add duplicate options to the list of valid options' do - described_class.add_valid_option(:one) - described_class.add_valid_option(:one) - - expect(described_class.valid_options).to have(1).item - end - end - - describe "::add_location_key" do - before do - @original = described_class.class_variable_get :@@location_keys - described_class.class_variable_set :@@location_keys, {} - end - - after do - described_class.class_variable_set :@@location_keys, @original - end - - it 'adds a location key and the associated class to the list of valid locations' do - described_class.add_location_key(:git, described_class) - - expect(described_class.location_keys).to have(1).item - expect(described_class.location_keys).to include(:git) - expect(described_class.location_keys[:git]).to eq(described_class) - end - - it 'does not add duplicate location keys to the list of location keys' do - described_class.add_location_key(:git, described_class) - described_class.add_location_key(:git, described_class) - - expect(described_class.location_keys).to have(1).item - expect(described_class.location_keys).to include(:git) - end - end end subject { described_class.new(berksfile, cookbook_name) } describe '#add_group' do @@ -191,103 +117,17 @@ end describe "#cached_cookbook" describe "#download" - describe '#downloaded?' do + describe '#installed?' do it 'returns true if self.cached_cookbook is not nil' do subject.stub(:cached_cookbook) { double('cb') } - expect(subject.downloaded?).to be_true + expect(subject.installed?).to be_true end it 'returns false if self.cached_cookbook is nil' do subject.stub(:cached_cookbook) { nil } - expect(subject.downloaded?).to be_false - end - end - - describe '#to_hash' do - let(:hash) { subject.to_hash } - - it 'does not include default values' do - [:constraint, :locked_version, :site, :git, :ref, :path].each do |key| - expect(hash).to_not have_key(key) - end - end - - it 'includes the locked version' do - subject.stub(locked_version: double('cached', to_s: '1.2.3')) - - expect(hash).to have_key(:locked_version) - expect(hash[:locked_version]).to eq('1.2.3') - end - - it 'includes the git url and ref' do - location = double('git', uri: 'git://github.com/foo/bar.git', ref: 'abcd1234', rel: nil, download: nil) - location.stub(:kind_of?).and_return(false) - location.stub(:kind_of?).with(Berkshelf::GitLocation).and_return(true) - subject.stub(:location).and_return(location) - - expect(hash).to have_key(:git) - expect(hash[:git]).to eq('git://github.com/foo/bar.git') - expect(hash).to have_key(:ref) - expect(hash[:ref]).to eq('abcd1234') - end - - it 'includes the git url and rel' do - location = double('git', uri: 'git://github.com/foo/bar.git', ref: nil, rel: 'cookbooks/foo', download: nil) - location.stub(:kind_of?).and_return(false) - location.stub(:kind_of?).with(Berkshelf::GitLocation).and_return(true) - subject.stub(:location).and_return(location) - - expect(hash).to have_key(:git) - expect(hash[:git]).to eq('git://github.com/foo/bar.git') - expect(hash).to have_key(:rel) - expect(hash[:rel]).to eq('cookbooks/foo') - end - - it 'includes a relative path' do - location = double('path', relative_path: '../dev/foo') - location.stub(:kind_of?).and_return(false) - location.stub(:kind_of?).with(Berkshelf::PathLocation).and_return(true) - subject.stub(:location).and_return(location) - - expect(hash).to have_key(:path) - expect(hash[:path]).to eq('../dev/foo') - end - end - - describe "#scm_location?" do - let(:options) { Hash.new } - subject { described_class.new(berksfile, cookbook_name, options).scm_location? } - - context "when the location is a GitLocation" do - let(:options) { { git: "git@github.com:berkshelf/berkshelf.git" } } - it { should be_true } - end - - context "when the location is a GithubLocation" do - let(:options) { { github: "berkshelf/berkshelf" } } - it { should be_true } - end - - context "when the location is a PathLocation" do - let(:options) { { path: fixtures_path.join('cookbooks', 'example_cookbook') } } - it { should be_false } - end - end - - describe "#path_location?" do - let(:options) { Hash.new } - subject { described_class.new(berksfile, cookbook_name, options).path_location? } - - context "when the location is a PathLocation" do - let(:options) { { path: fixtures_path.join("cookbooks", "example_cookbook") } } - it { should be_true } - end - - context "when the location is not a PathLocation" do - let(:options) { { github: "berkshelf/berkshelf" } } - it { should be_false } + expect(subject.installed?).to be_false end end end