blob: 47a6a8b986caf85807a18307fb75ae3e5c416940 (
plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe RefMatcher do
subject(:ref_matcher) { described_class.new(ref_pattern) }
let(:ref_pattern) { 'v1.0' }
shared_examples 'matching_refs' do
context 'when there is no match' do
let(:ref_pattern) { 'unknown' }
it { is_expected.to match_array([]) }
end
context 'when ref pattern is a wildcard' do
let(:ref_pattern) { 'v*' }
it { is_expected.to match_array(refs) }
end
end
describe '#matching' do
subject { ref_matcher.matching(refs) }
context 'when refs are strings' do
let(:refs) { ['v1.0', 'v1.1'] }
it { is_expected.to match_array([ref_pattern]) }
it_behaves_like 'matching_refs'
end
context 'when refs are ref objects' do
let(:matching_ref) { double('tag', name: 'v1.0') }
let(:not_matching_ref) { double('tag', name: 'v1.1') }
let(:refs) { [matching_ref, not_matching_ref] }
it { is_expected.to match_array([matching_ref]) }
it_behaves_like 'matching_refs'
end
end
describe '#matches?' do
subject { ref_matcher.matches?(ref_name) }
let(:ref_name) { 'v1.0' }
it { is_expected.to be_truthy }
context 'when ref_name is empty' do
let(:ref_name) { '' }
it { is_expected.to be_falsey }
end
context 'when ref pattern matches wildcard' do
let(:ref_pattern) { 'v*' }
it { is_expected.to be_truthy }
end
context 'when ref pattern does not match wildcard' do
let(:ref_pattern) { 'v2.*' }
it { is_expected.to be_falsey }
end
end
describe '#wildcard?' do
subject { ref_matcher.wildcard? }
it { is_expected.to be_falsey }
context 'when pattern is a wildcard' do
let(:ref_pattern) { 'v*' }
it { is_expected.to be_truthy }
end
end
end
|