pgit 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +26 -0
- data/LICENSE +22 -0
- data/README.markdown +32 -0
- data/Rakefile +24 -0
- data/bin/pgit +97 -0
- data/lib/pgit.rb +14 -0
- data/lib/pgit/configuration.rb +77 -0
- data/lib/pgit/current_branch.rb +23 -0
- data/lib/pgit/current_project.rb +62 -0
- data/lib/pgit/installer.rb +32 -0
- data/lib/pgit/name_parser.rb +57 -0
- data/lib/pgit/story.rb +48 -0
- data/lib/pgit/story_branch.rb +30 -0
- data/lib/pgit/story_branch/application.rb +19 -0
- data/lib/pgit/version.rb +3 -0
- data/lib/pgit_configuration.rb +57 -0
- data/man/pgit.1 +18 -0
- data/man/pgit.1.html +96 -0
- data/man/pgit.1.ronn +15 -0
- data/pgit.gemspec +21 -0
- data/pgit.rdoc +5 -0
- data/spec/pgit/application_spec.rb +16 -0
- data/spec/pgit/configuration_spec.rb +158 -0
- data/spec/pgit/current_branch_spec.rb +72 -0
- data/spec/pgit/current_project_spec.rb +80 -0
- data/spec/pgit/installer_spec.rb +158 -0
- data/spec/pgit/pgit_spec.rb +33 -0
- data/spec/pgit/story_branch/application_spec.rb +48 -0
- data/spec/pgit/story_branch/name_parser_spec.rb +42 -0
- data/spec/pgit/story_branch_spec.rb +90 -0
- data/spec/pgit/story_spec.rb +54 -0
- metadata +110 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'pgit'
|
2
|
+
|
3
|
+
describe 'PGit::CurrentBranch' do
|
4
|
+
describe '#name' do
|
5
|
+
it 'should return the current branch' do
|
6
|
+
git_branch_command = 'git branch'
|
7
|
+
fake_current_branch = 'master'
|
8
|
+
fake_branches = <<-FAKE_BRANCHES
|
9
|
+
some-branch
|
10
|
+
* master
|
11
|
+
some-other-branch
|
12
|
+
FAKE_BRANCHES
|
13
|
+
|
14
|
+
allow(PGit::CurrentBranch).to receive(:`).with(git_branch_command).and_return(fake_branches)
|
15
|
+
current_branch_name = PGit::CurrentBranch.new.name
|
16
|
+
|
17
|
+
expect(current_branch_name).to eq fake_current_branch
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#story_id' do
|
22
|
+
describe 'current branch has no story id' do
|
23
|
+
it 'should return nil' do
|
24
|
+
git_branch_command = 'git branch'
|
25
|
+
fake_current_branch = 'master'
|
26
|
+
fake_branches = <<-FAKE_BRANCHES
|
27
|
+
some-branch
|
28
|
+
* master
|
29
|
+
some-other-branch
|
30
|
+
FAKE_BRANCHES
|
31
|
+
|
32
|
+
allow_any_instance_of(PGit::CurrentBranch).to receive(:`).with(git_branch_command).and_return(fake_branches)
|
33
|
+
current_branch_story_id = PGit::CurrentBranch.new.story_id
|
34
|
+
|
35
|
+
expect(current_branch_story_id).to be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'current branch has story id' do
|
40
|
+
it 'should return the story id' do
|
41
|
+
git_branch_command = 'git branch'
|
42
|
+
fake_current_branch = 'master'
|
43
|
+
fake_branches = <<-FAKE_BRANCHES
|
44
|
+
some-branch
|
45
|
+
* some-feature-branch-123456
|
46
|
+
some-other-branch
|
47
|
+
FAKE_BRANCHES
|
48
|
+
|
49
|
+
allow_any_instance_of(PGit::CurrentBranch).to receive(:`).with(git_branch_command).and_return(fake_branches)
|
50
|
+
current_branch_story_id = PGit::CurrentBranch.new.story_id
|
51
|
+
|
52
|
+
expect(current_branch_story_id).to eq '123456'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'when there is error or fatal in the result' do
|
58
|
+
it 'should raise the error' do
|
59
|
+
git_branch_command = 'git branch'
|
60
|
+
fake_current_branch = 'master'
|
61
|
+
fake_branches = <<-FAKE_BRANCHES
|
62
|
+
fatal: Not a git repository
|
63
|
+
(or any of the parent directories): .git
|
64
|
+
FAKE_BRANCHES
|
65
|
+
|
66
|
+
|
67
|
+
allow_any_instance_of(PGit::CurrentBranch).to receive(:`).with(git_branch_command).and_return(fake_branches)
|
68
|
+
|
69
|
+
expect{PGit::CurrentBranch.new}.to raise_error(fake_branches)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'pgit'
|
2
|
+
# .edderic-dotfiles/config.yml
|
3
|
+
# projects
|
4
|
+
# - path: ~/Therapy-Exercises-Online
|
5
|
+
# id: 12345
|
6
|
+
# api_token: asoeuhot
|
7
|
+
#
|
8
|
+
def successful_setup
|
9
|
+
fake_project_1 = { "path" => "/Therapy-Exercises-Online/some_other_project",
|
10
|
+
"id" => 12345,
|
11
|
+
"api_token" => "astoeuh" }
|
12
|
+
fake_project_2 = { "path" => "~/Therapy-Exercises-Online",
|
13
|
+
"id" => 19191,
|
14
|
+
"api_token" => "astoeuh" }
|
15
|
+
fake_project_list = [ fake_project_1, fake_project_2 ]
|
16
|
+
fake_yaml = { "projects" => fake_project_list }
|
17
|
+
fake_pwd = "/Therapy-Exercises-Online/some_other_project/some_subdirectory"
|
18
|
+
allow(Dir).to receive(:pwd).and_return(fake_pwd)
|
19
|
+
|
20
|
+
fake_configuration = double('configuration', to_yaml: fake_yaml)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'PGit::CurrentProject' do
|
24
|
+
describe '#new(config_yaml)' do
|
25
|
+
describe 'none of the projects listed matches the working directory' do
|
26
|
+
it 'should throw an error' do
|
27
|
+
error_message = "None of the project paths matches the working directory"
|
28
|
+
fake_project_1 = { "path" => "~/some-non-matching-path",
|
29
|
+
"id" => 12345,
|
30
|
+
"api_token" => "astoeuh" }
|
31
|
+
fake_project_2 = { "path" => "~/some-other-non-matching-path",
|
32
|
+
"id" => 19191,
|
33
|
+
"api_token" => "astoeuh" }
|
34
|
+
fake_project_list = [ fake_project_1, fake_project_2 ]
|
35
|
+
fake_yaml = { "projects" => fake_project_list }
|
36
|
+
fake_pwd = "/Therapy-Exercises-Online/some_other_project/some_subdirectory"
|
37
|
+
fake_configuration = double('configuration', to_yaml: fake_yaml)
|
38
|
+
allow(Dir).to receive(:pwd).and_return(fake_pwd)
|
39
|
+
|
40
|
+
expect{ PGit::CurrentProject.new(fake_configuration.to_yaml) }.to raise_error(error_message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#pwd' do
|
47
|
+
describe 'more than one of the projects listed matches the working directory' do
|
48
|
+
it "should return the more specific directory" do
|
49
|
+
fake_configuration = successful_setup
|
50
|
+
|
51
|
+
current_project = PGit::CurrentProject.new(fake_configuration.to_yaml)
|
52
|
+
working_directory = current_project.pwd
|
53
|
+
|
54
|
+
expect(working_directory).to eq "/Therapy-Exercises-Online/some_other_project"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#id' do
|
60
|
+
it 'should return the correct pivotal tracker project_id' do
|
61
|
+
fake_configuration = successful_setup
|
62
|
+
|
63
|
+
current_project = PGit::CurrentProject.new(fake_configuration.to_yaml)
|
64
|
+
project_id = current_project.id
|
65
|
+
|
66
|
+
expect(project_id).to eq 12345
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#api_token' do
|
71
|
+
it 'should return the api_token associated to the current project' do
|
72
|
+
fake_configuration = successful_setup
|
73
|
+
|
74
|
+
current_project = PGit::CurrentProject.new(fake_configuration.to_yaml)
|
75
|
+
api_token = current_project.api_token
|
76
|
+
|
77
|
+
expect(api_token).to eq 'astoeuh'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'pgit'
|
2
|
+
|
3
|
+
describe 'PGit::Installer' do
|
4
|
+
describe '~/pgit.rc.yml exists' do
|
5
|
+
it 'should raise an error' do
|
6
|
+
global_opts = {}
|
7
|
+
opts = { }
|
8
|
+
args = {}
|
9
|
+
message = "Error: ~/.pgit.rc.yml already exists"
|
10
|
+
default_file_path = "~/.pgit.rc.yml"
|
11
|
+
file_expanded_path = "/home/edderic/.pgit.rc.yml"
|
12
|
+
|
13
|
+
allow(File).to receive(:expand_path).
|
14
|
+
with(".")
|
15
|
+
allow(File).to receive(:expand_path).
|
16
|
+
with(default_file_path).and_return(file_expanded_path)
|
17
|
+
allow(File).to receive(:exists?).
|
18
|
+
with(file_expanded_path).and_return(true)
|
19
|
+
|
20
|
+
expect do
|
21
|
+
PGit::Installer.new(global_opts, opts, args)
|
22
|
+
end.to raise_error message
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '~/pgit.rc.yml does not exist' do
|
27
|
+
it 'should ask to continue or not' do
|
28
|
+
global_opts = {}
|
29
|
+
opts = { }
|
30
|
+
args = {}
|
31
|
+
|
32
|
+
message = "*** Installing example pgit configuration file under ~/.pgit.rc.yml. " +
|
33
|
+
"Continue? [Y/n]"
|
34
|
+
confirmation_message = "Saving example pgit config in ~/.pgit.rc.yml..."
|
35
|
+
edit_message = "Saved! Please edit ~/.pgit.rc.yml and add the proper Pivotal Tracker API tokens, id, and file paths for each project"
|
36
|
+
answer = instance_double("String", chomp: 'y')
|
37
|
+
expanded_path = "/home/edderic/.pgit.rc.yml"
|
38
|
+
fake_writable_file = double('File')
|
39
|
+
allow(File).to receive(:expand_path).with("~/.pgit.rc.yml").and_return(expanded_path)
|
40
|
+
allow(File).to receive(:exists?).with(expanded_path).and_return(false)
|
41
|
+
allow(File).to receive(:open).with(expanded_path, 'w').and_return(fake_writable_file)
|
42
|
+
allow(STDIN).to receive(:gets).and_return(answer)
|
43
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(message)
|
44
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(confirmation_message)
|
45
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(edit_message)
|
46
|
+
installer = PGit::Installer.new(global_opts, opts, args)
|
47
|
+
|
48
|
+
expect(installer).to have_received(:puts).with(message)
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'user answers "y"' do
|
52
|
+
it "should show the save message" do
|
53
|
+
global_opts = {}
|
54
|
+
opts = { }
|
55
|
+
args = {}
|
56
|
+
|
57
|
+
first_message = "*** Installing example pgit configuration file under ~/.pgit.rc.yml. " +
|
58
|
+
"Continue? [Y/n]"
|
59
|
+
save_message = "Saving example pgit config in ~/.pgit.rc.yml..."
|
60
|
+
expanded_path = "/home/edderic/.pgit.rc.yml"
|
61
|
+
edit_message = "Saved! Please edit ~/.pgit.rc.yml and add the proper Pivotal Tracker API tokens, id, and file paths for each project"
|
62
|
+
fake_writable_file = double('File')
|
63
|
+
allow(File).to receive(:expand_path).with("~/.pgit.rc.yml").and_return(expanded_path)
|
64
|
+
allow(File).to receive(:exists?).with(expanded_path).and_return(false)
|
65
|
+
allow(File).to receive(:open).with(expanded_path, 'w').and_return(fake_writable_file)
|
66
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(edit_message)
|
67
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(first_message)
|
68
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(save_message)
|
69
|
+
|
70
|
+
answer = instance_double("String", chomp: 'Y')
|
71
|
+
allow(STDIN).to receive(:gets).and_return(answer)
|
72
|
+
|
73
|
+
installer = PGit::Installer.new(global_opts, opts, args)
|
74
|
+
|
75
|
+
expect(installer).to have_received(:puts).with(save_message)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should save the file under ~/.pgit.rc.yml' do
|
79
|
+
global_opts = {}
|
80
|
+
opts = { }
|
81
|
+
args = {}
|
82
|
+
|
83
|
+
first_message = "*** Installing example pgit configuration file under ~/.pgit.rc.yml. " +
|
84
|
+
"Continue? [Y/n]"
|
85
|
+
save_message = "Saving example pgit config in ~/.pgit.rc.yml..."
|
86
|
+
expanded_path = "/home/edderic/.pgit.rc.yml"
|
87
|
+
fake_writable_file = double('File')
|
88
|
+
edit_message = "Saved! Please edit ~/.pgit.rc.yml and add the proper Pivotal Tracker API tokens, id, and file paths for each project"
|
89
|
+
allow(File).to receive(:expand_path).with("~/.pgit.rc.yml").and_return(expanded_path)
|
90
|
+
allow(File).to receive(:exists?).with(expanded_path).and_return(false)
|
91
|
+
allow(File).to receive(:open).with(expanded_path, 'w').and_return(fake_writable_file)
|
92
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(first_message)
|
93
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(save_message)
|
94
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(edit_message)
|
95
|
+
|
96
|
+
answer = instance_double("String", chomp: 'Y')
|
97
|
+
allow(STDIN).to receive(:gets).and_return(answer)
|
98
|
+
|
99
|
+
installer = PGit::Installer.new(global_opts, opts, args)
|
100
|
+
|
101
|
+
expect(File).to have_received(:open).with(expanded_path, 'w')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should ask the user to edit the config file' do
|
105
|
+
global_opts = {}
|
106
|
+
opts = { }
|
107
|
+
args = {}
|
108
|
+
|
109
|
+
first_message = "*** Installing example pgit configuration file under ~/.pgit.rc.yml. " +
|
110
|
+
"Continue? [Y/n]"
|
111
|
+
save_message = "Saving example pgit config in ~/.pgit.rc.yml..."
|
112
|
+
edit_message = "Saved! Please edit ~/.pgit.rc.yml and add the proper Pivotal Tracker API tokens, id, and file paths for each project"
|
113
|
+
expanded_path = "/home/edderic/.pgit.rc.yml"
|
114
|
+
fake_writable_file = double('File')
|
115
|
+
allow(File).to receive(:expand_path).with("~/.pgit.rc.yml").and_return(expanded_path)
|
116
|
+
allow(File).to receive(:exists?).with(expanded_path).and_return(false)
|
117
|
+
allow(File).to receive(:open).with(expanded_path, 'w').and_return(fake_writable_file)
|
118
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(first_message)
|
119
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(edit_message)
|
120
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(save_message)
|
121
|
+
|
122
|
+
answer = instance_double("String", chomp: 'Y')
|
123
|
+
allow(STDIN).to receive(:gets).and_return(answer)
|
124
|
+
|
125
|
+
installer = PGit::Installer.new(global_opts, opts, args)
|
126
|
+
|
127
|
+
expect(installer).to have_received(:puts).with(edit_message)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe 'user answers with "n"' do
|
132
|
+
it "should show the abort message" do
|
133
|
+
message = "Aborting installation..."
|
134
|
+
global_opts = {}
|
135
|
+
opts = { }
|
136
|
+
args = {}
|
137
|
+
|
138
|
+
first_message = "*** Installing example pgit configuration file under ~/.pgit.rc.yml. " +
|
139
|
+
"Continue? [Y/n]"
|
140
|
+
expanded_path = "/home/edderic/.pgit.rc.yml"
|
141
|
+
allow(File).to receive(:expand_path).with("~/.pgit.rc.yml").and_return(expanded_path)
|
142
|
+
allow(File).to receive(:exists?).with(expanded_path).and_return(false)
|
143
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(first_message)
|
144
|
+
allow_any_instance_of(PGit::Installer).to receive(:puts).with(message)
|
145
|
+
|
146
|
+
answer = instance_double("String", chomp: 'n')
|
147
|
+
allow(STDIN).to receive(:gets).and_return(answer)
|
148
|
+
|
149
|
+
installer = PGit::Installer.new(global_opts, opts, args)
|
150
|
+
|
151
|
+
expect(installer).to have_received(:puts).with(message)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe 'user answers with something els' do
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
describe 'pgit' do
|
2
|
+
describe 'story_branch' do
|
3
|
+
it 'should output the help info for story_branch command' do
|
4
|
+
pgit_expanded_path = File.expand_path('bin/pgit')
|
5
|
+
|
6
|
+
result = `bundle exec #{pgit_expanded_path} story_branch`
|
7
|
+
story_branch_matches = result.match(/story_branch/)
|
8
|
+
name_match = result.match(/NAME/)
|
9
|
+
|
10
|
+
expect(story_branch_matches.length).to be >= 1
|
11
|
+
expect(name_match.length).to be >= 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# describe 'install' do
|
16
|
+
# it 'should ask the user some questions' do
|
17
|
+
# pgit_expanded_path = File.expand_path('bin/pgit')
|
18
|
+
# message = "This will save the config file on ~/.pgit.rc.yml"
|
19
|
+
# allow(Kernel).to receive(:puts).with message
|
20
|
+
#
|
21
|
+
# result = `bundle exec #{pgit_expanded_path} install`
|
22
|
+
# expect(Kernel).to have_received(:puts).with message
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
|
26
|
+
# describe 'commit' do
|
27
|
+
# describe 'on branch some-story-branch-1234' do
|
28
|
+
# it 'should prepend the commit with [#1234]' do
|
29
|
+
#
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'pgit'
|
2
|
+
|
3
|
+
describe 'PGit::StoryBranch::Application' do
|
4
|
+
describe '#new' do
|
5
|
+
describe 'options hash has start: 1234,
|
6
|
+
and "config" => is some config' do
|
7
|
+
it 'should call #start on an instance of StoryBranch' do
|
8
|
+
global_opts = {}
|
9
|
+
opts = { start: 1234 }
|
10
|
+
args = {}
|
11
|
+
fake_story_branch = instance_double('PGit::StoryBranch')
|
12
|
+
fake_config_yaml = double('config_yaml')
|
13
|
+
fake_configuration = instance_double('PGit::Configuration', to_yaml: fake_config_yaml)
|
14
|
+
allow(fake_story_branch).to receive(:start)
|
15
|
+
fake_get_request_results = double('json_response')
|
16
|
+
fake_story_id = double('fake_story_id')
|
17
|
+
|
18
|
+
fake_story = double('PGit::Story', id: fake_story_id)
|
19
|
+
fake_story_class = class_double('PGit::Story', get: fake_get_request_results)
|
20
|
+
fake_current_project = double('current_project')
|
21
|
+
fake_name_parser = instance_double(PGit::StoryBranch::NameParser)
|
22
|
+
allow(PGit::CurrentProject).to receive(:new).with(fake_config_yaml).and_return(fake_current_project)
|
23
|
+
allow(PGit::StoryBranch::NameParser).to receive(:new).with(fake_story).and_return(fake_name_parser)
|
24
|
+
allow(PGit::Story).to receive(:get).with(1234, fake_current_project).and_return(fake_story)
|
25
|
+
allow(PGit::StoryBranch).to receive(:new).with(fake_name_parser).and_return(fake_story_branch)
|
26
|
+
allow(PGit::Configuration).to receive(:new).and_return(fake_configuration)
|
27
|
+
|
28
|
+
PGit::StoryBranch::Application.new(global_opts, opts, args)
|
29
|
+
|
30
|
+
expect(fake_story_branch).to have_received(:start)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'options passed in have keys that only point to nil or false' do
|
35
|
+
it 'should show the helpfile' do
|
36
|
+
global_opts = {}
|
37
|
+
opts = { start: nil, finish: false }
|
38
|
+
args = {}
|
39
|
+
story_branch_help_call = 'pgit story_branch --help'
|
40
|
+
allow_any_instance_of(PGit::StoryBranch::Application).to receive(:`).with(story_branch_help_call)
|
41
|
+
|
42
|
+
story_branch = PGit::StoryBranch::Application.new(global_opts, opts, args)
|
43
|
+
|
44
|
+
expect(story_branch).to have_received(:`).with(story_branch_help_call)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'pgit'
|
2
|
+
|
3
|
+
describe 'PGit::StoryBranch::NameParser' do
|
4
|
+
describe '#name' do
|
5
|
+
it 'should remove fluff words, remove periods,
|
6
|
+
replace spaces with dashes, suffix story_id' do
|
7
|
+
|
8
|
+
unparsed_name = "Deemphasize the Clue on the stimulus screen of multi-screen exercises."
|
9
|
+
story_id = '12345'
|
10
|
+
fake_story = double('PGit::Story', id: story_id, name: unparsed_name)
|
11
|
+
|
12
|
+
name_parser = PGit::StoryBranch::NameParser.new(fake_story)
|
13
|
+
parsed = name_parser.name
|
14
|
+
|
15
|
+
expect(parsed).to eq "deemphasize-clue-stimulus-screen-multiscreen-exercises-12345"
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should strip non-alpha-numerics like apostrophes' do
|
19
|
+
unparsed_name = "Some don't like putin's dictatorship"
|
20
|
+
story_id = '29292'
|
21
|
+
|
22
|
+
fake_story = double('PGit::Story', id: story_id, name: unparsed_name)
|
23
|
+
|
24
|
+
name_parser = PGit::StoryBranch::NameParser.new(fake_story)
|
25
|
+
parsed = name_parser.name
|
26
|
+
|
27
|
+
expect(parsed).to eq "some-dont-like-putins-dictatorship-29292"
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should remove all non-word characters' do
|
31
|
+
unparsed_name = "Some *@# don't like ,putin's dictator-ship"
|
32
|
+
story_id = '29292'
|
33
|
+
|
34
|
+
fake_story = double('PGit::Story', id: story_id, name: unparsed_name)
|
35
|
+
|
36
|
+
name_parser = PGit::StoryBranch::NameParser.new(fake_story)
|
37
|
+
parsed = name_parser.name
|
38
|
+
|
39
|
+
expect(parsed).to eq "some-dont-like-putins-dictatorship-29292"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'pgit'
|
2
|
+
|
3
|
+
describe 'PGit::StoryBranch' do
|
4
|
+
describe '#id' do
|
5
|
+
it 'should return the story_id' do
|
6
|
+
fake_parsed_branch_name = 'bring-me-da-coconut-1234'
|
7
|
+
fake_story_id = '1234'
|
8
|
+
name_parser = instance_double('PGit::StoryBranch::NameParser',
|
9
|
+
story_id: fake_story_id,
|
10
|
+
name: fake_parsed_branch_name)
|
11
|
+
allow(name_parser).to receive(:name).and_return(fake_parsed_branch_name)
|
12
|
+
story_branch = PGit::StoryBranch.new(name_parser)
|
13
|
+
story_branch_id = story_branch.id
|
14
|
+
|
15
|
+
expect(story_branch_id).to eq '1234'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
describe '#start' do
|
21
|
+
it 'should call the backticks on the Kernel with the proper branch name' do
|
22
|
+
fake_parsed_json = { "name" => "Bring me the passengers",
|
23
|
+
"id" => 555
|
24
|
+
}
|
25
|
+
fake_json_response = double('fake_json_response')
|
26
|
+
fake_story_id = 555
|
27
|
+
fake_story_name = "bring-me-passengers-555"
|
28
|
+
allow(JSON).to receive(:parse).with(fake_json_response).and_return(fake_parsed_json)
|
29
|
+
fake_name_parser = instance_double('PGit::StoryBranch::NameParser',
|
30
|
+
story_id: fake_story_id,
|
31
|
+
name: fake_story_name
|
32
|
+
)
|
33
|
+
checkout_branch_command = "git checkout -b bring-me-passengers-555"
|
34
|
+
pg_branch = PGit::StoryBranch.new(fake_name_parser)
|
35
|
+
allow(pg_branch).to receive(:`).with(checkout_branch_command)
|
36
|
+
|
37
|
+
pg_branch.start
|
38
|
+
|
39
|
+
expect(pg_branch).to have_received(:`).with(checkout_branch_command)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#name' do
|
44
|
+
it 'should return the result of the parsed branch name' do
|
45
|
+
fake_parsed_json = { "name" => "Bring me the passengers",
|
46
|
+
"id" => 555
|
47
|
+
}
|
48
|
+
fake_json_response = double('fake_json_response')
|
49
|
+
allow(JSON).to receive(:parse).with(fake_json_response).and_return(fake_parsed_json)
|
50
|
+
checkout_branch_command = "git checkout -b bring-me-passengers-555"
|
51
|
+
fake_parsed_branch_name = double('parsed_branch_name')
|
52
|
+
fake_name_parser = double('name_parser', name: fake_parsed_branch_name)
|
53
|
+
|
54
|
+
|
55
|
+
pg_branch = PGit::StoryBranch.new(fake_name_parser)
|
56
|
+
|
57
|
+
branch_name = pg_branch.name
|
58
|
+
|
59
|
+
expect(branch_name).to eq fake_parsed_branch_name
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# describe '#new without any arguments' do
|
64
|
+
# describe 'on a branch without a story id' do
|
65
|
+
# describe '#id' do
|
66
|
+
# it 'should throw an error' do
|
67
|
+
# fake_current_branch_name = "master"
|
68
|
+
# error_message = "Error: #{fake_current_branch_name} does not have a story id at the end"
|
69
|
+
# allow(PGit::CurrentBranch).to receive(:name).and_return(fake_current_branch_name)
|
70
|
+
#
|
71
|
+
# expect{PGit::StoryBranch.new}.to raise_error error_message
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# describe 'on a branch with a story id' do
|
77
|
+
# describe '#id' do
|
78
|
+
# it 'should return the id' do
|
79
|
+
# fake_current_branch_name = "some-feature-branch-12345678"
|
80
|
+
# allow(PGit::CurrentBranch).to receive(:name).and_return(fake_current_branch_name)
|
81
|
+
# error_message = "Error: #{fake_current_branch_name} does not have a story id at the end"
|
82
|
+
# story_branch = PGit::StoryBranch.new
|
83
|
+
# story_branch_id = story_branch.id
|
84
|
+
#
|
85
|
+
# expect(story_branch_id).to eq('12345678')
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
end
|