git_reflow 0.8.10 → 0.9.0

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.ruby-version +1 -1
  4. data/Appraisals +1 -6
  5. data/CHANGELOG.md +426 -348
  6. data/Gemfile.lock +15 -19
  7. data/LICENSE +20 -20
  8. data/README.md +27 -7
  9. data/Rakefile +8 -8
  10. data/bin/console +7 -7
  11. data/bin/setup +6 -6
  12. data/circle.yml +5 -5
  13. data/exe/git-reflow +9 -30
  14. data/git_reflow.gemspec +1 -2
  15. data/lib/git_reflow/config.rb +22 -13
  16. data/lib/git_reflow/git_helpers.rb +69 -22
  17. data/lib/git_reflow/git_server/base.rb +68 -68
  18. data/lib/git_reflow/git_server/git_hub/pull_request.rb +15 -13
  19. data/lib/git_reflow/git_server/pull_request.rb +4 -2
  20. data/lib/git_reflow/merge_error.rb +9 -9
  21. data/lib/git_reflow/rspec/command_line_helpers.rb +9 -1
  22. data/lib/git_reflow/rspec/stub_helpers.rb +13 -13
  23. data/lib/git_reflow/rspec/workflow_helpers.rb +18 -0
  24. data/lib/git_reflow/rspec.rb +1 -0
  25. data/lib/git_reflow/sandbox.rb +1 -0
  26. data/lib/git_reflow/version.rb +1 -1
  27. data/lib/git_reflow/workflow.rb +277 -9
  28. data/lib/git_reflow/workflows/FlatMergeWorkflow +38 -0
  29. data/lib/git_reflow/workflows/core.rb +208 -79
  30. data/lib/git_reflow.rb +3 -14
  31. data/spec/fixtures/awesome_workflow.rb +2 -6
  32. data/spec/fixtures/git/git_config +7 -7
  33. data/spec/fixtures/issues/comment.json.erb +27 -27
  34. data/spec/fixtures/issues/comments.json +29 -29
  35. data/spec/fixtures/issues/comments.json.erb +15 -15
  36. data/spec/fixtures/pull_requests/comment.json.erb +45 -45
  37. data/spec/fixtures/pull_requests/comments.json +47 -47
  38. data/spec/fixtures/pull_requests/comments.json.erb +15 -15
  39. data/spec/fixtures/pull_requests/commits.json +29 -29
  40. data/spec/fixtures/pull_requests/external_pull_request.json +145 -145
  41. data/spec/fixtures/pull_requests/pull_request.json +142 -142
  42. data/spec/fixtures/pull_requests/pull_request.json.erb +142 -142
  43. data/spec/fixtures/pull_requests/pull_request_branch_nonexistent_error.json +32 -0
  44. data/spec/fixtures/pull_requests/pull_request_exists_error.json +32 -32
  45. data/spec/fixtures/pull_requests/pull_requests.json +136 -136
  46. data/spec/fixtures/repositories/commit.json +53 -53
  47. data/spec/fixtures/repositories/commit.json.erb +53 -53
  48. data/spec/fixtures/repositories/commits.json.erb +13 -13
  49. data/spec/fixtures/repositories/statuses.json +31 -31
  50. data/spec/lib/git_reflow/git_helpers_spec.rb +115 -12
  51. data/spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb +6 -6
  52. data/spec/lib/git_reflow/git_server/pull_request_spec.rb +9 -3
  53. data/spec/lib/git_reflow/workflow_spec.rb +190 -11
  54. data/spec/lib/git_reflow/workflows/core_spec.rb +224 -65
  55. data/spec/lib/git_reflow/workflows/flat_merge_spec.rb +17 -6
  56. data/spec/lib/git_reflow_spec.rb +2 -25
  57. data/spec/spec_helper.rb +3 -0
  58. data/spec/support/github_helpers.rb +1 -1
  59. data/spec/support/mock_pull_request.rb +17 -17
  60. data/spec/support/web_mocks.rb +39 -39
  61. metadata +9 -28
  62. data/lib/git_reflow/commands/deliver.rb +0 -10
  63. data/lib/git_reflow/commands/refresh.rb +0 -20
  64. data/lib/git_reflow/commands/review.rb +0 -13
  65. data/lib/git_reflow/commands/setup.rb +0 -11
  66. data/lib/git_reflow/commands/stage.rb +0 -9
  67. data/lib/git_reflow/commands/start.rb +0 -18
  68. data/lib/git_reflow/commands/status.rb +0 -7
  69. data/lib/git_reflow/workflows/flat_merge.rb +0 -10
  70. data/spec/fixtures/workflow_with_super.rb +0 -8
