Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scotje committed May 8, 2018
1 parent 0e660d2 commit cc7f19a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions spec/unit/pdk/module/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
expect(described_class.from_file(metadata_json_path).data).to include('name' => 'foo-bar', 'version' => '0.1.0')
end

it 'raises an ArgumentError if passed nil' do
expect { described_class.from_file(nil) }.to raise_error(ArgumentError, %r{no path to file}i)
end

it 'raises an ArgumentError if the file does not exist' do
allow(File).to receive(:file?).with(metadata_json_path).and_return(false)
expect { described_class.from_file(metadata_json_path) }.to raise_error(ArgumentError, %r{'#{metadata_json_path}'.*not exist})
Expand Down
28 changes: 20 additions & 8 deletions spec/unit/pdk/util/puppet_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,11 @@ def result(pe_version)
let(:metadata) { PDK::Module::Metadata.new }

context 'with default metadata' do
after(:each) do
described_class.from_module_metadata(metadata)
end

it 'searches for a Puppet gem >= 4.7.0 < 6.0.0' do
requirement = Gem::Requirement.create(['>= 4.7.0', '< 6.0.0'])
expect(described_class.instance).to receive(:find_gem).with(requirement)

described_class.from_module_metadata(metadata)
end
end

Expand All @@ -400,12 +398,10 @@ def result(pe_version)
metadata.data['requirements'] = [{ 'name' => 'puppet', 'version_requirement' => '4.10.10' }]
end

after(:each) do
described_class.from_module_metadata(metadata)
end

it 'searches for a Puppet gem matching the exact version' do
expect(described_class.instance).to receive(:find_gem).with(Gem::Requirement.create('4.10.10'))

described_class.from_module_metadata(metadata)
end
end

Expand All @@ -420,5 +416,21 @@ def result(pe_version)
}.to raise_error(ArgumentError)
end
end

context 'when module has no metadata.json' do
before(:each) do
allow(PDK::Util).to receive(:find_upwards).with('metadata.json').and_return(nil)
end

it 'logs a warning' do
expect(logger).to receive(:warn).with(%r{no metadata\.json present}i)

described_class.from_module_metadata
end

it 'returns nil' do
expect(described_class.from_module_metadata).to be_nil
end
end
end
end

0 comments on commit cc7f19a

Please sign in to comment.