blob: dfc3601ffa9557af7a6a4ff54c21920fe8501c0a (
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# frozen_string_literal: true
require 'fast_spec_helper'
# NOTE: Under the context of fast_spec_helper, when we `require 'gitlab'`
# we do not load the Gitlab client, but our own Gitlab module.
# Keep this in mind and just stub anything which might touch it!
require_relative '../../../scripts/setup/find-jh-branch'
RSpec.describe FindJhBranch do
subject { described_class.new }
describe '#run' do
context 'when it is not a merge request' do
before do
expect(subject).to receive(:merge_request?).and_return(false)
end
it 'returns JH_DEFAULT_BRANCH' do
expect(subject.run).to eq(described_class::JH_DEFAULT_BRANCH)
end
end
context 'when it is a merge request' do
let(:branch_name) { 'branch-name' }
let(:jh_branch_name) { 'branch-name-jh' }
let(:default_branch) { 'main' }
let(:merge_request) { double(target_branch: target_branch) }
let(:target_branch) { default_branch }
before do
expect(subject).to receive(:merge_request?).and_return(true)
expect(subject)
.to receive(:branch_exist?)
.with(described_class::JH_PROJECT_PATH, jh_branch_name)
.and_return(jh_branch_exist)
allow(subject).to receive(:ref_name).and_return(branch_name)
allow(subject).to receive(:default_branch).and_return(default_branch)
allow(subject).to receive(:merge_request).and_return(merge_request)
end
context 'when there is a corresponding JH branch' do
let(:jh_branch_exist) { true }
it 'returns the corresponding JH branch name' do
expect(subject.run).to eq(jh_branch_name)
end
end
context 'when there is no corresponding JH branch' do
let(:jh_branch_exist) { false }
it 'returns the default JH branch' do
expect(subject.run).to eq(described_class::JH_DEFAULT_BRANCH)
end
context 'when it is targeting a default branch' do
let(:target_branch) { '14-6-stable-ee' }
let(:jh_stable_branch_name) { '14-6-stable-jh' }
before do
expect(subject)
.to receive(:branch_exist?)
.with(described_class::JH_PROJECT_PATH, jh_stable_branch_name)
.and_return(jh_stable_branch_exist)
end
context 'when there is a corresponding JH stable branch' do
let(:jh_stable_branch_exist) { true }
it 'returns the corresponding JH stable branch' do
expect(subject.run).to eq(jh_stable_branch_name)
end
end
context 'when there is no corresponding JH stable branch' do
let(:jh_stable_branch_exist) { false }
it "raises #{described_class::BranchNotFound}" do
expect { subject.run }.to raise_error(described_class::BranchNotFound)
end
end
end
context 'when it is not targeting the default branch' do
let(:target_branch) { default_branch.swapcase }
it 'returns the default JH branch' do
expect(subject.run).to eq(described_class::JH_DEFAULT_BRANCH)
end
end
end
end
end
end
|