Commit 5fa7f83

mo khan <mo@mokhan.ca>
2021-12-15 21:49:27
fix: fallback to latest version
1 parent b47f94f
Changed files (2)
lib
spandx
spec
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
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