summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-02-02 13:59:08 -0700
committermo khan <mo.khan@gmail.com>2020-02-02 13:59:08 -0700
commitfb1c12a79a15472e710bb019e61ed9c19194f62a (patch)
treeec251efb24067cbf94b5dfa768fb56a81a5c608b /spec
parentc8fd92b56b07090901d1c74862c19cfc1d2df166 (diff)
Separate nuget specific code out of generic index
Diffstat (limited to 'spec')
-rw-r--r--spec/spec_helper.rb5
-rw-r--r--spec/unit/gateways/nuget_spec.rb15
-rw-r--r--spec/unit/index_spec.rb33
3 files changed, 35 insertions, 18 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index dccb16f..76907d7 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -3,9 +3,12 @@
require 'bundler/setup'
require 'spandx'
require 'spandx/cli'
+
require 'rspec-benchmark'
-require 'webmock/rspec'
require 'securerandom'
+require 'tmpdir'
+require 'webmock/rspec'
+
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
RSpec.configure do |config|
diff --git a/spec/unit/gateways/nuget_spec.rb b/spec/unit/gateways/nuget_spec.rb
index 196b12f..fd0b38d 100644
--- a/spec/unit/gateways/nuget_spec.rb
+++ b/spec/unit/gateways/nuget_spec.rb
@@ -17,4 +17,19 @@ RSpec.describe Spandx::Gateways::Nuget do
pending 'when the package specifies the license using a file'
pending 'when the package specifies the license using a url'
end
+
+ xdescribe '#update_index' do
+ let(:package_key) { Digest::SHA1.hexdigest('api.nuget.org/SpecFlow.Contrib.Variants/1.1.2') }
+ let(:package_data_dir) { File.join(directory, package_key.scan(/../).join('/')) }
+ let(:package_data_file) { File.join(package_data_dir, 'data') }
+ let(:index) { instance_double(Spandx::Index, indexed?: false, write: nil) }
+
+ before do
+ VCR.use_cassette('nuget-catalogue') do
+ subject.update_index(index, limit: 10)
+ end
+ end
+
+ specify { expect(index).to have_received(:write).with(['api.nuget.org', 'SpecFlow.Contrib.Variants', '1.1.2'], 'MIT') }
+ end
end
diff --git a/spec/unit/index_spec.rb b/spec/unit/index_spec.rb
index fda450e..751dadb 100644
--- a/spec/unit/index_spec.rb
+++ b/spec/unit/index_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require 'tmpdir'
-
RSpec.describe Spandx::Index do
subject { described_class.new(directory: directory) }
@@ -11,24 +9,25 @@ RSpec.describe Spandx::Index do
FileUtils.rm_r(directory, force: true, secure: true)
end
- describe '#update!' do
- let(:nuget) { Spandx::Gateways::Nuget.new(catalogue: catalogue) }
- let(:catalogue) { Spandx::Catalogue.from_file(fixture_file('spdx/json/licenses.json')) }
+ describe "#read" do
+ let(:key) { ['x', 'y', 'z'] }
+ let(:data) { SecureRandom.uuid }
- context 'when building the nuget index' do
- let(:package_key) { Digest::SHA1.hexdigest('api.nuget.org/SpecFlow.Contrib.Variants/1.1.2') }
- let(:package_data_dir) { File.join(directory, package_key.scan(/../).join('/')) }
- let(:package_data_file) { File.join(package_data_dir, 'data') }
+ before do
+ subject.write(key, data)
+ end
- before do
- VCR.use_cassette('nuget-catalogue') do
- subject.update!(nuget, limit: 10)
- end
- end
+ specify { expect(subject.read(key)).to eql(data) }
+ end
- specify { expect(Dir).to exist(package_data_dir) }
- specify { expect(File).to exist(package_data_file) }
- specify { expect(IO.read(package_data_file)).to eql('MIT') }
+ describe "#indexed?" do
+ let(:key) { ['x', 'y', 'z'] }
+ let(:data) { SecureRandom.uuid }
+
+ before do
+ subject.write(key, data)
end
+
+ specify { expect(subject).to be_indexed(key) }
end
end