kumade 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/README.md +9 -1
  2. data/features/kumade_executable.feature +11 -12
  3. data/features/kumade_without_jammit.feature +2 -2
  4. data/kumade.gemspec +1 -0
  5. data/lib/kumade.rb +7 -1
  6. data/lib/kumade/cli.rb +4 -4
  7. data/lib/kumade/command_line.rb +33 -0
  8. data/lib/kumade/configuration.rb +13 -6
  9. data/lib/kumade/deployer.rb +9 -9
  10. data/lib/kumade/git.rb +25 -20
  11. data/lib/kumade/heroku.rb +18 -11
  12. data/lib/kumade/outputter.rb +21 -0
  13. data/lib/kumade/packager.rb +23 -76
  14. data/lib/kumade/packager_list.rb +29 -0
  15. data/lib/kumade/packagers/jammit_packager.rb +20 -0
  16. data/lib/kumade/packagers/more_packager.rb +20 -0
  17. data/lib/kumade/packagers/noop_packager.rb +14 -0
  18. data/lib/kumade/rake_task_runner.rb +29 -0
  19. data/lib/kumade/version.rb +1 -1
  20. data/spec/kumade/cli_spec.rb +5 -5
  21. data/spec/kumade/command_line_spec.rb +107 -0
  22. data/spec/kumade/configuration_spec.rb +15 -2
  23. data/spec/kumade/deployer_spec.rb +39 -25
  24. data/spec/kumade/git_spec.rb +168 -57
  25. data/spec/kumade/heroku_spec.rb +19 -25
  26. data/spec/kumade/outputter_spec.rb +50 -0
  27. data/spec/kumade/packager_list_spec.rb +31 -0
  28. data/spec/kumade/packager_spec.rb +66 -275
  29. data/spec/kumade/packagers/jammit_packager_spec.rb +27 -0
  30. data/spec/kumade/packagers/more_packager_spec.rb +37 -0
  31. data/spec/kumade/packagers/noop_packager_spec.rb +9 -0
  32. data/spec/kumade/rake_task_runner_spec.rb +75 -0
  33. data/spec/spec_helper.rb +13 -2
  34. data/spec/support/define_constant.rb +41 -0
  35. data/spec/support/environments.rb +32 -0
  36. data/spec/support/git.rb +5 -0
  37. data/spec/support/heroku.rb +6 -6
  38. data/spec/support/shared_examples/packager.rb +6 -0
  39. metadata +65 -28
  40. data/lib/kumade/base.rb +0 -35
  41. data/spec/kumade/base_spec.rb +0 -99
@@ -1,318 +1,109 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'jammit'
3
+ describe Kumade::Packager, ".available_packager", :with_mock_outputter do
4
+ let(:packager_1) { "1st packager" }
5
+ let(:packager_2) { "2nd packager" }
4
6
 
5
- shared_context "with a fake Git" do
6
- let(:git) { stub() }
7
- subject { Kumade::Packager.new(git) }
8
- end
9
-
10
- describe Kumade::Packager, "#run" do
11
- include_context "with a fake Git"
12
-
13
- before do
14
- subject.stubs(:package_with_jammit)
7
+ it "returns the first available packager" do
8
+ Kumade::PackagerList.stubs(:new => [packager_1, packager_2])
9
+ Kumade::Packager.available_packager.should == packager_1
15
10
  end
16
11
 
