zenflow 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.zenflow +10 -0
  7. data/CHANGELOG.md +0 -0
  8. data/Gemfile +3 -0
  9. data/Gemfile.lock +95 -0
  10. data/Guardfile +6 -0
  11. data/LICENSE.md +22 -0
  12. data/README.markdown +92 -0
  13. data/VERSION.yml +5 -0
  14. data/bin/zenflow +17 -0
  15. data/lib/zenflow.rb +35 -0
  16. data/lib/zenflow/cli.rb +130 -0
  17. data/lib/zenflow/commands/deploy.rb +33 -0
  18. data/lib/zenflow/commands/feature.rb +10 -0
  19. data/lib/zenflow/commands/hotfix.rb +15 -0
  20. data/lib/zenflow/commands/release.rb +16 -0
  21. data/lib/zenflow/commands/reviews.rb +12 -0
  22. data/lib/zenflow/helpers/ask.rb +66 -0
  23. data/lib/zenflow/helpers/branch.rb +80 -0
  24. data/lib/zenflow/helpers/branch_command.rb +95 -0
  25. data/lib/zenflow/helpers/branch_commands/abort.rb +21 -0
  26. data/lib/zenflow/helpers/branch_commands/branches.rb +21 -0
  27. data/lib/zenflow/helpers/branch_commands/compare.rb +20 -0
  28. data/lib/zenflow/helpers/branch_commands/deploy.rb +29 -0
  29. data/lib/zenflow/helpers/branch_commands/diff.rb +19 -0
  30. data/lib/zenflow/helpers/branch_commands/finish.rb +68 -0
  31. data/lib/zenflow/helpers/branch_commands/review.rb +58 -0
  32. data/lib/zenflow/helpers/branch_commands/start.rb +39 -0
  33. data/lib/zenflow/helpers/branch_commands/update.rb +22 -0
  34. data/lib/zenflow/helpers/changelog.rb +100 -0
  35. data/lib/zenflow/helpers/config.rb +36 -0
  36. data/lib/zenflow/helpers/github.rb +40 -0
  37. data/lib/zenflow/helpers/help.rb +37 -0
  38. data/lib/zenflow/helpers/log.rb +21 -0
  39. data/lib/zenflow/helpers/pull_request.rb +68 -0
  40. data/lib/zenflow/helpers/repo.rb +13 -0
  41. data/lib/zenflow/helpers/shell.rb +89 -0
  42. data/lib/zenflow/helpers/version.rb +87 -0
  43. data/lib/zenflow/version.rb +3 -0
  44. data/spec/fixtures/VERSION.yml +5 -0
  45. data/spec/fixtures/cassettes/create_bad_pull_request.yml +57 -0
  46. data/spec/fixtures/cassettes/create_pull_request.yml +68 -0
  47. data/spec/fixtures/cassettes/existing_pull_request.yml +145 -0
  48. data/spec/fixtures/cassettes/pull_request_by_ref.yml +145 -0
  49. data/spec/fixtures/cassettes/pull_request_find.yml +70 -0
  50. data/spec/fixtures/cassettes/pull_request_for_non-existent_ref.yml +145 -0
  51. data/spec/fixtures/cassettes/pull_request_list.yml +74 -0
  52. data/spec/fixtures/cassettes/unexisting_pull_request.yml +145 -0
  53. data/spec/spec_helper.rb +36 -0
  54. data/spec/support/shared_examples_for_version_number.rb +19 -0
  55. data/spec/zenflow/commands/deploy_spec.rb +48 -0
  56. data/spec/zenflow/commands/feature_spec.rb +11 -0
  57. data/spec/zenflow/commands/hotfix_spec.rb +14 -0
  58. data/spec/zenflow/commands/release_spec.rb +15 -0
  59. data/spec/zenflow/commands/reviews_spec.rb +15 -0
  60. data/spec/zenflow/helpers/ask_spec.rb +115 -0
  61. data/spec/zenflow/helpers/branch_command_spec.rb +310 -0
  62. data/spec/zenflow/helpers/branch_spec.rb +300 -0
  63. data/spec/zenflow/helpers/changelog_spec.rb +188 -0
  64. data/spec/zenflow/helpers/cli_spec.rb +277 -0
  65. data/spec/zenflow/helpers/github_spec.rb +45 -0
  66. data/spec/zenflow/helpers/help_spec.rb +36 -0
  67. data/spec/zenflow/helpers/log_spec.rb +31 -0
  68. data/spec/zenflow/helpers/pull_request_spec.rb +108 -0
  69. data/spec/zenflow/helpers/shell_spec.rb +135 -0
  70. data/spec/zenflow/helpers/version_spec.rb +111 -0
  71. data/zenflow.gemspec +33 -0
  72. metadata +273 -0
