summaryrefslogtreecommitdiff
path: root/spec/integration/core
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-03-20 13:42:51 -0600
committermo khan <mo.khan@gmail.com>2020-03-20 13:42:51 -0600
commit83dcbdcd9859e8d1d352552442cc6d746cfd9f5f (patch)
tree685c15462b003709fac8bd6b964797aed0483e84 /spec/integration/core
parentd269d2543a5e5c43bb3a6ec2ede3eed3b4d7f0c8 (diff)
Extract shared examples to test each cache
Diffstat (limited to 'spec/integration/core')
-rw-r--r--spec/integration/core/cache_spec.rb36
1 files changed, 6 insertions, 30 deletions
diff --git a/spec/integration/core/cache_spec.rb b/spec/integration/core/cache_spec.rb
index 6c23f14..ec1a8b2 100644
--- a/spec/integration/core/cache_spec.rb
+++ b/spec/integration/core/cache_spec.rb
@@ -1,18 +1,15 @@
# frozen_string_literal: true
RSpec.describe Spandx::Core::Cache do
- subject { described_class.new(package_manager, url: url) }
+ RSpec.shared_examples 'each data file' do |package_manager, url|
+ describe "#licenses_for (#{package_manager})" do
+ subject { described_class.new(package_manager, url: url) }
- context 'rubygems' do
- 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}/#{package_manager}") }
- it 'is able to find all packages in the index' do
+ it "is able to find all packages in the #{package_manager} index" do
CSV.foreach(path) do |row|
results = subject.licenses_for(name: row[0], version: row[1])
expect(results).to match_array(row[2].split('-|-'))
@@ -27,27 +24,6 @@ RSpec.describe Spandx::Core::Cache do
end
end
- context 'nuget' do
- let(:package_manager) { :nuget }
- let(:url) { 'https://github.com/mokhan/spandx-index.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}/#{package_manager}") }
-
- it 'is able to find all packages in the index' do
- CSV.foreach(path) do |row|
- results = subject.licenses_for(name: row[0], version: row[1])
- expect(results).to match_array(row[2].split('-|-'))
- end
- end
- end
- end
-
- it 'returns an empty list of unknown packages' do
- expect(subject.licenses_for(name: 'x', version: 'x')).to be_empty
- end
- end
- end
+ include_examples 'each data file', 'rubygems', 'https://github.com/mokhan/spandx-rubygems.git'
+ include_examples 'each data file', 'nuget', 'https://github.com/mokhan/spandx-index.git'
end