@@ -14,6 +14,20 @@ describe GitReflow::GitHelpers do
14
14
  stub_run_for Gitacular
15
15
  end
16
16
 
17
+ describe ".default_editor" do
18
+ subject { Gitacular.default_editor }
19
+
20
+ context "when the environment has EDITOR set" do
21
+ before { allow(ENV).to receive(:[]).with('EDITOR').and_return('emacs') }
22
+ specify { expect( subject ).to eql('emacs') }
23
+ end
24
+
25
+ context "when the environment has no EDITOR set" do
26
+ before { allow(ENV).to receive(:[]).with('EDITOR').and_return(nil) }
27
+ specify { expect( subject ).to eql('vi') }
28
+ end
29
+ end
30
+
17
31
  describe ".git_root_dir" do
18
32
  subject { Gitacular.git_root_dir }
19
33
  it { expect{ subject }.to have_run_command_silently "git rev-parse --show-toplevel" }
@@ -42,7 +56,7 @@ describe GitReflow::GitHelpers do
42
56
  it { is_expected.to eq('reenhanced.spectacular') }
43
57
 
44
58
  context "remote origin url isn't set" do
45
- let(:origin_url) { nil }
59
+ let(:origin_url) { '' }
46
60
  it { is_expected.to eq('') }
47
61
  end
48
62
 
@@ -58,7 +72,7 @@ describe GitReflow::GitHelpers do
58
72
  it { is_expected.to eq('this-is-the.shit') }
59
73
 
60
74
  context "remote origin url isn't set" do
61
- let(:origin_url) { nil }
75
+ let(:origin_url) { '' }
62
76
  it { is_expected.to eq('') }
63
77
  end
64
78
 
@@ -68,6 +82,16 @@ describe GitReflow::GitHelpers do
68
82
  end
69
83
  end
70
84
 
85
+ describe '.default_base_branch' do
86
+ subject { Gitacular.default_base_branch }
87
+ it { is_expected.to eq('master') }
88
+
89
+ context 'when configured' do
90
+ before { allow(GitReflow::Config).to receive(:get).with('reflow.base-branch').and_return('tuba') }
91
+ it { is_expected.to eq('tuba') }
92
+ end
93
+ end
94
+
71
95
  describe ".current_branch" do
72
96
  subject { Gitacular.current_branch }
73
97
  it { expect{ subject }.to have_run_command_silently "git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g'" }
@@ -97,6 +121,68 @@ describe GitReflow::GitHelpers do
97
121
  end
98
122
  end
99
123
 
