|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe LibrarySource do |
| 4 | + subject { described_class.new uri } |
| 5 | + |
| 6 | + let(:uri) { nil } |
| 7 | + |
| 8 | + after(:all) { described_class.new.cleanup } |
| 9 | + |
| 10 | + describe '#uri' do |
| 11 | + context 'when it starts with github:' do |
| 12 | + let(:uri) { 'github:user/repo//the-path@the-ref' } |
| 13 | + |
| 14 | + it 'is transformed to git over https' do |
| 15 | + expect(subject.uri).to eq 'git:https://github.com/user/repo.git//the-path@the-ref' |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + context 'when it starts with github-ssh:' do |
| 20 | + let(:uri) { 'github-ssh:user/repo//the-path@the-ref' } |
| 21 | + |
| 22 | + it 'is transformed to git over ssh' do |
| 23 | + expect(subject.uri).to eq 'git:git@github.com:user/repo.git//the-path@the-ref' |
| 24 | + end |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + describe '#git?' do |
| 29 | + it 'returns false' do |
| 30 | + expect(subject).not_to be_git |
| 31 | + end |
| 32 | + |
| 33 | + context 'when the uri starts with git:' do |
| 34 | + let(:uri) { 'git:/repo' } |
| 35 | + |
| 36 | + it 'returns true' do |
| 37 | + expect(subject).to be_git |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + context 'when the uri starts with github:' do |
| 42 | + let(:uri) { 'github:/repo' } |
| 43 | + |
| 44 | + it 'returns true' do |
| 45 | + expect(subject).to be_git |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + context 'when the uri starts with github-ssh:' do |
| 50 | + let(:uri) { 'github-ssh:/repo' } |
| 51 | + |
| 52 | + it 'returns true' do |
| 53 | + expect(subject).to be_git |
| 54 | + end |
| 55 | + end |
| 56 | + end |
| 57 | + |
4 | 58 | describe '#config' do |
5 | 59 | it 'returns the contents of the libraries.yml file' do |
6 | 60 | expect(subject.config).to be_a Hash |
|
19 | 73 | end |
20 | 74 | end |
21 | 75 |
|
| 76 | + describe '#config_path' do |
| 77 | + it 'returns the path to libraries.yml' do |
| 78 | + expect(subject.config_path).to eq "#{subject.uri}/libraries.yml" |
| 79 | + end |
| 80 | + |
| 81 | + context 'with a git source' do |
| 82 | + let(:uri) { 'github:dannyben/bashly//spec/fixtures/libraries@0058d77' } |
| 83 | + |
| 84 | + it 'clones the repo to a temp directory and returns its path' do |
| 85 | + expect(subject.config_path).to match %r{/tmp/bashly-libs-.*/spec/fixtures/libraries/libraries.yml} |
| 86 | + end |
| 87 | + end |
| 88 | + |
| 89 | + context 'with a directory that does not contain libraries.yml' do |
| 90 | + let(:uri) { 'spec' } |
| 91 | + |
| 92 | + it 'raises an error' do |
| 93 | + expect { subject.config_path }.to raise_error('Cannot find spec/libraries.yml') |
| 94 | + end |
| 95 | + end |
| 96 | + end |
| 97 | + |
22 | 98 | describe '#libraries' do |
23 | 99 | it 'returns a hash' do |
24 | 100 | expect(subject.libraries).to be_a Hash |
|
35 | 111 | expect(subject.libraries.values.map(&:class).uniq).to eq [Library] |
36 | 112 | end |
37 | 113 | end |
| 114 | + |
| 115 | + describe '#cleanup' do |
| 116 | + it 'remoces all /tmp/bashly-libs-* directories' do |
| 117 | + expect(FileUtils).to receive(:rm_rf).with("#{Dir.tmpdir}/bashly-libs-*") |
| 118 | + subject.cleanup |
| 119 | + end |
| 120 | + end |
38 | 121 | end |
0 commit comments