git-contest 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/.travis.yml +21 -3
- data/README.md +5 -0
- data/Rakefile +8 -0
- data/appveyor.yml +21 -0
- data/bin/git-contest +4 -33
- data/bin/git-contest-config +4 -241
- data/bin/git-contest-finish +4 -151
- data/bin/git-contest-init +4 -65
- data/bin/git-contest-list +4 -64
- data/bin/git-contest-rebase +4 -64
- data/bin/git-contest-start +4 -57
- data/bin/git-contest-submit +4 -183
- data/git-contest.gemspec +2 -1
- data/lib/contest/driver/base.rb +7 -4
- data/lib/git/contest/command_line.rb +10 -0
- data/lib/git/contest/command_line/command.rb +117 -0
- data/lib/git/contest/command_line/main_command.rb +56 -0
- data/lib/git/contest/command_line/sub_commands.rb +35 -0
- data/lib/git/contest/command_line/sub_commands/config_command.rb +258 -0
- data/lib/git/contest/command_line/sub_commands/finish_command.rb +161 -0
- data/lib/git/contest/command_line/sub_commands/init_command.rb +79 -0
- data/lib/git/contest/command_line/sub_commands/list_command.rb +89 -0
- data/lib/git/contest/command_line/sub_commands/rebase_command.rb +87 -0
- data/lib/git/contest/command_line/sub_commands/start_command.rb +77 -0
- data/lib/git/contest/command_line/sub_commands/submit_command.rb +220 -0
- data/lib/git/contest/common.rb +6 -6
- data/lib/git/contest/git.rb +160 -156
- data/lib/git/contest/version.rb +1 -1
- data/spec/command/t004_git_contest_submit_spec.rb +254 -0
- data/spec/command/t005_git_contest_branching_spec.rb +90 -0
- data/spec/command/t007_git_contest_start_spec.rb +95 -0
- data/spec/command/t008_git_contest_finish_spec.rb +171 -0
- data/spec/command/t009_git_contest_init_spec.rb +85 -0
- data/spec/command/t012_git_contest_list_spec.rb +123 -0
- data/spec/command/t013_git_contest_config_spec.rb +186 -0
- data/spec/{lib/contest/driver → contest_driver}/t001_aizu_online_judge_spec.rb +1 -1
- data/spec/{lib/contest/driver → contest_driver}/t002_codeforces_spec.rb +1 -1
- data/spec/{lib/contest/driver → contest_driver}/t003_uva_online_judge_spec.rb +1 -1
- data/spec/{lib/contest/driver → contest_driver}/t010_kattis_spec.rb +1 -1
- data/spec/{lib/contest/driver → contest_driver}/t011_utils_spec.rb +0 -0
- data/spec/spec_helper.rb +18 -12
- data/spec/t006_config_spec.rb +37 -31
- metadata +57 -33
- data/spec/bin/t004_git_contest_submit_spec.rb +0 -223
- data/spec/bin/t005_git_contest_branching_spec.rb +0 -70
- data/spec/bin/t007_git_contest_start_spec.rb +0 -88
- data/spec/bin/t008_git_contest_finish_spec.rb +0 -162
- data/spec/bin/t009_git_contest_init_spec.rb +0 -55
- data/spec/bin/t012_git_contest_list_spec.rb +0 -99
- data/spec/bin/t013_git_contest_config_spec.rb +0 -149
- data/spec/spec_list.txt +0 -1
@@ -0,0 +1,171 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# Do not forget --no-edit option
|
4
|
+
|
5
|
+
describe "T008: git-contest-finish" do
|
6
|
+
|
7
|
+
def call_main(args)
|
8
|
+
cli = CommandLine::MainCommand.new(args)
|
9
|
+
cli.init
|
10
|
+
cli
|
11
|
+
end
|
12
|
+
|
13
|
+
context "A001: --keep" do
|
14
|
+
it "001: init -> start -> empty-commits -> finish" do
|
15
|
+
expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
|
16
|
+
expect { call_main(["start", "branch1"]).run }.to output(/.*/).to_stdout
|
17
|
+
Git.do "commit --allow-empty -m \"this is commit\""
|
18
|
+
expect { call_main(["finish", "--no-edit"]).run }.to output(/.*/).to_stdout
|
19
|
+
ret1 = Git.do "branch"
|
20
|
+
ret_log1 = Git.do "log --oneline master"
|
21
|
+
expect(ret1.split(/\s+/)).not_to include /branch1/
|
22
|
+
expect(ret_log1).to match /this is commit/
|
23
|
+
end
|
24
|
+
|
25
|
+
it "002: init -> start -> empty-commits -> finish --keep" do
|
26
|
+
expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
|
27
|
+
expect { call_main(["start", "branch1"]).run }.to output(/.*/).to_stdout
|
28
|
+
Git.do "commit --allow-empty -m \"this is commit\""
|
29
|
+
expect { call_main(["finish", "--no-edit", "--keep"]).run }.to output(/.*/).to_stdout
|
30
|
+
ret1 = Git.do "branch"
|
31
|
+
ret_log1 = Git.do "log --oneline master"
|
32
|
+
expect(ret1.split(/\s+/)).to include /branch1/
|
33
|
+
expect(ret_log1).to match /this is commit/
|
34
|
+
end
|
35
|
+
|
36
|
+
it "003: init -> start -> empty-commits -> finish -k" do
|
37
|
+
expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
|
38
|
+
expect { call_main(["start", "branch1"]).run }.to output(/.*/).to_stdout
|
39
|
+
Git.do "commit --allow-empty -m \"this is commit\""
|
40
|
+
expect { call_main(["finish", "--no-edit", "-k"]).run }.to output(/.*/).to_stdout
|
41
|
+
ret1 = Git.do "branch"
|
42
|
+
ret_log1 = Git.do "log --oneline master"
|
43
|
+
expect(ret1.split(/\s+/)).to include /branch1/
|
44
|
+
expect(ret_log1).to match /this is commit/
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "A002: --rebase" do
|
50
|
+
it "001: init -> start -> empty-commits -> finish --rebase" do
|
51
|
+
# create branches: branch1(normal) -> branch2(rebase) -> branch3(normal)
|
52
|
+
expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
|
53
|
+
expect { call_main(["start", "branch1"]).run }.to output(/.*/).to_stdout
|
54
|
+
3.times {|x|
|
55
|
+
name = "test-1.#{x}"
|
56
|
+
FileUtils.touch name
|
57
|
+
Git.do "add #{name}"
|
58
|
+
Git.do "commit -m \"Add #{name}\""
|
59
|
+
}
|
60
|
+
expect { call_main(["start", "branch2"]).run }.to output(/.*/).to_stdout
|
61
|
+
3.times {|x|
|
62
|
+
name = "test-2.#{x}"
|
63
|
+
FileUtils.touch name
|
64
|
+
Git.do "add #{name}"
|
65
|
+
Git.do "commit -m \"Add #{name}\""
|
66
|
+
}
|
67
|
+
expect { call_main(["start", "branch3"]).run }.to output(/.*/).to_stdout
|
68
|
+
3.times {|x|
|
69
|
+
name = "test-3.#{x}"
|
70
|
+
FileUtils.touch name
|
71
|
+
Git.do "add #{name}"
|
72
|
+
Git.do "commit -m \"Add #{name}\""
|
73
|
+
}
|
74
|
+
# finish branches
|
75
|
+
ret_branch_1 = Git.do "branch"
|
76
|
+
expect { call_main(["finish", "--no-edit", "branch1"]).run }.to output(/.*/).to_stdout
|
77
|
+
expect { call_main(["finish", "--no-edit", "--rebase", "branch2"]).run }.to output(/.*/).to_stdout
|
78
|
+
expect { call_main(["finish", "--no-edit", "branch3"]).run }.to output(/.*/).to_stdout
|
79
|
+
ret_branch_2 = Git.do "branch"
|
80
|
+
ret_log = Git.do "log --oneline"
|
81
|
+
expect(ret_branch_1.split(/\s+/)).to include /branch1/
|
82
|
+
expect(ret_branch_1.split(/\s+/)).to include /branch2/
|
83
|
+
expect(ret_branch_1.split(/\s+/)).to include /branch3/
|
84
|
+
expect(ret_branch_2.split(/\s+/)).not_to include /branch1/
|
85
|
+
expect(ret_branch_2.split(/\s+/)).not_to include /branch2/
|
86
|
+
expect(ret_branch_2.split(/\s+/)).not_to include /branch3/
|
87
|
+
expect(ret_log).to match /test-1/m
|
88
|
+
expect(ret_log).to match /test-2/m
|
89
|
+
expect(ret_log).to match /test-3/m
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
context "A003: --force-delete" do
|
95
|
+
# TODO: recheck
|
96
|
+
it "001: init -> start -> trigger merge error -> finish --force-delete" do
|
97
|
+
# make conflict
|
98
|
+
expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
|
99
|
+
FileUtils.touch "test.txt"
|
100
|
+
Git.do "add test.txt"
|
101
|
+
Git.do "commit -m \"Add test.txt\""
|
102
|
+
expect { call_main(["start", "branch1"]).run }.to output(/.*/).to_stdout
|
103
|
+
expect { call_main(["start", "branch2"]).run }.to output(/.*/).to_stdout
|
104
|
+
Git.do "checkout contest/branch1"
|
105
|
+
File.open "test.txt", "w" do |file|
|
106
|
+
file.write "test1"
|
107
|
+
end
|
108
|
+
# Git.do "add test.txt"
|
109
|
+
# Git.do "commit -m \"Edit test.txt @ branch1\""
|
110
|
+
Git.do "checkout contest/branch2"
|
111
|
+
File.open "test.txt", "w" do |file|
|
112
|
+
file.write "test2"
|
113
|
+
end
|
114
|
+
Git.do "add test.txt"
|
115
|
+
Git.do "commit -m \"Edit test.txt @ branch2\""
|
116
|
+
# finish
|
117
|
+
expect { call_main(["finish", "--no-edit", "branch1"]).run }.to output(/.*/).to_stdout
|
118
|
+
expect { call_main(["finish", "--no-edit", "--force-delete", "branch2"]).run }.to output(/.*/).to_stdout
|
119
|
+
ret_branch = Git.do "branch"
|
120
|
+
expect(ret_branch.split(/\s+/)).not_to include /contest\/branch1/
|
121
|
+
expect(ret_branch.split(/\s+/)).not_to include /contest\/branch2/
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "A004: --squash" do
|
126
|
+
it "001: init -> start -> empty-commits -> finish --squash" do
|
127
|
+
expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
|
128
|
+
expect { call_main(["start", "branch1"]).run }.to output(/.*/).to_stdout
|
129
|
+
3.times do |x|
|
130
|
+
filename = "test#{x}.txt"
|
131
|
+
FileUtils.touch filename
|
132
|
+
Git.do "add #{filename}"
|
133
|
+
Git.do "commit -m \"this is commit #{x}\""
|
134
|
+
end
|
135
|
+
expect { call_main(["finish", "--no-edit", "--squash", "branch1"]).run }.to output(/.*/).to_stdout
|
136
|
+
ret_log1 = Git.do "log --oneline"
|
137
|
+
ret_branch1 = Git.do "branch"
|
138
|
+
expect(ret_branch1.split(/\s+/)).not_to include /branch1/
|
139
|
+
expect(ret_log1).to match /this is commit/
|
140
|
+
expect(ret_log1).to match /Squashed commit/
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "A005: --fetch" do
|
145
|
+
before do
|
146
|
+
Dir.mkdir "src"
|
147
|
+
Dir.chdir "src"
|
148
|
+
expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
|
149
|
+
expect { call_main(["start", "branch1"]).run }.to output(/.*/).to_stdout
|
150
|
+
3.times {|x| Git.do "commit --allow-empty -m \"this is commit #{x}\"" }
|
151
|
+
Dir.chdir ".."
|
152
|
+
Git.do "clone --single-branch -b master src dest"
|
153
|
+
Dir.chdir "dest"
|
154
|
+
end
|
155
|
+
|
156
|
+
it "001: init -> start -> clone -> checkout@dest -> empty-commits@dest -> finish@dest" do
|
157
|
+
Git.do "checkout -b master origin/master"
|
158
|
+
expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
|
159
|
+
expect { call_main(["start", "--fetch", "branch1"]).run }.to output(/.*/).to_stdout
|
160
|
+
expect { call_main(["finish", "--no-edit", "--fetch", "branch1"]).run }.to output(/.*/).to_stdout
|
161
|
+
ret_branch2 = Git.do "branch"
|
162
|
+
Dir.chdir ".."
|
163
|
+
Dir.chdir "src"
|
164
|
+
ret_branch1 = Git.do "branch"
|
165
|
+
Git.do "checkout master"
|
166
|
+
expect(ret_branch1.split(/\s+/)).to include /branch1/
|
167
|
+
expect(ret_branch2.split(/\s+/)).to_not include /branch1/
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# Don't forget --defaults option
|
4
|
+
|
5
|
+
describe "T009: git-contest-init" do
|
6
|
+
|
7
|
+
def call_main(args)
|
8
|
+
cli = CommandLine::MainCommand.new(args)
|
9
|
+
cli.init
|
10
|
+
cli
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "--force option" do
|
14
|
+
|
15
|
+
context "$ git contest init" do
|
16
|
+
|
17
|
+
before do
|
18
|
+
expect { call_main(["init", "--defaults"]).run }.to output("").to_stdout
|
19
|
+
end
|
20
|
+
|
21
|
+
context "config --get" do
|
22
|
+
it { expect(Git.do "config --get git.contest.branch.master").to eq "master" }
|
23
|
+
|
24
|
+
context "$ git contest init" do
|
25
|
+
subject { lambda { call_main(["init", "--defaults"]).run } }
|
26
|
+
it { should output(/Already initialized/).to_stdout.and raise_error SystemExit }
|
27
|
+
it { should output(/init -f/).to_stdout.and raise_error SystemExit }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "$ git contest init -f" do
|
31
|
+
before do
|
32
|
+
expect { call_main(["init", "--defaults", "-f"]).run }.to output("").to_stdout
|
33
|
+
end
|
34
|
+
|
35
|
+
context "$ git contest init --force" do
|
36
|
+
before do
|
37
|
+
expect { call_main(["init", "--defaults", "--force"]).run }.to output("").to_stdout
|
38
|
+
end
|
39
|
+
context "config --get" do
|
40
|
+
it { expect(Git.do "config --get git.contest.branch.master").to eq "master" }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end # git contest init
|
48
|
+
|
49
|
+
context "$ git contest init -f" do
|
50
|
+
|
51
|
+
before do
|
52
|
+
expect { call_main(["init", "--defaults", "-f"]).run }.to output("").to_stdout
|
53
|
+
end
|
54
|
+
|
55
|
+
context "config --get" do
|
56
|
+
it { expect(Git.do "config --get git.contest.branch.master").to eq "master" }
|
57
|
+
|
58
|
+
context "$ git contest init" do
|
59
|
+
subject { lambda { call_main(["init", "--defaults"]).run } }
|
60
|
+
it { should output(/Already initialized/).to_stdout.and raise_error SystemExit }
|
61
|
+
it { should output(/init -f/).to_stdout.and raise_error SystemExit }
|
62
|
+
end
|
63
|
+
|
64
|
+
context "$ git contest init -f" do
|
65
|
+
before do
|
66
|
+
expect { call_main(["init", "--defaults", "-f"]).run }.to output("").to_stdout
|
67
|
+
end
|
68
|
+
|
69
|
+
context "$ git contest init --force" do
|
70
|
+
before do
|
71
|
+
expect { call_main(["init", "--defaults", "--force"]).run }.to output("").to_stdout
|
72
|
+
end
|
73
|
+
context "config --get" do
|
74
|
+
it { expect(Git.do "config --get git.contest.branch.master").to eq "master" }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end # git contest init -f
|
82
|
+
|
83
|
+
end # --force option
|
84
|
+
end # git-contest-init
|
85
|
+
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "T012: git-contest-list" do
|
4
|
+
|
5
|
+
def call_main(args)
|
6
|
+
cli = CommandLine::MainCommand.new(args)
|
7
|
+
cli.init
|
8
|
+
cli
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
ENV['GIT_CONTEST_CONFIG'] = "#{@temp_dir}/config.yml"
|
13
|
+
ENV['GIT_CONTEST_HOME'] = @temp_dir
|
14
|
+
end
|
15
|
+
|
16
|
+
context "git-contest-list sites" do
|
17
|
+
before do
|
18
|
+
# create config
|
19
|
+
File.open "#{@temp_dir}/config.yml", 'w' do |file|
|
20
|
+
file.write <<EOF
|
21
|
+
sites:
|
22
|
+
test_site1:
|
23
|
+
driver: test_driver1
|
24
|
+
user: test_user1
|
25
|
+
password: test_password1
|
26
|
+
test_site2:
|
27
|
+
driver: test_driver2
|
28
|
+
user: test_user2
|
29
|
+
password: test_password2
|
30
|
+
test_site3:
|
31
|
+
driver: test_driver3
|
32
|
+
user: test_user3
|
33
|
+
password: test_password3
|
34
|
+
EOF
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "git-contest list sites" do
|
39
|
+
subject { lambda { call_main(["list", "sites"]).run } }
|
40
|
+
describe "site" do
|
41
|
+
it { should output(/test_site1/).to_stdout }
|
42
|
+
it { should output(/test_site2/).to_stdout }
|
43
|
+
it { should output(/test_site3/).to_stdout }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "user" do
|
47
|
+
it { should output(/test_user1/).to_stdout }
|
48
|
+
it { should output(/test_user2/).to_stdout }
|
49
|
+
it { should output(/test_user3/).to_stdout }
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "driver" do
|
53
|
+
it { should output(/test_driver1/).to_stdout }
|
54
|
+
it { should output(/test_driver2/).to_stdout }
|
55
|
+
it { should output(/test_driver3/).to_stdout }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "password (hidden)" do
|
59
|
+
it { should_not output(/test_password1/).to_stdout }
|
60
|
+
it { should_not output(/test_password2/).to_stdout }
|
61
|
+
it { should_not output(/test_password3/).to_stdout }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context "git-contest-list drivers" do
|
68
|
+
before do
|
69
|
+
# prepare drivers
|
70
|
+
FileUtils.mkdir "#{@temp_dir}/plugins"
|
71
|
+
File.open "#{@temp_dir}/plugins/test01_driver.rb", "w" do |f|
|
72
|
+
f.write <<EOF
|
73
|
+
module Contest
|
74
|
+
module Driver
|
75
|
+
class Test01Driver < DriverBase
|
76
|
+
def get_site_name
|
77
|
+
"test01_site_name"
|
78
|
+
end
|
79
|
+
def get_desc
|
80
|
+
"test01_desc"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
EOF
|
86
|
+
end
|
87
|
+
File.open "#{@temp_dir}/plugins/test02_driver.rb", "w" do |f|
|
88
|
+
f.write <<EOF
|
89
|
+
module Contest
|
90
|
+
module Driver
|
91
|
+
class Test02Driver < DriverBase
|
92
|
+
def get_site_name
|
93
|
+
"test02_site_name"
|
94
|
+
end
|
95
|
+
def get_desc
|
96
|
+
"test02_desc"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
EOF
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "$ git contest list drivers" do
|
106
|
+
|
107
|
+
subject { lambda { call_main(["list", "drivers"]).run } }
|
108
|
+
|
109
|
+
context "class" do
|
110
|
+
it { should output(/Test01Driver/).to_stdout }
|
111
|
+
it { should output(/Test02Driver/).to_stdout }
|
112
|
+
end
|
113
|
+
|
114
|
+
context "desc" do
|
115
|
+
it { should output(/test01_desc/).to_stdout }
|
116
|
+
it { should output(/test02_desc/).to_stdout }
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe "T013: git-contest-config" do
|
5
|
+
|
6
|
+
let(:config_file) { File.join @temp_dir, "config.yml" }
|
7
|
+
|
8
|
+
def call_main(args, new_stdin = STDIN)
|
9
|
+
cli = CommandLine::MainCommand.new(args, new_stdin)
|
10
|
+
cli.init
|
11
|
+
cli
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
ENV['GIT_CONTEST_CONFIG'] = config_file
|
16
|
+
end
|
17
|
+
|
18
|
+
context "git contest config set" do
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
# create config file
|
22
|
+
File.open config_file, 'w' do |file|
|
23
|
+
file.write <<EOF
|
24
|
+
key1: value1
|
25
|
+
sites:
|
26
|
+
test_site1:
|
27
|
+
driver: test_driver1
|
28
|
+
user: test_user1
|
29
|
+
password: test_password1
|
30
|
+
EOF
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "git contest config set key value1" do
|
35
|
+
|
36
|
+
let(:fake_input) { ::StringIO.new("value2" + $/) }
|
37
|
+
|
38
|
+
before { expect { call_main(["config", "set", "key1"], fake_input).run }.to output(/input value/).to_stdout }
|
39
|
+
|
40
|
+
context "load config" do
|
41
|
+
let(:conf) { YAML.load_file config_file }
|
42
|
+
|
43
|
+
it { expect(conf["key1"]).to eq "value2" }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "git contest config set sites.test_site1.driver test_driver2" do
|
48
|
+
expect { call_main(["config", "set", "sites.test_site1.driver", "test_driver2"]).run }.to output(/.*/).to_stdout
|
49
|
+
|
50
|
+
ret1 = YAML.load_file(config_file)
|
51
|
+
expect(ret1["sites"]["test_site1"]["driver"]).to eq "test_driver2"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "git contest config get" do
|
56
|
+
before(:each) do
|
57
|
+
# create config file
|
58
|
+
File.open config_file, 'w' do |file|
|
59
|
+
file.write <<EOF
|
60
|
+
key1: value1
|
61
|
+
sites:
|
62
|
+
test_site1:
|
63
|
+
driver: test_driver1
|
64
|
+
user: test_user1
|
65
|
+
password: test_password1
|
66
|
+
EOF
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "git contest config get key1" do
|
71
|
+
expect { call_main(["config", "get", "key1"]).run }.to output(/value1/).to_stdout
|
72
|
+
end
|
73
|
+
|
74
|
+
it "git contest config get sites.test_site1.user" do
|
75
|
+
expect { call_main(["config", "get", "sites.test_site1.user"]).run }.to output(/test_user1/).to_stdout
|
76
|
+
end
|
77
|
+
|
78
|
+
context "config get sites.test_site1" do
|
79
|
+
subject { lambda { call_main(["config", "get", "sites.test_site1"]).run } }
|
80
|
+
it { should output(/driver/).to_stdout }
|
81
|
+
it { should output(/user/).to_stdout }
|
82
|
+
it { should output(/password/).to_stdout }
|
83
|
+
it { should_not output(/test_driver1/).to_stdout }
|
84
|
+
it { should_not output(/test_user1/).to_stdout }
|
85
|
+
it { should_not output(/test_password1/).to_stdout }
|
86
|
+
end
|
87
|
+
|
88
|
+
it "raise error: not found" do
|
89
|
+
expect { call_main(["config", "get", "foo.bar"]).run }.to output(/ERROR/).to_stderr.and raise_error SystemExit
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "git contest config site add" do
|
94
|
+
|
95
|
+
before(:each) do
|
96
|
+
# create config
|
97
|
+
File.open config_file, "w" do |file|
|
98
|
+
file.write <<EOF
|
99
|
+
sites:
|
100
|
+
test_site1:
|
101
|
+
driver: test_driver1
|
102
|
+
user: test_user1
|
103
|
+
password: test_password1
|
104
|
+
EOF
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "$ git contest config site add test_site2" do
|
109
|
+
|
110
|
+
let(:fake_input) do
|
111
|
+
::StringIO.new([
|
112
|
+
"test_driver2",
|
113
|
+
"test_user2",
|
114
|
+
"test_password2",
|
115
|
+
].join($/) + $/)
|
116
|
+
end
|
117
|
+
|
118
|
+
before { expect { call_main(["config", "site", "add", "test_site2"], fake_input).run }.to output(/.*/).to_stdout }
|
119
|
+
|
120
|
+
context "load config" do
|
121
|
+
let(:conf) { YAML.load_file config_file }
|
122
|
+
it { expect(conf["sites"]["test_site1"]["driver"]).to eq "test_driver1" }
|
123
|
+
it { expect(conf["sites"]["test_site1"]["user"]).to eq "test_user1" }
|
124
|
+
it { expect(conf["sites"]["test_site1"]["password"]).to eq "test_password1" }
|
125
|
+
it { expect(conf["sites"]["test_site2"]["driver"]).to eq "test_driver2" }
|
126
|
+
it { expect(conf["sites"]["test_site2"]["user"]).to eq "test_user2" }
|
127
|
+
it { expect(conf["sites"]["test_site2"]["password"]).to eq "test_password2" }
|
128
|
+
end
|
129
|
+
|
130
|
+
end # git contest config site add test_site2
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
context "git contest config site rm" do
|
135
|
+
before(:each) do
|
136
|
+
# create config
|
137
|
+
File.open config_file, "w" do |file|
|
138
|
+
file.write <<EOF
|
139
|
+
sites:
|
140
|
+
test_site1:
|
141
|
+
driver: test_driver1
|
142
|
+
user: test_user1
|
143
|
+
password: test_password1
|
144
|
+
test_site2:
|
145
|
+
driver: test_driver2
|
146
|
+
user: test_user2
|
147
|
+
password: test_password2
|
148
|
+
EOF
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "git contest config site rm test_site1 (input = yes)" do
|
153
|
+
|
154
|
+
let(:fake_input) { ::StringIO.new("yes" + $/) }
|
155
|
+
before { expect { call_main(["config", "site", "rm", "test_site1"], fake_input).run }.to output(/.*/).to_stdout }
|
156
|
+
|
157
|
+
context "load config" do
|
158
|
+
let(:conf) { YAML.load_file config_file }
|
159
|
+
it { expect(conf["sites"]["test_site1"]).to be_nil }
|
160
|
+
it { expect(conf["sites"]["test_site2"]["driver"]).to eq "test_driver2" }
|
161
|
+
it { expect(conf["sites"]["test_site2"]["user"]).to eq "test_user2" }
|
162
|
+
it { expect(conf["sites"]["test_site2"]["password"]).to eq "test_password2" }
|
163
|
+
end
|
164
|
+
|
165
|
+
end # git contest config site rm
|
166
|
+
|
167
|
+
context "git contest config site rm test_site1 (input no)" do
|
168
|
+
|
169
|
+
let(:fake_input) { ::StringIO.new("no" + $/) }
|
170
|
+
before { expect { call_main(["config", "site", "rm", "test_site1"], fake_input).run }.to output(/.*/).to_stdout }
|
171
|
+
|
172
|
+
context "load config" do
|
173
|
+
let(:conf) { YAML.load_file config_file }
|
174
|
+
it { expect(conf["sites"]["test_site1"]["driver"]).to eq "test_driver1" }
|
175
|
+
it { expect(conf["sites"]["test_site1"]["user"]).to eq "test_user1" }
|
176
|
+
it { expect(conf["sites"]["test_site1"]["password"]).to eq "test_password1" }
|
177
|
+
it { expect(conf["sites"]["test_site2"]["driver"]).to eq "test_driver2" }
|
178
|
+
it { expect(conf["sites"]["test_site2"]["user"]).to eq "test_user2" }
|
179
|
+
it { expect(conf["sites"]["test_site2"]["password"]).to eq "test_password2" }
|
180
|
+
end
|
181
|
+
|
182
|
+
end # git contest config site rm
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|