17
- context "with Jammit installed" do
18
- it "calls package_with_jammit" do
19
- subject.run
20
-
21
- subject.should have_received(:package_with_jammit)
22
- end
23
- end
24
-
25
- context "with Jammit not installed" do
26
- before { subject.stubs(:jammit_installed? => false) }
27
-
28
- it "does not call package_with_jammit" do
29
- subject.run
30
-
31
- subject.should_not have_received(:package_with_jammit)
32
- end
33
- end
34
-
35
- context "with More installed" do
36
- before do
37
- subject.stubs(:jammit_installed? => false)
38
- subject.stubs(:more_installed? => true)
39
- subject.stubs(:package_with_more)
40
- end
41
-
42
- it "calls package_with_more" do
43
- subject.run
44
-
45
- subject.should have_received(:package_with_more)
46
- end
47
- end
48
-
49
- context "with More not installed" do
50
- before do
51
- subject.stubs(:jammit_installed? => false)
52
- subject.stubs(:more_installed? => false)
53
- end
54
-
55
- it "does not call package_with_more" do
56
- subject.run
57
-
58
- subject.should_not have_received(:package_with_more)
59
- end
60
- end
61
-
62
- context "with custom rake task installed" do
63
- before do
64
- subject.stubs(:jammit_installed? => false,
65
- :more_installed? => false,
66
- :invoke_custom_task => nil,
67
- :custom_task? => true)
68
- end
69
-
70
- it "invokes custom task" do
71
- subject.run
72
-
73
- subject.should have_received(:invoke_custom_task)
74
- end
75
- end
76
-
77
- context "with custom rake task not installed" do
78
- before do
79
- subject.stubs(:jammit_installed? => false,
80
- :more_installed? => false,
81
- :invoke_custom_task => nil,
82
- :custom_task? => false)
83
- end
84
-
85
- it "does not invoke custom task" do
86
- subject.run
87
-
88
- subject.should_not have_received(:invoke_custom_task)
89
- end
12
+ it "returns nil if no packagers are availabke" do
13
+ Kumade::PackagerList.stubs(:new => [])
14
+ Kumade::Packager.available_packager.should be_nil
90
15
  end
91
16
  end
92
17
 
93
- describe Kumade::Packager, "#invoke_custom_task" do
94
- include_context "with a fake Git"
95
-
96
- let(:task) { stub('kumade:before_asset_compilation task', :invoke => nil) }
18
+ describe Kumade::Packager, "#run", :with_mock_outputter do
19
+ let(:git) { stub("git", :dirty? => true, :add_and_commit_all_assets_in => true) }
20
+ let(:packager) { stub("packager", :name => "MyPackager", :package => true, :assets_path => 'fake_assets_path') }
21
+ let(:rake_task_runner) { stub("RakeTaskRunner", :invoke => true) }
97
22
 
98
23
  before do
99
- subject.stubs(:say)
100
- Rake::Task.stubs(:[] => task)
24
+ Kumade::RakeTaskRunner.stubs(:new => rake_task_runner)
101
25
  end
102
26
 
103
- it "calls deploy task" do
104
- Rake::Task.expects(:[]).with("kumade:before_asset_compilation").returns(task)
105
-
106
- subject.invoke_custom_task
27
+ subject { Kumade::Packager.new(git, packager) }
107
28
 
108
- task.should have_received(:invoke)
29
+ it "precompiles assets" do
30
+ subject.run
31
+ Kumade::RakeTaskRunner.should have_received(:new).with("kumade:before_asset_compilation")
32
+ rake_task_runner.should have_received(:invoke)
109
33
  end
110
- end
111
34
 
112
- describe Kumade::Packager, "#custom_task?" do
113
- include_context "with a fake Git"
35
+ context "when packaging with a packager" do
36
+ context "when pretending" do
37
+ before do
38
+ Kumade.configuration.pretending = true
39
+ end
114
40
 
115
- before do
116
- Rake::Task.clear
117
- end
41
+ it "prints a success message" do
42
+ subject.run
43
+ Kumade.configuration.outputter.should have_received(:success).with("Packaged with MyPackager")
44
+ end
118
45
 
119
- it "returns true if it task found" do
120
- namespace :kumade do
121
- task :before_asset_compilation do
46
+ it "does not package" do
47
+ subject.run
48
+ packager.should have_received(:package).never
122
49
  end
123
50
  end
124
51
 
125
- subject.custom_task?.should be_true
126
- end
127
-
128
- it "returns false if task not found" do
129
- subject.custom_task?.should be_false
130
- end
131
- end
132
-
133
- describe Kumade::Packager, "#package_with_jammit" do
134
- include_context "with a fake Git"
135
-
136
- before do
137
- subject.stubs(:git_add_and_commit_all_assets_in)
138
- subject.stubs(:success)
139
- subject.stubs(:error)
140
- Jammit.stubs(:package!)
141
- end
142
-
143
- it "calls Jammit.package!" do
144
- subject.package_with_jammit
145
-
146
- Jammit.should have_received(:package!).once
147
- end
148
-
149
- context "with updated assets" do
150
- before { subject.git.stubs(:dirty? => true) }
151
-
152
- it "prints the correct message" do
153
- subject.package_with_jammit
52
+ context "when not pretending" do
53
+ before do
54
+ Kumade.configuration.pretending = false
55
+ end
154
56
 
