pgit 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.agignore +3 -0
- data/.travis.yml +1 -0
- data/README.markdown +32 -9
- data/Rakefile +12 -0
- data/bin/pgit +167 -25
- data/lib/pgit.rb +40 -10
- data/lib/pgit/bilateral/handle_back.rb +22 -0
- data/lib/pgit/bilateral/handle_choose_story.rb +31 -0
- data/lib/pgit/bilateral/story.rb +44 -0
- data/lib/pgit/command.rb +83 -0
- data/lib/pgit/command/add.rb +36 -0
- data/lib/pgit/command/application.rb +21 -0
- data/lib/pgit/command/edit.rb +36 -0
- data/lib/pgit/command/remove.rb +36 -0
- data/lib/pgit/command/run.rb +32 -0
- data/lib/pgit/command/show.rb +53 -0
- data/lib/pgit/configuration.rb +27 -3
- data/lib/pgit/current_project.rb +9 -45
- data/lib/pgit/current_project/validator.rb +2 -1
- data/lib/pgit/error/external.rb +11 -0
- data/lib/pgit/error/user.rb +12 -0
- data/lib/pgit/helpers/heredoc.rb +17 -0
- data/lib/pgit/helpers/query_methods.rb +63 -0
- data/lib/pgit/helpers/string_extensions.rb +29 -0
- data/lib/pgit/installer/bash_auto_completion.rb +57 -0
- data/lib/pgit/pivotal/collection_request.rb +21 -0
- data/lib/pgit/pivotal/individual_request.rb +47 -0
- data/lib/pgit/pivotal/iteration.rb +6 -0
- data/lib/pgit/pivotal/iterations.rb +15 -0
- data/lib/pgit/pivotal/project.rb +6 -0
- data/lib/pgit/pivotal/projects.rb +20 -0
- data/lib/pgit/pivotal/query.rb +8 -0
- data/lib/pgit/pivotal/request.rb +33 -0
- data/lib/pgit/pivotal/request/query.rb +25 -0
- data/lib/pgit/pivotal/story.rb +38 -0
- data/lib/pgit/pivotal_request_validator.rb +1 -1
- data/lib/pgit/project.rb +78 -0
- data/lib/pgit/project/add.rb +28 -0
- data/lib/pgit/project/application.rb +21 -0
- data/lib/pgit/project/interactive_adder.rb +41 -0
- data/lib/pgit/project/remove.rb +41 -0
- data/lib/pgit/project/reuse_api_token_adder.rb +48 -0
- data/lib/pgit/response_handler.rb +16 -0
- data/lib/pgit/root.rb +5 -0
- data/lib/pgit/status.rb +16 -0
- data/lib/pgit/story_branch/application.rb +3 -3
- data/lib/pgit/{name_parser.rb → story_branch/name_parser.rb} +0 -0
- data/lib/pgit/story_branch/story_id_parser.rb +11 -0
- data/lib/pgit/validators/project_validator.rb +20 -0
- data/lib/pgit/version.rb +1 -1
- data/lib/pivotal +0 -0
- data/pgit.gemspec +5 -0
- data/spec/fixtures/iterations +1 -0
- data/spec/pgit/bilateral/handle_back_spec.rb +29 -0
- data/spec/pgit/bilateral/handle_choose_story_spec.rb +17 -0
- data/spec/pgit/bilateral/story_spec.rb +178 -0
- data/spec/pgit/command/add_spec.rb +68 -0
- data/spec/pgit/command/application_spec.rb +110 -0
- data/spec/pgit/command/edit_spec.rb +61 -0
- data/spec/pgit/command/remove_spec.rb +76 -0
- data/spec/pgit/command/run_spec.rb +49 -0
- data/spec/pgit/command/show_spec.rb +95 -0
- data/spec/pgit/command_spec.rb +299 -0
- data/spec/pgit/configuration_spec.rb +121 -18
- data/spec/pgit/current_project/validator_spec.rb +2 -1
- data/spec/pgit/current_project_spec.rb +20 -71
- data/spec/pgit/{external_error_spec.rb → error/external_spec.rb} +3 -3
- data/spec/pgit/error/user_spec.rb +17 -0
- data/spec/pgit/helpers/heredoc_spec.rb +33 -0
- data/spec/pgit/helpers/query_methods_spec.rb +24 -0
- data/spec/pgit/helpers/string_extensions_spec.rb +49 -0
- data/spec/pgit/installer/bash_auto_completion_spec.rb +134 -0
- data/spec/pgit/pivotal/individual_request_spec.rb +32 -0
- data/spec/pgit/pivotal/iteration_spec.rb +19 -0
- data/spec/pgit/pivotal/iterations_spec.rb +37 -0
- data/spec/pgit/pivotal/project_spec.rb +9 -0
- data/spec/pgit/pivotal/projects_spec.rb +48 -0
- data/spec/pgit/pivotal/request/query_spec.rb +24 -0
- data/spec/pgit/pivotal/story_spec.rb +113 -0
- data/spec/pgit/pivotal_request_validator_spec.rb +3 -3
- data/spec/pgit/project/add_spec.rb +52 -0
- data/spec/pgit/project/application_spec.rb +69 -0
- data/spec/pgit/project/interactive_adder_spec.rb +45 -0
- data/spec/pgit/project/remove_spec.rb +86 -0
- data/spec/pgit/project/reuse_api_token_adder_spec.rb +41 -0
- data/spec/pgit/project_spec.rb +513 -0
- data/spec/pgit/status_spec.rb +40 -0
- data/spec/pgit/story_branch/application_spec.rb +5 -8
- data/spec/pgit/story_branch/name_parser_spec.rb +3 -3
- data/spec/pgit/story_branch/story_id_parser_spec.rb +17 -0
- data/spec/pgit/validators/project_validator_spec.rb +39 -0
- metadata +146 -21
- data/lib/pgit/configuration/layout_error.rb +0 -9
- data/lib/pgit/configuration/missing_attributes_error.rb +0 -10
- data/lib/pgit/configuration/not_found_error.rb +0 -10
- data/lib/pgit/configuration/project_missing_error.rb +0 -10
- data/lib/pgit/configuration/validator.rb +0 -41
- data/lib/pgit/current_project/no_paths_match_working_dir_error.rb +0 -10
- data/lib/pgit/external_error.rb +0 -9
- data/lib/pgit/installer/configuration.rb +0 -34
- data/lib/pgit/story.rb +0 -44
- data/spec/pgit/configuration/missing_attributes_error_spec.rb +0 -30
- data/spec/pgit/configuration/not_found_error_spec.rb +0 -17
- data/spec/pgit/configuration/project_missing_error_spec.rb +0 -30
- data/spec/pgit/configuration/validator_spec.rb +0 -79
- data/spec/pgit/current_project/no_paths_match_working_dir_error_spec.rb +0 -17
- data/spec/pgit/installer/configuration_spec.rb +0 -162
- data/spec/pgit/story_spec.rb +0 -35
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'PGit::Command::Add' do
|
4
|
+
describe 'when the command already exist' do
|
5
|
+
it 'should raise an error since it already exists' do
|
6
|
+
name = 'existent_command'
|
7
|
+
steps = ['existent_step']
|
8
|
+
global_opts = {}
|
9
|
+
opts = { name: name, steps: steps }
|
10
|
+
args = []
|
11
|
+
expected_message = "Command 'existent_command' already exists in the current project. If you want to update the command, see `pgit cmd edit --help`"
|
12
|
+
new_command = instance_double('PGit::Command', name: name, steps: steps)
|
13
|
+
fake_command = instance_double('PGit::Command', name: name, steps: steps)
|
14
|
+
fake_project = instance_double('PGit::CurrentProject')
|
15
|
+
|
16
|
+
fake_app = instance_double('PGit::Command::Application',
|
17
|
+
commands: [fake_command],
|
18
|
+
command: new_command,
|
19
|
+
args: args,
|
20
|
+
opts: opts,
|
21
|
+
global_opts: global_opts,
|
22
|
+
current_project: fake_project)
|
23
|
+
|
24
|
+
add = PGit::Command::Add.new(fake_app)
|
25
|
+
|
26
|
+
expect{ add.execute! }.to raise_error PGit::Error::User, expected_message
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'when there the command does not exist' do
|
31
|
+
it 'should show the success message' do
|
32
|
+
non_existent_name = 'non_existent_command'
|
33
|
+
non_existent_steps = ['existent_step']
|
34
|
+
existent_name = 'existent_name'
|
35
|
+
existent_steps= 'existent_steps'
|
36
|
+
global_opts = {}
|
37
|
+
opts = { name: non_existent_name, steps: non_existent_steps }
|
38
|
+
args = []
|
39
|
+
expected_message = "Successfully added command 'non_existent_command' to the current project!"
|
40
|
+
fake_project = instance_double('PGit::CurrentProject')
|
41
|
+
fake_command = instance_double('PGit::Command',
|
42
|
+
name: existent_name,
|
43
|
+
steps: existent_steps,
|
44
|
+
save!: nil)
|
45
|
+
|
46
|
+
new_fake_command = instance_double('PGit::Command',
|
47
|
+
name: non_existent_name,
|
48
|
+
steps: non_existent_steps,
|
49
|
+
save!: nil)
|
50
|
+
|
51
|
+
fake_app = instance_double('PGit::Command::Application',
|
52
|
+
commands: [fake_command],
|
53
|
+
command: new_fake_command,
|
54
|
+
args: args,
|
55
|
+
opts: opts,
|
56
|
+
global_opts: global_opts,
|
57
|
+
current_project: fake_project)
|
58
|
+
|
59
|
+
add = PGit::Command::Add.new(fake_app)
|
60
|
+
allow(add).to receive(:puts)
|
61
|
+
|
62
|
+
add.execute!
|
63
|
+
|
64
|
+
expect(new_fake_command).to have_received(:save!)
|
65
|
+
expect(add).to have_received(:puts).with(expected_message)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'PGit::Command::Application' do
|
4
|
+
class SomeCommandApp < PGit::Command::Application
|
5
|
+
end
|
6
|
+
|
7
|
+
before do
|
8
|
+
existent_name = 'existent_name'
|
9
|
+
some_other_existent_name = 'some_other_existent_name'
|
10
|
+
new_name = 'new_name'
|
11
|
+
new_steps = ['echo step1', 'echo step2']
|
12
|
+
@global_opts, @opts, @args = {}, { 'name' => new_name, 'steps' => new_steps}, [existent_name]
|
13
|
+
|
14
|
+
fake_steps = ["git fetch origin master",
|
15
|
+
"git push origin :STORY_BRANCH"]
|
16
|
+
fake_command_string = double('fake_command_string')
|
17
|
+
@new_command = instance_double('PGit::Command', name: new_name, steps: new_steps)
|
18
|
+
@fake_command = instance_double('PGit::Command', to_s: fake_command_string, name: existent_name)
|
19
|
+
@fake_commands = [@fake_command]
|
20
|
+
fake_yaml = double('fake_yaml')
|
21
|
+
fake_configuration = instance_double('PGit::Configuration', to_yaml: fake_yaml)
|
22
|
+
@fake_current_project = instance_double('PGit::CurrentProject',
|
23
|
+
commands: @fake_commands)
|
24
|
+
|
25
|
+
allow(PGit::Configuration).to receive(:new).
|
26
|
+
and_return(fake_configuration)
|
27
|
+
allow(PGit::CurrentProject).to receive(:new).
|
28
|
+
with(fake_configuration).and_return(@fake_current_project)
|
29
|
+
allow(PGit::Command).to receive(:new).
|
30
|
+
with(existent_name, fake_steps, @fake_current_project).and_return(@fake_command)
|
31
|
+
allow(PGit::Command).to receive(:new).
|
32
|
+
with(new_name, new_steps, @fake_current_project).and_return(@new_command)
|
33
|
+
|
34
|
+
@app = SomeCommandApp.new(@global_opts, @opts, @args)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#commands' do
|
38
|
+
it 'returns the commands' do
|
39
|
+
expect(@app.commands).to eq @fake_commands
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#global_opts' do
|
44
|
+
it 'returns the global_opts' do
|
45
|
+
expect(@app.global_opts).to eq @global_opts
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#opts' do
|
50
|
+
it 'returns the opts' do
|
51
|
+
expect(@app.opts).to eq @opts
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#args' do
|
56
|
+
it 'returns the args' do
|
57
|
+
expect(@app.args).to eq @args
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#current_project' do
|
62
|
+
it 'return the current project' do
|
63
|
+
expect(@app.current_project).to eq @fake_current_project
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#command' do
|
68
|
+
it 'returns the command' do
|
69
|
+
expect(@app.command).to eq @new_command
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'passing in opts without steps' do
|
74
|
+
it 'should default steps of the command to [:no_steps_provided]' do
|
75
|
+
class SomeOtherCommandApp < PGit::Command::Application
|
76
|
+
end
|
77
|
+
|
78
|
+
existent_name = 'existent_name'
|
79
|
+
some_other_existent_name = 'some_other_existent_name'
|
80
|
+
new_name = 'new_name'
|
81
|
+
new_steps = [:no_steps_provided]
|
82
|
+
@global_opts, @opts, @args = {}, { 'name' => new_name }, [existent_name]
|
83
|
+
|
84
|
+
fake_steps = ["git fetch origin master",
|
85
|
+
"git push origin :STORY_BRANCH"]
|
86
|
+
fake_command_string = double('fake_command_string')
|
87
|
+
@new_command = instance_double('PGit::Command', name: new_name, steps: new_steps)
|
88
|
+
@fake_command = instance_double('PGit::Command', to_s: fake_command_string, name: existent_name)
|
89
|
+
@fake_commands = [@fake_command]
|
90
|
+
fake_yaml = double('fake_yaml')
|
91
|
+
fake_configuration = instance_double('PGit::Configuration', to_yaml: fake_yaml)
|
92
|
+
@fake_current_project = instance_double('PGit::CurrentProject',
|
93
|
+
commands: @fake_commands)
|
94
|
+
allow(PGit::Configuration).to receive(:new).
|
95
|
+
and_return(fake_configuration)
|
96
|
+
allow(PGit::CurrentProject).to receive(:new).
|
97
|
+
with(fake_configuration).and_return(@fake_current_project)
|
98
|
+
allow(PGit::Command).to receive(:new).
|
99
|
+
with(existent_name, fake_steps, @fake_current_project).and_return(@fake_command)
|
100
|
+
allow(PGit::Command).to receive(:new).
|
101
|
+
with(new_name, new_steps, @fake_current_project).and_return(@new_command)
|
102
|
+
|
103
|
+
|
104
|
+
@app = SomeOtherCommandApp.new(@global_opts, @opts, @args)
|
105
|
+
expect(@app.command).to eq @new_command
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'PGit::Command::Edit' do
|
4
|
+
describe 'when the command already exists' do
|
5
|
+
it 'should be successful' do
|
6
|
+
name = 'existent_command'
|
7
|
+
steps = ['existent_step']
|
8
|
+
global_opts = {}
|
9
|
+
opts = { name: name, steps: steps }
|
10
|
+
args = []
|
11
|
+
expected_message = "Successfully edited command 'existent_command' of the current project!"
|
12
|
+
fake_command = instance_double('PGit::Command', name: name, steps: steps, save!: nil)
|
13
|
+
|
14
|
+
fake_app = instance_double('PGit::Command::Application',
|
15
|
+
command: fake_command,
|
16
|
+
commands: [fake_command],
|
17
|
+
args: args,
|
18
|
+
opts: opts,
|
19
|
+
global_opts: global_opts)
|
20
|
+
|
21
|
+
edit = PGit::Command::Edit.new(fake_app)
|
22
|
+
allow(edit).to receive(:puts).with(expected_message)
|
23
|
+
edit.execute!
|
24
|
+
|
25
|
+
expect(edit).to have_received(:puts).with(expected_message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'when there the command does not exist' do
|
30
|
+
it 'should raise an error' do
|
31
|
+
non_existent_name = 'non_existent_command'
|
32
|
+
non_existent_steps = ['existent_step']
|
33
|
+
existent_name = 'existent_name'
|
34
|
+
existent_steps= 'existent_steps'
|
35
|
+
global_opts = {}
|
36
|
+
opts = { name: non_existent_name, steps: non_existent_steps }
|
37
|
+
args = []
|
38
|
+
expected_message = "Cannot edit a command that does not exist in the current project. See `pgit cmd add --help` if you want to add a new command"
|
39
|
+
fake_command = instance_double('PGit::Command',
|
40
|
+
name: existent_name,
|
41
|
+
steps: existent_steps,
|
42
|
+
save!: nil)
|
43
|
+
|
44
|
+
new_fake_command = instance_double('PGit::Command',
|
45
|
+
name: non_existent_name,
|
46
|
+
steps: non_existent_steps,
|
47
|
+
save!: nil)
|
48
|
+
|
49
|
+
fake_app = instance_double('PGit::Command::Application',
|
50
|
+
command: new_fake_command,
|
51
|
+
commands: [fake_command],
|
52
|
+
args: args,
|
53
|
+
opts: opts,
|
54
|
+
global_opts: global_opts)
|
55
|
+
|
56
|
+
edit = PGit::Command::Edit.new(fake_app)
|
57
|
+
|
58
|
+
expect{ edit.execute! }.to raise_error(PGit::Error::User, expected_message)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'PGit::Command::Remove' do
|
4
|
+
describe 'when the command already exists' do
|
5
|
+
it 'should be successful' do
|
6
|
+
name = 'existent_command'
|
7
|
+
steps = ['existent_step']
|
8
|
+
global_opts = {}
|
9
|
+
opts = { name: name }
|
10
|
+
args = []
|
11
|
+
expected_message = "Successfully removed command 'existent_command' from the current project!"
|
12
|
+
fake_command = instance_double('PGit::Command', name: name,
|
13
|
+
steps: steps,
|
14
|
+
save!: nil,
|
15
|
+
remove!: nil)
|
16
|
+
new_command = instance_double('PGit::Command', name: name,
|
17
|
+
steps: steps,
|
18
|
+
save!: nil,
|
19
|
+
remove!: nil)
|
20
|
+
|
21
|
+
project = instance_double('PGit::CurrentProject')
|
22
|
+
|
23
|
+
fake_app = instance_double('PGit::Command::Application',
|
24
|
+
commands: [fake_command],
|
25
|
+
command: new_command,
|
26
|
+
args: args,
|
27
|
+
opts: opts,
|
28
|
+
global_opts: global_opts,
|
29
|
+
current_project: project)
|
30
|
+
|
31
|
+
allow(PGit::Command).to receive(:new).with(name, ['fake_steps'], project).and_return(fake_command)
|
32
|
+
remove = PGit::Command::Remove.new(fake_app)
|
33
|
+
allow(remove).to receive(:puts)
|
34
|
+
remove.execute!
|
35
|
+
|
36
|
+
expect(remove).to have_received(:puts).with(expected_message)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'when there the command does not exist' do
|
41
|
+
it 'should raise an error' do
|
42
|
+
non_existent_name = 'non_existent_command'
|
43
|
+
non_existent_steps = ['existent_step']
|
44
|
+
existent_name = 'existent_name'
|
45
|
+
existent_steps= 'existent_steps'
|
46
|
+
global_opts = {}
|
47
|
+
opts = { name: non_existent_name }
|
48
|
+
args = []
|
49
|
+
expected_message = "Cannot remove a command that does not exist in the current project. See `pgit cmd add --help` if you want to add a new command"
|
50
|
+
project = instance_double('PGit::CurrentProject')
|
51
|
+
fake_command = instance_double('PGit::Command',
|
52
|
+
name: existent_name,
|
53
|
+
steps: existent_steps,
|
54
|
+
save!: nil)
|
55
|
+
|
56
|
+
new_fake_command = instance_double('PGit::Command',
|
57
|
+
name: non_existent_name,
|
58
|
+
steps: non_existent_steps,
|
59
|
+
save!: nil)
|
60
|
+
|
61
|
+
allow(PGit::Command).to receive(:new).with(opts[:name], ['fake_steps'], project).and_return(new_fake_command)
|
62
|
+
|
63
|
+
fake_app = instance_double('PGit::Command::Application',
|
64
|
+
command: new_fake_command,
|
65
|
+
commands: [fake_command],
|
66
|
+
args: args,
|
67
|
+
opts: opts,
|
68
|
+
global_opts: global_opts,
|
69
|
+
current_project: project)
|
70
|
+
|
71
|
+
remove = PGit::Command::Remove.new(fake_app)
|
72
|
+
|
73
|
+
expect{ remove.execute! }.to raise_error(PGit::Error::User, expected_message)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'PGit::Command::Run' do
|
4
|
+
describe '#run' do
|
5
|
+
it 'raises a command not found exception if the item does not exist' do
|
6
|
+
global_opts = {}
|
7
|
+
opts = {}
|
8
|
+
args = ['non_existent_command']
|
9
|
+
project = instance_double('PGit::CurrentProject')
|
10
|
+
|
11
|
+
app = instance_double('PGit::Command::Application',
|
12
|
+
commands: [],
|
13
|
+
args: args,
|
14
|
+
opts: opts,
|
15
|
+
global_opts: global_opts,
|
16
|
+
current_project: project)
|
17
|
+
|
18
|
+
run = PGit::Command::Run.new(app)
|
19
|
+
error_message = "Command '#{args[0]}' does not exist. Run 'pgit cmd show' to see the available custom commands."
|
20
|
+
|
21
|
+
expect do
|
22
|
+
run.execute!
|
23
|
+
end.to raise_error(PGit::Error::User, error_message)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'calls execute on the command if it exists' do
|
27
|
+
existent_name = 'existent_command'
|
28
|
+
global_opts = {}
|
29
|
+
opts = {}
|
30
|
+
args = [existent_name]
|
31
|
+
|
32
|
+
fake_command = instance_double('PGit::Command', name: existent_name)
|
33
|
+
allow(fake_command).to receive(:execute)
|
34
|
+
project = instance_double('PGit::CurrentProject')
|
35
|
+
app = instance_double('PGit::Command::Application',
|
36
|
+
commands: [fake_command],
|
37
|
+
args: args,
|
38
|
+
opts: opts,
|
39
|
+
global_opts: global_opts,
|
40
|
+
current_project: project
|
41
|
+
)
|
42
|
+
|
43
|
+
run = PGit::Command::Run.new(app)
|
44
|
+
run.execute!
|
45
|
+
|
46
|
+
expect(fake_command).to have_received(:execute)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'PGit::Command::Show' do
|
4
|
+
before { Rainbow.enabled = false }
|
5
|
+
describe 'without any options' do
|
6
|
+
it 'raises an error if there are no commands' do
|
7
|
+
global_opts = []
|
8
|
+
opts = []
|
9
|
+
args = []
|
10
|
+
|
11
|
+
fake_app = instance_double('PGit::Command::Application',
|
12
|
+
commands: [],
|
13
|
+
args: args,
|
14
|
+
opts: opts,
|
15
|
+
global_opts: global_opts)
|
16
|
+
app = PGit::Command::Show.new(fake_app)
|
17
|
+
message = "No commands are listed for this project. Run `pgit cmd add --help` for more info."
|
18
|
+
expect { app.execute! }.to raise_error(PGit::Error::User, message)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'lists the commands if there are commands' do
|
22
|
+
global_opts = []
|
23
|
+
opts = []
|
24
|
+
args = []
|
25
|
+
|
26
|
+
expected_message = "Listing custom commands of the current project..."
|
27
|
+
fake_formatted_command = instance_double('String')
|
28
|
+
fake_command = instance_double('PGit::Command', to_s: fake_formatted_command)
|
29
|
+
|
30
|
+
fake_app = instance_double('PGit::Command::Application',
|
31
|
+
commands: [fake_command],
|
32
|
+
args: args,
|
33
|
+
opts: opts,
|
34
|
+
global_opts: global_opts)
|
35
|
+
show = PGit::Command::Show.new(fake_app)
|
36
|
+
allow(show).to receive(:puts)
|
37
|
+
|
38
|
+
show.execute!
|
39
|
+
|
40
|
+
expect(show).to have_received(:puts).with(expected_message)
|
41
|
+
expect(show).to have_received(:puts).with(fake_formatted_command)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'when a command_name is passed in' do
|
46
|
+
it 'should print the command if exists' do
|
47
|
+
existent_command_name = 'fake_command'
|
48
|
+
global_opts = []
|
49
|
+
opts = []
|
50
|
+
args = [existent_command_name]
|
51
|
+
|
52
|
+
expected_message = "Listing custom command '#{existent_command_name}' of the current project..."
|
53
|
+
fake_formatted_command = instance_double('String')
|
54
|
+
fake_command = instance_double('PGit::Command',
|
55
|
+
to_s: fake_formatted_command,
|
56
|
+
name: existent_command_name)
|
57
|
+
|
58
|
+
fake_app = instance_double('PGit::Command::Application',
|
59
|
+
commands: [fake_command],
|
60
|
+
args: args,
|
61
|
+
opts: opts,
|
62
|
+
global_opts: global_opts)
|
63
|
+
show = PGit::Command::Show.new(fake_app)
|
64
|
+
allow(show).to receive(:puts)
|
65
|
+
|
66
|
+
show.execute!
|
67
|
+
|
68
|
+
expect(show).to have_received(:puts).with(expected_message)
|
69
|
+
expect(show).to have_received(:puts).with(fake_formatted_command)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should raise an error if the command does not exist' do
|
73
|
+
nonexistent_command_name = 'non_existent_fake_command'
|
74
|
+
existent_command_name = 'fake_command'
|
75
|
+
global_opts = []
|
76
|
+
opts = []
|
77
|
+
args = [nonexistent_command_name]
|
78
|
+
|
79
|
+
expected_message = "Command '#{nonexistent_command_name}' not found for this project"
|
80
|
+
fake_formatted_command = instance_double('String')
|
81
|
+
fake_command = instance_double('PGit::Command',
|
82
|
+
to_s: fake_formatted_command,
|
83
|
+
name: existent_command_name)
|
84
|
+
|
85
|
+
fake_app = instance_double('PGit::Command::Application',
|
86
|
+
commands: [fake_command],
|
87
|
+
args: args,
|
88
|
+
opts: opts,
|
89
|
+
global_opts: global_opts)
|
90
|
+
show = PGit::Command::Show.new(fake_app)
|
91
|
+
|
92
|
+
expect{ show.execute! }.to raise_error PGit::Error::User, expected_message
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|