diff options
| author | mo khan <mo.khan@gmail.com> | 2020-03-03 10:58:47 -0700 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-03-03 10:58:47 -0700 |
| commit | 28881febd40ecb5c0b771c307b9624689c4e0973 (patch) | |
| tree | 236e94055ae78f3d53c4052c8cbe4c96c4629aa7 /spec/integration/core | |
| parent | b10053c7c14c3312f79a6d476b676d0d647d66cb (diff) | |
Extract core namespace
Diffstat (limited to 'spec/integration/core')
| -rw-r--r-- | spec/integration/core/database_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/integration/core/database_spec.rb b/spec/integration/core/database_spec.rb new file mode 100644 index 0000000..71b52bc --- /dev/null +++ b/spec/integration/core/database_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +RSpec.describe Spandx::Core::Database do + subject { described_class.new(url: url) } + + let(:url) { 'https://github.com/spdx/license-list-data.git' } + let(:shell) { subject } + + before do + allow(shell).to receive(:system) + end + + describe '#url' do + it { expect(subject.url).to eql(url) } + end + + describe '#path' do + let(:expected_path) { File.expand_path(File.join(ENV['HOME'], '.local', 'share', 'spdx', 'license-list-data')) } + + it { expect(subject.path).to eql(expected_path) } + end + + describe 'update!' do + let(:expected_path) { File.expand_path(File.join(ENV['HOME'], '.local', 'share', 'spdx', 'license-list-data')) } + + context 'when the repository has not been cloned' do + before do + allow(File).to receive(:directory?).with(File.join(expected_path, '.git')).and_return(false) + + subject.update! + end + + specify { expect(shell).to have_received(:system).with('git', 'clone', '--quiet', url, expected_path) } + end + + context 'when the repository has already been cloned' do + before do + allow(File).to receive(:directory?).with(File.join(expected_path, '.git')).and_return(true) + allow(Dir).to receive(:chdir).with(expected_path).and_yield + + subject.update! + end + + it { expect(shell).to have_received(:system).with('git', 'pull', '--no-rebase', '--quiet', 'origin', 'master') } + end + end +end |
