1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# frozen_string_literal: true
RSpec.describe Spandx::Core::IndexFile do
subject { described_class.new(data_file) }
describe '#search' do
let(:data_file) { Spandx::Core::DataFile.new(tmp_file.path) }
let(:tmp_file) { Tempfile.new }
before do
data_file.insert('activemodel', '6.0.2.2', ['Apache-2.0'])
data_file.insert('spandx', '0.1.0', ['MIT'])
data_file.insert('zlib', '1.1.0', ['0BSD'])
subject.update!
end
after do
tmp_file.unlink
end
specify do
result = subject.search { |row| 'activemodel-6.0.2.2' <=> "#{row[0]}-#{row[1]}" }
expect(result).to eql(['activemodel', '6.0.2.2', 'Apache-2.0'])
end
specify do
result = subject.search { |row| 'spandx-0.1.0' <=> "#{row[0]}-#{row[1]}" }
expect(result).to eql(['spandx', '0.1.0', 'MIT'])
end
specify do
result = subject.search { |row| 'zlib-1.1.0' <=> "#{row[0]}-#{row[1]}" }
expect(result).to eql(['zlib', '1.1.0', '0BSD'])
end
end
describe '#update!' do
let(:data_file) { Spandx::Core::DataFile.new(path) }
let(:path) { File.expand_path(File.join(Dir.home, '.local', 'share', 'spandx', 'cache', '.index', '00', 'nuget')) }
before do
subject.update!
end
it 'rebuilds the index correctly' do
data_file.each do |item|
expect(item).not_to be_nil
end
end
specify { expect(data_file.count).to be > 1_000 }
end
end
|