124
+ describe ".pull_request_template" do
125
+ subject { Gitacular.pull_request_template }
126
+
127
+ context "template file exists" do
128
+ let(:root_dir) { "/some_repo" }
129
+ let(:template_content) { "Template content" }
130
+
131
+ before do
132
+ allow(Gitacular).to receive(:git_root_dir).and_return(root_dir)
133
+ allow(File).to receive(:exist?).with("#{root_dir}/.github/PULL_REQUEST_TEMPLATE.md").and_return(true)
134
+ allow(File).to receive(:read).with("#{root_dir}/.github/PULL_REQUEST_TEMPLATE.md").and_return(template_content)
135
+ end
136
+
137
+ it { is_expected.to eq template_content }
138
+
139
+ context "when template has mustache tags" do
140
+ let(:template_content) { "This is the coolest {{current_branch}}" }
141
+ before { allow(GitReflow).to receive(:current_branch).and_return("tomato") }
142
+ it { is_expected.to eq "This is the coolest tomato" }
143
+ end
144
+ end
145
+
146
+ context "template file does not exist" do
147
+ before do
148
+ allow(File).to receive(:exist?).and_return(false)
149
+ end
150
+
151
+ it { is_expected.to be_nil }
152
+ end
153
+ end
154
+
155
+ describe ".merge_commit_template" do
156
+ subject { Gitacular.merge_commit_template }
157
+
158
+ context "template file exists" do
159
+ let(:root_dir) { "/some_repo" }
160
+ let(:template_content) { "Template content" }
161
+
162
+ before do
163
+ allow(Gitacular).to receive(:git_root_dir).and_return(root_dir)
164
+ allow(File).to receive(:exist?).with("#{root_dir}/.github/MERGE_COMMIT_TEMPLATE.md").and_return(true)
165
+ allow(File).to receive(:read).with("#{root_dir}/.github/MERGE_COMMIT_TEMPLATE.md").and_return(template_content)
166
+ end
167
+
168
+ it { is_expected.to eq template_content }
169
+
170
+ context "when template has mustache tags" do
171
+ let(:template_content) { "This is the coolest {{current_branch}}" }
172
+ before { allow(GitReflow).to receive(:current_branch).and_return("tomato") }
173
+ it { is_expected.to eq "This is the coolest tomato" }
174
+ end
175
+ end
176
+
177
+ context "template file does not exist" do
178
+ before do
179
+ allow(File).to receive(:exist?).and_return(false)
180
+ end
181
+
182
+ it { is_expected.to be_nil }
183
+ end
184
+ end
185
+
100
186
  describe ".get_first_commit_message" do
101
187
  subject { Gitacular.get_first_commit_message }
102
188
  it { expect{ subject }.to have_run_command_silently 'git log --pretty=format:"%s" --no-merges -n 1' }
@@ -157,26 +243,43 @@ describe GitReflow::GitHelpers do
157
243
  end
158
244
  end
159
245
 
160
- describe ".append_to_squashed_commit_message(message)" do
161
- let(:original_squash_message) { "Oooooo, SQUASH IT" }
246
+ describe ".append_to_merge_commit_message(message)" do
247
+ let(:original_commit_message) { "Oooooo, SQUASH IT" }
162
248
  let(:message) { "do do the voodoo that you do" }
163
249
  let(:root_dir) { '/home/gitreflow' }
164
- let(:squash_path) { "#{root_dir}/.git/SQUASH_MSG" }
165
- let(:tmp_squash_path) { "#{root_dir}/.git/tmp_squash_msg" }
250
+ let(:merge_message_path) { "#{root_dir}/.git/SQUASH_MSG" }
251
+ let(:tmp_merge_message_path) { "#{root_dir}/.git/tmp_merge_msg" }
166
252
  before { allow(Gitacular).to receive(:git_root_dir).and_return(root_dir) }
167
- subject { Gitacular.append_to_squashed_commit_message(message) }
253
+ subject { Gitacular.append_to_merge_commit_message(message) }
168
254
 
169
255
  it "appends the message to git's SQUASH_MSG temp file" do
170
256
  tmp_file = double('file')
171
- allow(File).to receive(:open).with(tmp_squash_path, "w").and_yield(tmp_file)
172
- allow(File).to receive(:exists?).with(squash_path).and_return(true)
173
- allow(File).to receive(:foreach).with(squash_path).and_yield(original_squash_message)
257
+ allow(File).to receive(:open).with(tmp_merge_message_path, "w").and_yield(tmp_file)
258
+ allow(File).to receive(:exists?).with(merge_message_path).and_return(true)
259
+ allow(File).to receive(:foreach).with(merge_message_path).and_yield(original_commit_message)
174
260
  expect(tmp_file).to receive(:puts).with(message)
175
- expect(tmp_file).to receive(:puts).with(original_squash_message)
261
+ expect(tmp_file).to receive(:puts).with(original_commit_message)
176
262
 
177
263
  expect { subject }.to have_run_commands_in_order [
178
- "mv #{tmp_squash_path} #{squash_path}"
264
+ "mv #{tmp_merge_message_path} #{merge_message_path}"
179
265
  ]
180
266
  end
