forked from fastlane/fastlane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_remote_branch_spec.rb
83 lines (65 loc) 路 2.83 KB
/
git_remote_branch_spec.rb
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
describe Fastlane do
describe Fastlane::FastFile do
directory = "fl_spec_default_remote_branch"
describe "Git Remote Branch Action" do
it "generates the correct git command for retrieving default branch from remote" do
result = Fastlane::FastFile.new.parse("lane :test do
git_remote_branch
end").runner.execute(:test)
expect(result).to eq("variable=$(git remote) && git remote show $variable | grep 'HEAD branch' | sed 's/.*: //'")
end
end
describe "Git Remote Branch Action with optional remote name" do
it "generates the correct git command for retrieving default branch using provided remote name" do
result = Fastlane::FastFile.new.parse("lane :test do
git_remote_branch(remote_name:'upstream')
end").runner.execute(:test)
expect(result).to eq("git remote show upstream | grep 'HEAD branch' | sed 's/.*: //'")
end
end
context "runs the command in a directory with no git repo" do
it "Confirms that no default remote is found" do
test_directory_path = Dir.mktmpdir(directory)
Dir.chdir(test_directory_path) do
expect(Fastlane::Actions).to receive(:sh)
.with("variable=$(git remote) && git remote show $variable | grep 'HEAD branch' | sed 's/.*: //'", log: false)
result = Fastlane::FastFile.new.parse("lane :test do
git_remote_branch
end").runner.execute(:test)
expect(result).to be_nil
end
end
end
context "runs the command in a directory with no remote git repo" do
it "Confirms that no default remote is found" do
test_directory_path = Dir.mktmpdir(directory)
Dir.chdir(test_directory_path) do
`git init`
File.write('test_file', <<-TESTFILE)
'Hello'
TESTFILE
`git add .`
`git commit --message "Test file"`
expect(Fastlane::Actions).to receive(:sh)
.with("variable=$(git remote) && git remote show $variable | grep 'HEAD branch' | sed 's/.*: //'", log: false)
result = Fastlane::FastFile.new.parse("lane :test do
git_remote_branch
end").runner.execute(:test)
expect(result).to be_nil
end
end
end
context "runs the command with a remote git repo" do
it "Confirms that a default remote is found" do
allow(Fastlane::Actions).to receive(:sh)
.with("variable=$(git remote) && git remote show $variable | grep 'HEAD branch' | sed 's/.*: //'", log: false)
.and_return("main")
allow(Fastlane::Actions).to receive(:git_branch).and_return(nil)
result = Fastlane::FastFile.new.parse("lane :test do
git_remote_branch
end").runner.execute(:test)
expect(result).to eq("main")
end
end
end
end