summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-03-17 17:39:11 -0600
committermo khan <mo.khan@gmail.com>2020-03-17 17:39:11 -0600
commit0309a0968564f269b7fb4e00a3c23ce0af3d4cdb (patch)
tree470518e98d847b45bdef2a3267f11a243a0f83e8
parent11fecb21ae815a75e4ac0d77af5e682cc2001c65 (diff)
Extract url parameter so that it can be generic enough to use in other package managers
-rw-r--r--lib/spandx/rubygems/offline_index.rb8
-rw-r--r--spec/integration/rubygems/offline_index_spec.rb9
2 files changed, 10 insertions, 7 deletions
diff --git a/lib/spandx/rubygems/offline_index.rb b/lib/spandx/rubygems/offline_index.rb
index 53df463..aeb97e6 100644
--- a/lib/spandx/rubygems/offline_index.rb
+++ b/lib/spandx/rubygems/offline_index.rb
@@ -3,11 +3,11 @@
module Spandx
module Rubygems
class OfflineIndex
- attr_reader :db
+ attr_reader :db, :package_manager
- def initialize(package_manager)
+ def initialize(package_manager, url: "https://github.com/mokhan/spandx-#{package_manager}.git")
@package_manager = package_manager
- @db = ::Spandx::Core::Database.new(url: "https://github.com/mokhan/spandx-#{package_manager}.git")
+ @db = ::Spandx::Core::Database.new(url: url)
end
def licenses_for(name:, version:)
@@ -35,7 +35,7 @@ module Spandx
end
def datafile_for(name)
- ".index/#{key_for(name)}/#{@package_manager}"
+ ".index/#{key_for(name)}/#{package_manager}"
end
def lines_in(io)
diff --git a/spec/integration/rubygems/offline_index_spec.rb b/spec/integration/rubygems/offline_index_spec.rb
index 459d3e1..3897979 100644
--- a/spec/integration/rubygems/offline_index_spec.rb
+++ b/spec/integration/rubygems/offline_index_spec.rb
@@ -1,15 +1,18 @@
# frozen_string_literal: true
RSpec.describe Spandx::Rubygems::OfflineIndex do
- subject { described_class.new(:rubygems) }
+ subject { described_class.new(package_manager, url: url) }
+
+ let(:package_manager) { :rubygems }
+ let(:url) { "https://github.com/mokhan/spandx-#{package_manager}.git" }
describe '#licenses_for' do
(0x00..0xFF).map { |x| x.to_s(16).upcase.rjust(2, '0').downcase }.each do |hex|
context hex do
- let(:path) { subject.db.expand_path(".index/#{hex}/rubygems") }
+ let(:path) { subject.db.expand_path(".index/#{hex}/#{package_manager}") }
it 'is able to find all packages in the index' do
- CSV.readlines(path).shuffle.each do |row|
+ CSV.foreach(path) do |row|
results = subject.licenses_for(name: row[0], version: row[1])
expect(results).to match_array(row[2].split('-|-'))
end