267
+
268
+ context "when doing a direct merge" do
269
+ let(:merge_message_path) { "#{root_dir}/.git/MERGE_MSG" }
270
+ subject { Gitacular.append_to_merge_commit_message(message, merge_method: "merge") }
271
+ it "appends the message to git's MERGE_MSG temp file if using a direct merge" do
272
+ tmp_file = double('file')
273
+ allow(File).to receive(:open).with(tmp_merge_message_path, "w").and_yield(tmp_file)
274
+ allow(File).to receive(:exists?).with(merge_message_path).and_return(true)
275
+ allow(File).to receive(:foreach).with(merge_message_path).and_yield(original_commit_message)
276
+ expect(tmp_file).to receive(:puts).with(message)
277
+ expect(tmp_file).to receive(:puts).with(original_commit_message)
278
+
279
+ expect { subject }.to have_run_commands_in_order [
280
+ "mv #{tmp_merge_message_path} #{merge_message_path}"
281
+ ]
282
+ end
283
+ end
181
284
  end
182
285
  end
@@ -86,21 +86,21 @@ describe GitReflow::GitServer::GitHub::PullRequest do
86
86
  pull_request: {
87
87
  number: existing_pull_request.number,
88
88
  comments: [{author: comment_author}],
89
- reviews: []
89
+ reviews: [{author: existing_pull_request.user.login}]
90
90
  },
91
91
  issue: {
92
92
  number: existing_pull_request.number,
93
- comments: [{author: comment_author}]
93
+ comments: [{author: comment_author}, {author: existing_pull_request.user.login}]
94
94
  }
95
95
  )
96
96
  end
97
- specify { expect(subject).to eql(existing_pull_comments.to_a + existing_issue_comments.to_a) }
97
+ specify { expect(subject).to eql(existing_pull_comments.to_a + existing_issue_comments.to_a - [existing_pull_request.user.login]) }
98
98
  end
99
99
 
100
100
  context "Testing Nil Comments" do
101
101
  before do
102
102
  stub_request(:get, "https://api.github.com/repos/reenhanced/repo/pulls/2/comments?access_token=a1b2c3d4e5f6g7h8i9j0").
103
- with(:headers => {'Accept'=>'application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1', 'Accept-Charset'=>'utf-8', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'token a1b2c3d4e5f6g7h8i9j0', 'User-Agent'=>'Github API Ruby Gem 0.15.0'}).
103
+ with(:headers => {'Accept'=>'application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1', 'Accept-Charset'=>'utf-8', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'token a1b2c3d4e5f6g7h8i9j0', 'User-Agent'=>'Github API Ruby Gem 0.18.2'}).
104
104
  to_return(:status => 200, :body => "", :headers => {})
105
105
 
106
106
  FakeGitHub.new(
@@ -133,7 +133,7 @@ describe GitReflow::GitServer::GitHub::PullRequest do
133
133
  number: existing_pull_request.number,
134
134
  owner: existing_pull_request.user.login,
135
135
  comments: [{author: 'tito'}, {author: 'bobby'}, {author: 'ringo'}],
136
- reviews: [{author: 'nature-boy'}]
136
+ reviews: [{author: 'ringo'}, {author: 'nature-boy'}]
137
137
  },