155
- subject.should have_received(:success).with("Packaged assets with Jammit")
156
- end
57
+ it "prints a success message" do
58
+ subject.run
59
+ Kumade.configuration.outputter.should have_received(:success).with("Packaged with MyPackager")
60
+ end
157
61
 
158
- it "calls git_add_and_commit_all_assets_in" do
159
- subject.stubs(:jammit_assets_path => 'jammit-assets')
160
- subject.expects(:git_add_and_commit_all_assets_in).
161
- with('jammit-assets').
162
- returns(true)
62
+ it "packages" do
63
+ subject.run
64
+ packager.should have_received(:package).once
65
+ end
163
66
 
164
- subject.package_with_jammit
67
+ it "prints an error if an exception is raised" do
68
+ packager.stubs(:package).raises(RuntimeError.new("my specific error"))
69
+ subject.run
70
+ Kumade.configuration.outputter.should have_received(:error).with("Error: RuntimeError: my specific error")
71
+ end
165
72
  end
166
73
  end
167
74
 
168
- it "prints an error if packaging failed" do
169
- Jammit.expects(:package!).raises(Jammit::MissingConfiguration.new("random Jammit error"))
170
-
171
- subject.package_with_jammit
172
-
173
- subject.should have_received(:error).with("Error: Jammit::MissingConfiguration: random Jammit error")
174
- end
175
- end
176
-
177
- describe Kumade::Packager, "#package_with_more" do
178
- include_context "with a fake Git"
179
-
180
- before do
181
- subject.stubs(:git_add_and_commit_all_assets_in => true,
182
- :more_assets_path => 'assets')
183
- subject.stubs(:say)
184
- end
185
-
186
- it "calls the more:generate task" do
187
- git.expects(:dirty?).returns(true)
188
- subject.expects(:run).with("bundle exec rake more:generate")
189
- subject.package_with_more
190
- end
191
-
192
- context "with changed assets" do
75
+ context "when packaging and the repository becomes dirty" do
193
76
  before do
77
+ Kumade.configuration.pretending = false
194
78
  git.stubs(:dirty? => true)
195
79
  end
196
80
 
197
- it "prints a success message" do
198
- subject.stubs(:run).with("bundle exec rake more:generate")
199
- subject.expects(:success).with("Packaged assets with More")
200
-
201
- subject.package_with_more
202
- end
203
-
204
- it "calls git_add_and_commit_all_assets_in if assets were added" do
205
- subject.stubs(:more_assets_path => 'blerg')
206
- subject.stubs(:run).with("bundle exec rake more:generate")
207
- subject.expects(:git_add_and_commit_all_assets_in).
208
- with('blerg').
209
- returns(true)
210
-
211
- subject.package_with_more
212
- end
213
- end
214
-
215
- context "with no changed assets" do
216
- it "prints no message" do
217
- subject.stubs(:run).with("bundle exec rake more:generate")
218
- subject.stubs(:git => mock(:dirty? => false))
219
- subject.expects(:say).never
220
-
221
- subject.package_with_more
222
- end
223
-
224
- it "does not call git_add_and_commit_all_more_assets" do
225
- subject.stubs(:run).with("bundle exec rake more:generate")
226
- subject.stubs(:git => mock(:dirty? => false))
227
- subject.expects(:git_add_and_commit_all_assets_in).never
228
-
229
- subject.package_with_more
81
+ it "performs a commit" do
82
+ subject.run
83
+ git.should have_received(:add_and_commit_all_assets_in).with(packager.assets_path)
230
84
  end
231
- end
232
-
233
- it "prints an error if packaging failed" do
234
- subject.stubs(:run).with("bundle exec rake more:generate").raises("blerg")
235
-
236
- subject.expects(:error).with("Error: RuntimeError: blerg")
237
-
238
- subject.package_with_more
239
- end
240
- end
241
-
242
- describe Kumade::Packager, "#git_add_and_commit_all_assets_in" do
243
- include_context "with a fake Git"
244
-
245
- it "should call git.add_and_commit_all_in" do
246
- git.expects(:add_and_commit_all_in).with("dir", 'deploy', 'Compiled assets', "Added and committed all assets", "couldn't commit assets")
247
- subject.git_add_and_commit_all_assets_in("dir")
248
- end
249
- end
250
-
251
- describe Kumade::Packager, "#jammit_assets_path" do
252
- let(:git) { stub() }
253
- let(:packager) { Kumade::Packager.new(git) }
254
-
255
- before do
256
- Jammit.stubs(:package_path).returns('blerg')
257
- end
258
-
259
- subject { packager.jammit_assets_path }
260
-
261
- it { should == File.join(Jammit::PUBLIC_ROOT, 'blerg') }
262
- end
263
-
264
- describe Kumade::Packager, "#more_assets_path" do
265
- include_context "with a fake Git"
266
85
 
