diff options
| -rw-r--r-- | lib/spandx/spdx/catalogue.rb | 3 | ||||
| -rw-r--r-- | spec/unit/spdx/catalogue_spec.rb | 21 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/spandx/spdx/catalogue.rb b/lib/spandx/spdx/catalogue.rb index b9ea7ba..feb1d6b 100644 --- a/lib/spandx/spdx/catalogue.rb +++ b/lib/spandx/spdx/catalogue.rb @@ -37,7 +37,8 @@ module Spandx end def from_git - from_json(Spandx.git[:spdx].read('json/licenses.json')) + json = Spandx.git[:spdx].read('json/licenses.json') + json ? from_json(json) : latest end def default diff --git a/spec/unit/spdx/catalogue_spec.rb b/spec/unit/spdx/catalogue_spec.rb index efbe8ab..eeab29a 100644 --- a/spec/unit/spdx/catalogue_spec.rb +++ b/spec/unit/spdx/catalogue_spec.rb @@ -97,4 +97,25 @@ RSpec.describe Spandx::Spdx::Catalogue do it { expect(subject.count).to be > 400 } end + + describe '.default' do + subject { described_class.default } + + context 'when the SPDX catalogue has not been cloned' do + let(:gateway) { instance_double(Spandx::Spdx::Gateway, fetch: catalogue) } + let(:catalogue) { { licenses: [{ licenseId: 'example' }] } } + + before do + allow(Spandx::Spdx::Gateway).to receive(:new).and_return(gateway) + allow(Spandx.git[:spdx]).to receive(:read).and_return(nil) + end + + it { expect { subject }.not_to raise_error } + it { expect(subject.count).to be(1) } + end + + context 'when the SPDX catalogue has been cloned' do + it { expect(subject.count).to be > 400 } + end + end end |