138
138
  issue: {
139
139
  number: existing_pull_request.number,
@@ -484,7 +484,7 @@ describe GitReflow::GitServer::GitHub::PullRequest do
484
484
  allow(GitReflow.git_server).to receive(:connection).and_return(github_api)
485
485
  allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
486
486
  allow_any_instance_of(GitReflow::GitServer::PullRequest).to receive(:commit_message_for_merge).and_return('Bingo')
487
- allow_any_instance_of(GitReflow).to receive(:append_to_squashed_commit_message).and_return(true)
487
+ allow_any_instance_of(GitReflow).to receive(:append_to_merge_commit_message).and_return(true)
488
488
  end
489
489
 
490
490
  context "and force-merging" do
@@ -364,7 +364,7 @@ describe GitReflow::GitServer::PullRequest do
364
364
  subject { pr.merge! inputs }
365
365
 
366
366
  before do
367
- allow(GitReflow).to receive(:append_to_squashed_commit_message)
367
+ allow(GitReflow).to receive(:append_to_merge_commit_message)
368
368
  allow(pr).to receive(:commit_message_for_merge).and_return(commit_message_for_merge)
369
369
  end
370
370
 
@@ -376,7 +376,7 @@ describe GitReflow::GitServer::PullRequest do
376
376
  it "updates both feature and destination branch and squash-merges feature into base branch" do
377
377
  expect(GitReflow).to receive(:update_current_branch)
378
378
  expect(GitReflow).to receive(:fetch_destination).with(pr.base_branch_name)
379
- expect(GitReflow).to receive(:append_to_squashed_commit_message).with(pr.commit_message_for_merge)
379
+ expect(GitReflow).to receive(:append_to_merge_commit_message).with(pr.commit_message_for_merge)
380
380
  expect { subject }.to have_run_commands_in_order [
381
381
  "git checkout #{pr.base_branch_name}",
382
382
  "git pull origin #{pr.base_branch_name}",
@@ -470,6 +470,12 @@ describe GitReflow::GitServer::PullRequest do
470
470
  before { allow(pr).to receive(:approvals).and_return(['sally', 'joey']) }
471
471
  specify { expect(subject).to include "\nLGTM given by: @sally, @joey\n" }
472
472
  end
473
+
474
+ context "with custom merge commit message template" do
475
+ before { allow(GitReflow).to receive(:merge_commit_template).and_return("Super cool changes") }
476
+ specify { expect(subject).to include "Super cool changes" }
477
+ specify { expect(subject).to_not include "\nMerges ##{pr.number}\n" }
478
+ end
473
479
  end
474
480
 
475
481
  context "#cleanup_feature_branch?" do
@@ -490,7 +496,7 @@ describe GitReflow::GitServer::PullRequest do
490
496
  it { should be_truthy }
491
497
  end
492
498
 
493
- context "and user choose not to cleanup" do
499
+ context "and user chooses not to cleanup" do
494
500
  before { expect(pr).to receive(:ask).with('Would you like to push this branch to your remote repo and cleanup your feature branch? ').and_return('no') }
495
501
  it { should be_falsy }
496
502
  end
@@ -12,16 +12,153 @@ describe GitReflow::Workflow do
12
12
  describe ".current" do
13
13
  subject { GitReflow::Workflow.current }
14
14
 
15
+ before do
16
+ allow(GitReflow::Workflows::Core).to receive(:load_raw_workflow)
17
+ end
18
+
15
19
  context "when no workflow is set" do
16
20
  before { allow(GitReflow::Config).to receive(:get).with("reflow.workflow").and_return('') }
17
21
  specify { expect( subject ).to eql(GitReflow::Workflows::Core) }
18
22
  end
19
23
 
20
- context "when a workflow is set" do
24
+ context "when a global workflow is set" do
21
25
  let(:workflow_path) { File.join(File.expand_path("../../../fixtures", __FILE__), "/awesome_workflow.rb") }
22
26
 
23
27
  before { allow(GitReflow::Config).to receive(:get).with("reflow.workflow").and_return(workflow_path) }
24
- specify { expect( subject ).to eql(GitReflow::Workflow::AwesomeWorkflow) }
28
+ specify { expect( subject ).to eql(GitReflow::Workflows::Core) }
29
+ end
30
+
31
+ context "when a local workflow is set" do
32
+ let(:workflow_content) do
33
+ <<~WORKFLOW_CONTENT
34
+ command :dummy do
35
+ GitReflow.say "derp"
36
+ end
37
+ WORKFLOW_CONTENT
38
+ end
39
+
40
+ before do
41
+ allow(File).to receive(:exists?).with("#{GitReflow.git_root_dir}/Workflow").and_return(true)
42
+ allow(File).to receive(:read).with("#{GitReflow.git_root_dir}/Workflow").and_return(workflow_content)
43
+ expect(GitReflow::Workflows::Core).to receive(:load_raw_workflow).with(workflow_content).and_call_original
44
+ end
45
+
46
+ specify { expect( subject ).to respond_to(:dummy) }
47
+ specify { expect( subject ).to eql(GitReflow::Workflows::Core) }
48
+ end
49
+
50
+ context "when both a local and a global workflow are set" do
51
+ let(:workflow_path) { File.join(File.expand_path("../../../fixtures", __FILE__), "/awesome_workflow.rb") }
52
+ let(:workflow_content) do
53
+ <<~WORKFLOW_CONTENT
54
+ command :dummy do
55
+ GitReflow.say "derp"
56
+ end
57
+ WORKFLOW_CONTENT
58
+ end
59
+
60
+ before do
61
+ allow(File).to receive(:exists?).with("#{GitReflow.git_root_dir}/Workflow").and_return(true)
62
+ allow(File).to receive(:read).with("#{GitReflow.git_root_dir}/Workflow").and_return(workflow_content)
63
+ allow(GitReflow::Config).to receive(:get).with("reflow.workflow").and_return(workflow_path)
64
+ allow(GitReflow::Workflows::Core).to receive(:load_raw_workflow).and_call_original
65
+ end
66
+
67
+ specify { expect(subject).to respond_to(:dummy) }
68
+ specify { expect(subject).to eql(GitReflow::Workflows::Core) }
69
+ end
70
+ end
71
+
72
+ describe ".before" do
73
+ it "executes the block before the command" do
74
+ GitReflow::Workflows::Core.load_raw_workflow <<~WORKFLOW_CONTENT
75
+ command :yips do
76
+ puts "Yips."
77
+ end
78
+
79
+ before :yips do
80
+ puts "Would you like a donut?"
81
+ end
82
+ WORKFLOW_CONTENT
83
+
84
+ allow(GitReflow::Workflows::Core).to receive(:load_workflow).and_return(true)
85
+
86
+ expect { GitReflow.workflow.yips }.to have_output "Would you like a donut?\nYips."
87
+ end
88
+
89
+ it "executes blocks sequentially by order of appearance" do
90
+ GitReflow::Workflows::Core.load_raw_workflow <<~WORKFLOW_CONTENT
91
+ command :yips do
92
+ puts "Yips."
93
+ end
94
+
95
+ before :yips do
96
+ puts "Cupcake?"
97
+ end
98
+
99
+ before :yips do
100
+ puts "Would you like a donut?"
101
+ end
102
+ WORKFLOW_CONTENT
103
+
104
+ allow(GitReflow::Workflows::Core).to receive(:load_workflow).and_return(true)
105
+
106
+ expect { GitReflow.workflow.yips }.to have_output "Cupcake?\nWould you like a donut?\nYips."
107
+ end
108
+
109
+ it "proxies any arguments returned to the command" do
110
+ GitReflow::Workflows::Core.load_raw_workflow <<~WORKFLOW_CONTENT
111
+ command :yips, arguments: { spiced: false } do |**params|
112
+ puts params[:spiced] ? "Too spicy." : "Yips."
113
+ end
114
+
115
+ before :yips do
116
+ puts "Wasabe?"
117
+ { spiced: true }
118
+ end
119
+ WORKFLOW_CONTENT
120
+
121
+ allow(GitReflow::Workflows::Core).to receive(:load_workflow).and_return(true)
122
+
123
+ expect { GitReflow.workflow.yips }.to have_output "Wasabe?\nToo spicy."
124
+ end
125
+ end
126
+
127
+ describe ".after" do
128
+ it "executes the block after the command" do
129
+ GitReflow::Workflows::Core.load_raw_workflow <<~WORKFLOW_CONTENT
130
+ command :vroom do
131
+ puts "Vroom"
132
+ end
133
+
134
+ after :vroom do
135
+ puts "VROOOOM"
136
+ end
137
+ WORKFLOW_CONTENT
138
+
139
+ allow(GitReflow::Workflows::Core).to receive(:load_workflow).and_return(true)
140
+
141
+ expect { GitReflow.workflow.vroom }.to have_output "Vroom\nVROOOOM"
142
+ end
143
+
144
+ it "executes blocks sequentially by order of appearance" do
145
+ GitReflow::Workflows::Core.load_raw_workflow <<~WORKFLOW_CONTENT
146
+ command :vroom do
147
+ puts "Vroom"
148
+ end
149
+
150
+ after :vroom do
151
+ puts "Vrooom"
152
+ end
153
+
154
+ after :vroom do
155
+ puts "VROOOOM"
156
+ end
157
+ WORKFLOW_CONTENT
158
+
159
+ allow(GitReflow::Workflows::Core).to receive(:load_workflow).and_return(true)
160
+
161
+ expect { GitReflow.workflow.vroom }.to have_output "Vroom\nVrooom\nVROOOOM"
25
162
  end
26
163
  end
27
164
 
@@ -31,28 +168,70 @@ describe GitReflow::Workflow do
31
168
  include GitReflow::Workflow
32
169
  end
33
170
  workflow.command :bogus do
34
- "Woohoo"
171
+ GitReflow.say "Woohoo"
35
172
  end
36
173
 
37
- expect(DummyWorkflow.bogus).to eql("Woohoo")
174
+ expect { DummyWorkflow.bogus }.to have_said("Woohoo")
38
175
  end
39
176
 
40
177
  it "creates a method for a bogus command with arguments" do
41
- workflow.command :bogus, arguments: [:feature_branch] do |**params|
42
- "Woohoo #{params[:feature_branch]}!"
178
+ workflow.command :bogus, arguments: { feature_branch: nil } do |**params|
179
+ GitReflow.say "Woohoo #{params[:feature_branch]}!"
43
180
  end
44
181
 
45
- expect(DummyWorkflow.bogus(feature_branch: "donuts")).to eql("Woohoo donuts!")
182
+ expect { DummyWorkflow.bogus(feature_branch: "arguments") }.to have_said("Woohoo arguments!")
46
183
  end
47
184
 
48
- it "creates a class method for a bogus command with default options" do
49
- workflow.command :bogus, arguments: [:feature_branch], defaults: {decoration: 'sprinkles'} do |**params|
185
+ it "creates a class method for a bogus command with default arguments" do
186
+ workflow.command :bogus, arguments: { feature_branch: nil, decoration: "sprinkles" } do |**params|
50
187
  donut_excitement = "Woohoo #{params[:feature_branch]}"
51
188
  donut_excitement += " with #{params[:decoration]}" if params[:decoration]
52
- "#{donut_excitement}!"
189
+ GitReflow.say "#{donut_excitement}!"
190
+ end
191
+
192
+ expect { DummyWorkflow.bogus(feature_branch: "donuts") }.to have_said("Woohoo donuts with sprinkles!")
193
+ end
194
+
195
+ it "creates a class method for a bogus command with flags" do
196
+ workflow.command :bogus, flags: { feature_branch: nil } do |**params|
197
+ GitReflow.say "Woohoo #{params[:feature_branch]}!"
198
+ end
199
+
200
+ expect { DummyWorkflow.bogus(feature_branch: "flags") }.to have_said("Woohoo flags!")
201
+ end
202
+
203
+ it "creates a class method for a bogus command with default flags" do
204
+ workflow.command :bogus, flags: { feature_branch: "donuts" } do |**params|
205
+ GitReflow.say "Woohoo #{params[:feature_branch]}!"
206
+ end
207
+
208
+ expect { DummyWorkflow.bogus }.to have_said("Woohoo donuts!")
209
+ end
210
+
211
+ it "creates a class method for a bogus command with switches" do
212
+ workflow.command :bogus, switches: { feature_branch: nil } do |**params|
213
+ GitReflow.say "Woohoo #{params[:feature_branch]}!"
214
+ end
215
+
216
+ expect { DummyWorkflow.bogus(feature_branch: "switches") }.to have_said("Woohoo switches!")
217
+ end
218
+
219
+ it "creates a class method for a bogus command with default switches" do
220
+ workflow.command :bogus, switches: { feature_branch: "donuts" } do |**params|
221
+ GitReflow.say "Woohoo #{params[:feature_branch]}!"
53
222
  end
54
223
 
55
- expect(DummyWorkflow.bogus(feature_branch: "donuts")).to eql("Woohoo donuts with sprinkles!")
224
+ expect { DummyWorkflow.bogus }.to have_said("Woohoo donuts!")
225
+ end
226
+ end
227
+
228
+ describe ".use(workflow_name)" do
229
+ it "Uses a pre-existing workflow as a basis" do
230
+ allow(GitReflow::Workflows::Core).to receive(:load_workflow)
231
+ expect(GitReflow::Workflows::Core).to receive(:load_workflow)
232
+ .with(workflow.workflows["FlatMergeWorkflow"])
233
+ .and_return(true)
234
+ workflow.use "FlatMergeWorkflow"
56
235
  end
57
236
  end
58
237