267
- it "returns the correct asset path" do
268
- module ::Less
269
- class More
270
- def self.destination_path
271
- 'blerg'
272
- end
273
- end
86
+ it "prints the success message after committing" do
87
+ git.stubs(:add_and_commit_all_assets_in).raises(RuntimeError.new("something broke"))
88
+ subject.run
89
+ Kumade.configuration.outputter.should have_received(:success).never
274
90
  end
275
- subject.more_assets_path.should == 'public/blerg'
276
91
  end
277
- end
278
-
279
- describe Kumade::Packager, "#jammit_installed?" do
280
- include_context "with a fake Git"
281
-
282
- it "returns true because it's loaded by the Gemfile" do
283
- subject.jammit_installed?.should be_true
284
- end
285
-
286
- it "returns false if jammit is not installed" do
287
- subject.jammit_installed?.should be_true
288
- end
289
- end
290
-
291
- describe Kumade::Packager, "#more_installed?" do
292
- include_context "with a fake Git"
293
92
 
294
- context "when More is not installed" do
93
+ context "when packaging and the repository is not dirty" do
295
94
  before do
296
- if defined?(Less)
297
- Object.send(:remove_const, :Less)
298
- end
299
- end
300
-
301
- it "returns false" do
302
- subject.more_installed?.should be_false
95
+ Kumade.configuration.pretending = false
96
+ git.stubs(:dirty? => false)
303
97
  end
304
- end
305
98
 
306
- context "when More is installed" do
307
- before do
308
- module Less
309
- class More
310
- end
311
- end
99
+ it "does not print a success message" do
100
+ subject.run
101
+ Kumade.configuration.outputter.should have_received(:success).never
312
102
  end
313
103
 
314
- it "returns true" do
315
- subject.more_installed?.should be_true
104
+ it "doesn't perform a commit" do
105
+ subject.run
106
+ git.should have_received(:add_and_commit_all_assets_in).never
316
107
  end
317
108
  end
318
109
  end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ require "jammit"
4
+
5
+ describe Kumade::JammitPackager, :with_mock_outputter do
6
+ subject { Kumade::JammitPackager }
7
+
8
+ it_should_behave_like "packager"
9
+
10
+ its(:assets_path) { should == File.join(Jammit::PUBLIC_ROOT, Jammit.package_path) }
11
+
12
+ it "knows how to package itself" do
13
+ ::Jammit.stubs(:package!)
14
+ subject.package
15
+ ::Jammit.should have_received(:package!).once
16
+ end
17
+
18
+ context "when Jammit is defined" do
19
+ before { Jammit }
20
+ it { should be_installed }
21
+ end
22
+
23
+ context "when Jammit is not defined" do
24
+ before { Object.send(:remove_const, :Jammit) }
25
+ it { should_not be_installed }
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+ require "less"
4
+
5
+ describe Kumade::MorePackager, :with_mock_outputter do
6
+ subject { Kumade::MorePackager }
7
+
8
+ before do
9
+ define_constant "Less::More" do
10
+ def self.destination_path
11
+ "awesome_destination"
12
+ end
13
+ end
14
+ end
15
+
16
+ it_should_behave_like "packager"
17
+
18
+ its(:assets_path) { should == File.join('public', ::Less::More.destination_path) }
19
+
20
+ it "knows how to package itself" do
21
+ Less::More.stubs(:generate_all)
22
+
23
+ subject.package
24
+
25
+ Less::More.should have_received(:generate_all).once
26
+ end
27
+
28
+ context "when More is defined" do
29
+ before { Less::More }
30
+ it { should be_installed }
31
+ end
32
+
33
+ context "when Less::More is not defined" do
34
+ before { Less.send(:remove_const, :More) }
35
+ it { should_not be_installed }
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe Kumade::NoopPackager, :with_mock_outputter do
4
+ subject { Kumade::NoopPackager }
5
+
6
+ it_should_behave_like "packager"
7
+
8
+ its(:assets_path) { should == "" }
9
+ end