@@ -0,0 +1,300 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zenflow::Branch do
4
+ describe 'self.list' do
5
+ context "when the prefix has no branches" do
6
+ before do
7
+ Zenflow::Shell.should_receive(:run).with("git branch | grep features", :silent => true).and_return("")
8
+ end
9
+
10
+ it "indicates there are no branches" do
11
+ expect(Zenflow::Branch.list('features')).to eq(['!! NONE !!'])
12
+ end
13
+ end
14
+
15
+ context "when the prefix has branches" do
16
+ before do
17
+ Zenflow::Shell.should_receive(:run).with("git branch | grep features", :silent => true).and_return(" feature/test_zenflow\n* feature/refactor_zenflow\n")
18
+ end
19
+
20
+ it "indicates there are no branches" do
21
+ expect(Zenflow::Branch.list('features')).to eq([" feature/test_zenflow", "* feature/refactor_zenflow"])
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "self.current" do
27
+ context "when the current branch doesn't match the prefix" do
28
+ before do
29
+ Zenflow::Shell.should_receive(:run).with("git branch | grep '* feature'", :silent => true).and_return("")
30
+ end
31
+
32
+ it "returns nil" do
33
+ expect(Zenflow::Branch.current('feature')).to be_nil
34
+ end
35
+ end
36
+
37
+ context "when the current branch matches the prefix" do
38
+ before do
39
+ Zenflow::Shell.should_receive(:run).with("git branch | grep '* feature'", :silent => true).and_return("* feature/test-current-branch\n")
40
+ end
41
+
42
+ it "returns returns the branch name" do
43
+ expect(Zenflow::Branch.current('feature')).to eq('test-current-branch')
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "self.update" do
49
+ it "updates the branch" do
50
+ Zenflow.should_receive(:Log).with("Updating the master branch")
51
+ Zenflow::Shell.should_receive(:run).with("git checkout master && git pull")
52
+ Zenflow::Branch.update('master')
53
+ end
54
+ end
55
+
56
+ describe "self.create" do
57
+ it "updates the branch" do
58
+ Zenflow.should_receive(:Log).with("Creating the feature/test-branch-creation branch based on master")
59
+ Zenflow::Shell.should_receive(:run).with("git checkout -b feature/test-branch-creation master")
60
+ Zenflow::Branch.create('feature/test-branch-creation', 'master')
61
+ end
62
+ end
63
+
64
+ describe "self.push" do
65
+ after(:each) do
66
+ Zenflow::Config[:remote] = 'origin'
67
+ Zenflow::Config[:backup_remote] = false
68
+ end
69
+
70
+ context "when a remote is configured" do
71
+ before do
72
+ Zenflow::Config[:remote] = 'some-remote'
73
+ end
74
+
75
+ it 'pushes to the configured remote' do
76
+ Zenflow.should_receive(:Log).with("Pushing the feature/test-pushing branch to some-remote")
77
+ Zenflow::Shell.should_receive(:run).with("git push some-remote feature/test-pushing")
78
+ Zenflow::Branch.push('feature/test-pushing')
79
+ end
80
+ end
81
+
82
+ context "when a remote is not configured" do
83
+ it 'pushes to the origin' do
84
+ Zenflow.should_receive(:Log).with("Pushing the feature/test-pushing branch to origin")
85
+ Zenflow::Shell.should_receive(:run).with("git push origin feature/test-pushing")
86
+ Zenflow::Branch.push('feature/test-pushing')
87
+ end
88
+ end
89
+
90
+ context "when a backup remote is not configured" do
91
+ it "pushes to the primary remote and then pushes to the backup remote" do
92
+ Zenflow.should_receive(:Log).with("Pushing the feature/test-pushing branch to origin")
93
+ Zenflow::Shell.should_receive(:run).with("git push origin feature/test-pushing")
94
+ Zenflow.should_not_receive(:Log).with("Pushing the feature/test-pushing branch to backup-remote")
95
+ Zenflow::Shell.should_not_receive(:run).with("git push backup-remote feature/test-pushing")
96
+ Zenflow::Branch.push('feature/test-pushing')
97
+ end
98
+ end
99
+
100
+ context "when a backup remote is configured" do
101
+ before do
102
+ Zenflow::Config[:backup_remote] = 'backup-remote'
103
+ end
104
+
105
+ it "pushes to the primary remote and then pushes to the backup remote" do
106
+ Zenflow.should_receive(:Log).with("Pushing the feature/test-pushing branch to origin")
107
+ Zenflow::Shell.should_receive(:run).with("git push origin feature/test-pushing")
108
+ Zenflow.should_receive(:Log).with("Pushing the feature/test-pushing branch to backup-remote")
109
+ Zenflow::Shell.should_receive(:run).with("git push backup-remote feature/test-pushing")
110
+ Zenflow::Branch.push('feature/test-pushing')
111
+ end
112
+ end
113
+ end
114
+
115
+ describe "self.push_tags" do
116
+ after(:each) do
117
+ Zenflow::Config[:remote] = 'origin'
118
+ Zenflow::Config[:backup_remote] = false
119
+ end
120
+
121
+ context "when a remote is configured" do
122
+ before do
123
+ Zenflow::Config[:remote] = 'some-remote'
124
+ end
125
+
126
+ it 'pushes to the configured remote' do
127
+ Zenflow.should_receive(:Log).with("Pushing tags to some-remote")
128
+ Zenflow::Shell.should_receive(:run).with("git push some-remote --tags")
129
+ Zenflow::Branch.push_tags
130
+ end
131
+ end
132
+
133
+ context "when a remote is not configured" do
134
+ it 'pushes to the origin' do
135
+ Zenflow.should_receive(:Log).with("Pushing tags to origin")
136
+ Zenflow::Shell.should_receive(:run).with("git push origin --tags")
137
+ Zenflow::Branch.push_tags
138
+ end
139
+ end
140
+
141
+ context "when a backup remote is not configured" do
142
+ it "pushes to the primary remote and then pushes to the backup remote" do
143
+ Zenflow.should_receive(:Log).with("Pushing tags to origin")
144
+ Zenflow::Shell.should_receive(:run).with("git push origin --tags")
145
+ Zenflow.should_not_receive(:Log).with("Pushing tags to backup-remote")
146
+ Zenflow::Shell.should_not_receive(:run).with("git push backup-remote --tags")
147
+ Zenflow::Branch.push_tags
148
+ end
149
+ end
150
+
151
+ context "when a backup remote is configured" do
152
+ before do
153
+ Zenflow::Config[:backup_remote] = 'backup-remote'
154
+ end
155
+
156
+ it "pushes to the primary remote and then pushes to the backup remote" do
157
+ Zenflow.should_receive(:Log).with("Pushing tags to origin")
158
+ Zenflow::Shell.should_receive(:run).with("git push origin --tags")
159
+ Zenflow.should_receive(:Log).with("Pushing tags to backup-remote")
160
+ Zenflow::Shell.should_receive(:run).with("git push backup-remote --tags")
161
+ Zenflow::Branch.push_tags
162
+ end
163
+ end
164
+ end
165
+
166
+ describe "self.track" do
167
+ after(:each) do
168
+ Zenflow::Config[:remote] = 'origin'
169
+ end
170
+
171
+ context "when a remote is configured" do
172
+ before do
173
+ Zenflow::Config[:remote] = 'some-remote'
174
+ end
175
+
176
+ it "tracks the branch in that remote" do
177
+ Zenflow.should_receive(:Log).with("Tracking the feature/test-tracking branch against some-remote/feature/test-tracking")
178
+ Zenflow::Shell.should_receive(:run).with("git branch --set-upstream-to=some-remote/feature/test-tracking feature/test-tracking")
179
+ Zenflow::Branch.track('feature/test-tracking')
180
+ end
181
+ end
182
+
183
+ context "when a remote is not configured" do
184
+ before do
185
+ Zenflow::Config[:remote] = nil
186
+ end
187
+
188
+ it "tracks the branch in origin" do
189
+ Zenflow.should_receive(:Log).with("Tracking the feature/test-tracking branch against origin/feature/test-tracking")
190
+ Zenflow::Shell.should_receive(:run).with("git branch --set-upstream-to=origin/feature/test-tracking feature/test-tracking")
191
+ Zenflow::Branch.track('feature/test-tracking')
192
+ end
193
+ end
194
+ end
195
+
196
+ describe "self.checkout" do
197
+ it "checks out the branch" do
198
+ Zenflow.should_receive(:Log).with("Switching to the feature/test-checkout branch")
199
+ Zenflow::Shell.should_receive(:run).with("git checkout feature/test-checkout")
200
+ Zenflow::Branch.checkout('feature/test-checkout')
201
+ end
202
+ end
203
+
204
+ describe "self.merge" do
205
+ it "merges in the specified branch" do
206
+ Zenflow.should_receive(:Log).with("Merging in the feature/test-merging branch")
207
+ Zenflow::Shell.should_receive(:run).with("git merge --no-ff feature/test-merging")
208
+ Zenflow::Branch.merge('feature/test-merging')
209
+ end
210
+ end
211
+
212
+ describe "self.tag" do
213
+ context "when name and description are specified" do
214
+ it "creates a tag with the name and description" do
215
+ Zenflow.should_receive(:Log).with("Tagging the release")
216
+ Zenflow::Shell.should_receive(:run).with("git tag -a 'v0.1.2' -m 'this tag is amazing'")
217
+ Zenflow::Branch.tag('v0.1.2', 'this tag is amazing')
218
+ end
219
+ end
220
+
221
+ context "when name and description are not specified" do
222
+ it "asks for name and description and then creates a tag" do
223
+ Zenflow.should_receive(:Log).with("Tagging the release")
224
+ Zenflow.should_receive(:Ask).with('Name of the tag:', :required => true).and_return('v0.1.3')
225
+ Zenflow.should_receive(:Ask).with('Tag message:', :required => true).and_return('this tag is even more amazing')
226
+ Zenflow::Shell.should_receive(:run).with("git tag -a 'v0.1.3' -m 'this tag is even more amazing'")
227
+ Zenflow::Branch.tag
228
+ end
229
+ end
230
+ end
231
+
232
+ describe "self.delete_remote" do
233
+ after(:each) do
234
+ Zenflow::Config[:remote] = 'origin'
235
+ Zenflow::Config[:backup_remote] = false
236
+ end
237
+
238
+ context "when a remote is configured" do
239
+ before do
240
+ Zenflow::Config[:remote] = 'some-remote'
241
+ end
242
+
243
+ it 'pushes to the configured remote' do
244
+ Zenflow.should_receive(:Log).with("Removing the remote branch from some-remote")
245
+ Zenflow::Shell.should_receive(:run).with("git branch -r | grep some-remote/feature/test-remote-removal && git push some-remote :feature/test-remote-removal || echo ''")
246
+ Zenflow::Branch.delete_remote('feature/test-remote-removal')
247
+ end
248
+ end
249
+
250
+ context "when a remote is not configured" do
251
+ it 'pushes to the origin' do
252
+ Zenflow.should_receive(:Log).with("Removing the remote branch from origin")
253
+ Zenflow::Shell.should_receive(:run).with("git branch -r | grep origin/feature/test-remote-removal && git push origin :feature/test-remote-removal || echo ''")
254
+ Zenflow::Branch.delete_remote('feature/test-remote-removal')
255
+ end
256
+ end
257
+
258
+ context "when a backup remote is not configured" do
259
+ it "pushes to the primary remote and then pushes to the backup remote" do
260
+ Zenflow.should_receive(:Log).with("Removing the remote branch from origin")
261
+ Zenflow::Shell.should_receive(:run).with("git branch -r | grep origin/feature/test-remote-removal && git push origin :feature/test-remote-removal || echo ''")
262
+ Zenflow.should_not_receive(:Log).with(/Removing the remote branch/)
263
+ Zenflow::Shell.should_not_receive(:run).with(/git push/)
264
+ Zenflow::Branch.delete_remote('feature/test-remote-removal')
265
+ end
266
+ end
267
+
268
+ context "when a backup remote is configured" do
269
+ before do
270
+ Zenflow::Config[:backup_remote] = 'backup-remote'
271
+ end
272
+
273
+ it "pushes to the primary remote and then pushes to the backup remote" do
274
+ Zenflow.should_receive(:Log).with("Removing the remote branch from origin")
275
+ Zenflow::Shell.should_receive(:run).with("git branch -r | grep origin/feature/test-remote-removal && git push origin :feature/test-remote-removal || echo ''")
276
+ Zenflow.should_receive(:Log).with("Removing the remote branch from backup-remote")
277
+ Zenflow::Shell.should_receive(:run).with("git branch -r | grep backup-remote/feature/test-remote-removal && git push backup-remote :feature/test-remote-removal || echo ''")
278
+ Zenflow::Branch.delete_remote('feature/test-remote-removal')
279
+ end
280
+ end
281
+ end
282
+
283
+ describe "self.delete_local" do
284
+ context "with the force option" do
285
+ it "force deletes the local branch" do
286
+ Zenflow.should_receive(:Log).with("Removing the local branch")
287
+ Zenflow::Shell.should_receive(:run).with("git branch -D feature/test-local-deletion")
288
+ Zenflow::Branch.delete_local('feature/test-local-deletion', :force => true)
289
+ end
290
+ end
291
+
292
+ context "without the force option" do
293
+ it "deletes the local branch" do
294
+ Zenflow.should_receive(:Log).with("Removing the local branch")
295
+ Zenflow::Shell.should_receive(:run).with("git branch -d feature/test-local-deletion")
296
+ Zenflow::Branch.delete_local('feature/test-local-deletion')
297
+ end
298
+ end
299
+ end
300
+ end
@@ -0,0 +1,188 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zenflow::Changelog do
4
+
5
+ describe '.update' do
6
+ context "when no changelog exists" do
7
+ before { File.should_receive(:exist?).with("CHANGELOG.md").and_return(false) }
8
+ it "does nothing" do
9
+ Zenflow::Changelog.should_not_receive(:prompt_for_change)
10
+ expect(Zenflow::Changelog.update).to be_nil
11
+ end
12
+ end
13
+
14
+ context "when the changelog exists" do
15
+ before { File.should_receive(:exist?).with("CHANGELOG.md").and_return(true) }
16
+
17
+ context "when a change is received" do
18
+ before { Zenflow::Changelog.should_receive(:prompt_for_change).and_return('wrote tests for updating the changelog') }
19
+
20
+ it "prepends the change to the changelog and returns the change" do
21
+ Zenflow::Changelog.should_receive(:prepend_change_to_changelog).with('wrote tests for updating the changelog', {})
22
+ expect(Zenflow::Changelog.update).to eq('wrote tests for updating the changelog')
23
+ end
24
+ end
25
+
26
+ context "when no change is received" do
27
+ before { Zenflow::Changelog.should_receive(:prompt_for_change).and_return(nil) }
28
+
29
+ context "and the rotate option is invoked" do
30
+ it "rotates the changelog and returns nil" do
31
+ Zenflow::Changelog.should_receive(:rotate).with(:commit => true)
32
+ expect(Zenflow::Changelog.update(:rotate => true)).to be_nil
33
+ end
34
+ end
35
+
36
+ context "and the rotate option is absent" do
37
+ it "rotates the changelog and returns nil" do
38
+ Zenflow::Changelog.should_not_receive(:rotate)
39
+ expect(Zenflow::Changelog.update).to be_nil
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '.prompt_for_change' do
47
+ context "when the required option is false" do
48
+ it "asks for a change and indicates it is optional" do
49
+ Zenflow.should_receive(:Ask).with("Add one line to the changelog (optional):", :required => false)
50
+ Zenflow::Changelog.prompt_for_change(:required => false)
51
+ end
52
+ end
53
+
54
+ context "when the required option is anything else" do
55
+ it "asks for a change and does not indicate is optional" do
56
+ Zenflow.should_receive(:Ask).with("Add one line to the changelog:", :required => true)
57
+ Zenflow::Changelog.prompt_for_change
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '.prepend_change_to_changelog' do
63
+ context "when the rotate option is not invoked" do
64
+ it "prepends changes to the changelog" do
65
+ Zenflow::Changelog.should_receive(:prepended_changelog).with('changed the world').and_return('some other text I suppose')
66
+ file_handler = double()
67
+ file_handler.should_receive(:write).with('some other text I suppose')
68
+ File.should_receive(:open).with("CHANGELOG.md", "w").and_yield(file_handler)
69
+ Zenflow::Changelog.should_not_receive(:rotate)
70
+ Zenflow::Shell.should_receive(:run).with("git add . && git commit -a -m 'Adding line to CHANGELOG: changed the world'")
71
+ Zenflow::Changelog.prepend_change_to_changelog('changed the world')
72
+ end
73
+ end
74
+
75
+ context "when the rotate option is present" do
76
+ it "prepends changes to the changelog" do
77
+ File.should_receive(:open).with("CHANGELOG.md", "w")
78
+ Zenflow::Changelog.should_receive(:rotate)
79
+ Zenflow::Shell.should_receive(:run).with("git add . && git commit -a -m 'Adding line to CHANGELOG: changed the world'")
80
+ Zenflow::Changelog.prepend_change_to_changelog('changed the world', :rotate => true)
81
+ end
82
+ end
83
+ end
84
+
85
+ describe '.prepended_changelog' do
86
+ it "returns the new changes prepended to the existing changelog" do
87
+ Zenflow::Changelog.should_receive(:get_changes).and_return(['test branching', 'amongst other things'])
88
+ expect(Zenflow::Changelog.prepended_changelog('test prepended changelog')).to eq("test prepended changelog\ntest branching\n--------------------------------------------------------------------------------\namongst other things\n")
89
+ end
90
+ end
91
+
92
+ describe '.rotate' do
93
+ context "when there are no changes to rotate" do
94
+ before { Zenflow::Changelog.should_receive(:rotated_changelog).and_return(nil) }
95
+
96
+ it "does nothing" do
97
+ File.should_not_receive(:open)
98
+ Zenflow::Changelog.rotate
99
+ end
100
+ end
101
+
102
+ context "when there are no changes to rotate" do
103
+ before { Zenflow::Changelog.should_receive(:rotated_changelog).and_return('amazing new changelog') }
104
+
105
+ context "when the commit option is not invoked" do
106
+ it "rotates the changelog but does not create a commit" do
107
+ Zenflow::Version.should_receive(:current)
108
+ Zenflow.should_receive(:Log)
109
+ file_handler = double()
110
+ file_handler.should_receive(:write).with('amazing new changelog')
111
+ File.should_receive(:open).with("CHANGELOG.md", "w").and_yield(file_handler)
112
+ Zenflow::Shell.should_not_receive(:run)
113
+ Zenflow::Changelog.rotate
114
+ end
115
+ end
116
+
117
+ context "when the commit option is present" do
118
+ it "rotates the changelog and creates a commit" do
119
+ Zenflow::Version.should_receive(:current)
120
+ Zenflow.should_receive(:Log)
121
+ file_handler = double()
122
+ file_handler.should_receive(:write).with('amazing new changelog')
123
+ File.should_receive(:open).with("CHANGELOG.md", "w").and_yield(file_handler)
124
+ Zenflow::Shell.should_receive(:run).with("git add CHANGELOG.md && git commit -a -m 'Rotating CHANGELOG.'")
125
+ Zenflow::Changelog.rotate(:commit => true)
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ describe '.rotated_changelog' do
132
+ it "returns the changelog with changes rotated to the bottom" do
133
+ Zenflow::Changelog.should_receive(:get_changes).and_return(['test branching', 'amongst other things'])
134
+ expect(Zenflow::Changelog.rotated_changelog).to eq("amongst other things\n\n---- #{Zenflow::Version.current.to_s} / #{Time.now.strftime('%Y-%m-%d')} --------------------------------------------------------\ntest branching\n")
135
+ end
136
+ end
137
+
138
+ describe '.get_changes' do
139
+ context "when the changelog file doesn't exist" do
140
+ before do
141
+ Zenflow::Changelog.should_receive(:exist?).and_return(false)
142
+ end
143
+
144
+ it 'does nothing' do
145
+ File.should_not_receive(:read)
146
+ expect(Zenflow::Changelog.get_changes).to be_nil
147
+ end
148
+ end
149
+
150
+ context "when the changelog exists" do
151
+ before do
152
+ Zenflow::Changelog.should_receive(:exist?).and_return(true)
153
+ end
154
+
155
+ context "but there are no changes" do
156
+ before do
157
+ file = "\n--------------------------------------------------------------------------------\nold changes"
158
+ File.should_receive(:read).with('CHANGELOG.md').and_return(file)
159
+ end
160
+
161
+ it 'returns nil' do
162
+ expect(Zenflow::Changelog.get_changes).to be_nil
163
+ end
164
+ end
165
+
166
+ context "and there are changes" do
167
+ before do
168
+ file = "new changes\n--------------------------------------------------------------------------------\nold changes"
169
+ File.should_receive(:read).with('CHANGELOG.md').and_return(file)
170
+ end
171
+
172
+ it "returns the new changes and the rest of the changelog" do
173
+ expect(Zenflow::Changelog.get_changes).to eq(["new changes", "--------------------------------------------------------------------------------\nold changes"])
174
+ end
175
+ end
176
+ end
177
+ end
178
+
179
+ describe '.create' do
180
+ it "writes the changelog template to the changelog" do
181
+ file = double()
182
+ file.should_receive(:write).with(Zenflow::Changelog.changelog_template)
183
+ File.should_receive(:open).with('CHANGELOG.md', 'w').and_yield(file)
184
+ Zenflow::Changelog.create
185
+ end
186
+ end
187
+
188
+ end