pessimizer 1.0.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.
@@ -0,0 +1,590 @@
1
+ require 'spec_helper'
2
+
3
+ describe "running pessimize" do
4
+ include IntegrationHelper
5
+
6
+ shared_examples "a working pessimizer" do |gemfile, lockfile, result, cli_args = ""|
7
+ before do
8
+ write_gemfile(gemfile)
9
+ write_gemfile_lock(lockfile)
10
+ run(cli_args)
11
+ end
12
+
13
+ context "after execution" do
14
+
15
+ context "the stderr", exclude_platform: :java do
16
+ subject { stderr }
17
+ it { should == "" }
18
+ end
19
+
20
+ # exclude from jruby
21
+ context "the return code", exclude_platform: :java do
22
+ subject { $?.exitstatus }
23
+ it { should == 0 }
24
+ end
25
+
26
+ context "the Gemfile.backup" do
27
+ it "should be created" do
28
+ File.exist?(tmp_path + 'Gemfile.backup').should be(true)
29
+ end
30
+
31
+ it "should be the same as the original Gemfile" do
32
+ gemfile_backup_contents.should == gemfile
33
+ end
34
+ end
35
+
36
+ context "the Gemfile" do
37
+ subject { gemfile_contents }
38
+
39
+ it { should == result }
40
+ end
41
+ end
42
+ end
43
+
44
+ shared_examples "a working pessimizer without backups" do |gemfile, lockfile, result, cli_args = ""|
45
+ before do
46
+ write_gemfile(gemfile)
47
+ write_gemfile_lock(lockfile)
48
+ run(cli_args)
49
+ end
50
+
51
+ context "after execution" do
52
+
53
+ context "the stderr" do
54
+ subject { stderr }
55
+ it { should == "" }
56
+ end
57
+
58
+ # exclude from jruby
59
+ context "the return code", exclude_platform: :java do
60
+ subject { $?.exitstatus }
61
+ it { should == 0 }
62
+ end
63
+
64
+ context "the Gemfile.backup" do
65
+ it "should not exist" do
66
+ File.exist?(tmp_path + 'Gemfile.backup').should be(false)
67
+ end
68
+ end
69
+
70
+ context "the Gemfile.lock.backup" do
71
+ it "should not exist" do
72
+ File.exist?(tmp_path + 'Gemfile.lock.backup').should be(false)
73
+ end
74
+ end
75
+
76
+ context "the Gemfile" do
77
+ subject { gemfile_contents }
78
+
79
+ it { should == result }
80
+ end
81
+ end
82
+ end
83
+
84
+ before do
85
+ setup
86
+ end
87
+
88
+ after do
89
+ tear_down
90
+ end
91
+
92
+ context "with the help option" do
93
+ before do
94
+ run('--help')
95
+ end
96
+
97
+ context "the exit status", :platform => :java do
98
+ subject { status.exitstatus }
99
+
100
+ it { should == 0 }
101
+ end
102
+
103
+ context "the output" do
104
+ subject { stdout }
105
+
106
+ it { should include("Usage:") }
107
+ end
108
+ end
109
+
110
+ context "with the version option" do
111
+ before do
112
+ run('--version')
113
+ end
114
+
115
+ context "the exit status", :platform => :java do
116
+ subject { status.exitstatus }
117
+
118
+ it { should == 0 }
119
+ end
120
+
121
+ context "the output" do
122
+ subject { stdout }
123
+
124
+ it { should include(Pessimize::VERSION) }
125
+ end
126
+ end
127
+
128
+ context "with the version option" do
129
+ before do
130
+ run('-c rubbish')
131
+ end
132
+
133
+ context "the exit status", :platform => :java do
134
+ subject { status.exitstatus }
135
+
136
+ it { should == 255 }
137
+ end
138
+
139
+ context "the error output" do
140
+ subject { stderr }
141
+
142
+ it { should include("--version-constraint must be one of minor|patch") }
143
+ end
144
+ end
145
+
146
+ context "with no Gemfile" do
147
+ before do
148
+ run
149
+ end
150
+
151
+ context "the exit status", :platform => :java do
152
+ subject { status.exitstatus }
153
+
154
+ it { should == 1 }
155
+ end
156
+
157
+ context "the error output" do
158
+ subject { stderr }
159
+
160
+ it { should include("no Gemfile exists") }
161
+ end
162
+ end
163
+
164
+ context "with no Gemfile.lock" do
165
+ before do
166
+ write_gemfile "cheese"
167
+ run
168
+ end
169
+
170
+ context "the exit status", :platform => :java do
171
+ subject { status.exitstatus }
172
+
173
+ it { should == 2 }
174
+ end
175
+
176
+ context "the error output" do
177
+ subject { stderr }
178
+
179
+ it { should include("no Gemfile.lock exists") }
180
+ it { should include("Please run `bundle install`") }
181
+ end
182
+ end
183
+
184
+ context "with an unreadable Gemfile" do
185
+ before do
186
+ write_gemfile "cheese"
187
+ write_gemfile_lock "cheese"
188
+ system "chmod 222 Gemfile"
189
+ run
190
+ end
191
+
192
+ context "the exit status", :platform => :java do
193
+ subject { status.exitstatus }
194
+
195
+ it { should == 3 }
196
+ end
197
+
198
+ context "the error output" do
199
+ subject { stderr }
200
+
201
+ it { should include("failed to backup existing Gemfile, exiting") }
202
+ end
203
+ end
204
+
205
+ context "with an unreadable Gemfile.lock" do
206
+ before do
207
+ write_gemfile "cheese"
208
+ write_gemfile_lock "cheese"
209
+ system "chmod 222 Gemfile.lock"
210
+ run
211
+ end
212
+
213
+ context "the exit status", :platform => :java do
214
+ subject { status.exitstatus }
215
+
216
+ it { should == 4 }
217
+ end
218
+
219
+ context "the error output" do
220
+ subject { stderr }
221
+
222
+ it { should include("failed to backup existing Gemfile.lock, exiting") }
223
+ end
224
+ end
225
+
226
+ context "with a simple Gemfile and Gemfile.lock" do
227
+ gemfile = <<-EOD
228
+ source "https://rubygems.org"
229
+ gem 'json'
230
+ gem 'rake'
231
+ EOD
232
+
233
+ lockfile = <<-EOD
234
+ GEM
235
+ remote: https://rubygems.org/
236
+ specs:
237
+ json (1.8.0)
238
+ rake (10.0.4)
239
+ EOD
240
+
241
+ result = <<-EOD
242
+ source "https://rubygems.org"
243
+ gem 'json', "~> 1.8"
244
+ gem 'rake', "~> 10.0"
245
+ EOD
246
+
247
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
248
+ end
249
+
250
+ context "with a Gemfile containing groups" do
251
+ gemfile = <<-EOD
252
+ source "https://rubygems.org"
253
+ gem 'json'
254
+ gem 'rake'
255
+
256
+ group :development do
257
+ gem 'sqlite3', '>= 1.3.7'
258
+ end
259
+
260
+ group :production do
261
+ gem 'pg', '>= 0.15.0', '<= 0.15.2'
262
+ end
263
+ EOD
264
+
265
+ lockfile = <<-EOD
266
+ GEM
267
+ remote: https://rubygems.org/
268
+ specs:
269
+ json (1.8.0)
270
+ rake (10.0.4)
271
+ pg (0.15.0)
272
+ sqlite3 (1.3.7)
273
+ EOD
274
+
275
+ result = <<-EOD
276
+ source "https://rubygems.org"
277
+ gem 'json', "~> 1.8"
278
+ gem 'rake', "~> 10.0"
279
+
280
+ group :development do
281
+ gem 'sqlite3', '~> 1.3'
282
+ end
283
+
284
+ group :production do
285
+ gem 'pg', '~> 0.15', '<= 0.15.2'
286
+ end
287
+ EOD
288
+
289
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
290
+ end
291
+
292
+ context "with a Gemfile containing a group with multiple arguments" do
293
+ gemfile = <<-EOD
294
+ source "https://rubygems.org"
295
+ gem 'json'
296
+ gem 'rake'
297
+
298
+ group :development, :test do
299
+ gem 'sqlite3', '>= 1.3.7'
300
+ end
301
+ EOD
302
+
303
+ lockfile = <<-EOD
304
+ GEM
305
+ remote: https://rubygems.org/
306
+ specs:
307
+ json (1.8.0)
308
+ rake (10.0.4)
309
+ sqlite3 (1.3.7)
310
+ EOD
311
+
312
+ result = <<-EOD
313
+ source "https://rubygems.org"
314
+ gem 'json', "~> 1.8"
315
+ gem 'rake', "~> 10.0"
316
+
317
+ group :development, :test do
318
+ gem 'sqlite3', '~> 1.3'
319
+ end
320
+ EOD
321
+
322
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
323
+ end
324
+
325
+ context "with a Gemfile containing a group with an array argument" do
326
+ gemfile = <<-EOD
327
+ source "https://rubygems.org"
328
+ gem 'json'
329
+ gem 'rake'
330
+
331
+ group [:development, :test] do
332
+ gem 'sqlite3', '>= 1.3.7'
333
+ end
334
+ EOD
335
+
336
+ lockfile = <<-EOD
337
+ GEM
338
+ remote: https://rubygems.org/
339
+ specs:
340
+ json (1.8.0)
341
+ rake (10.0.4)
342
+ sqlite3 (1.3.7)
343
+ EOD
344
+
345
+ result = <<-EOD
346
+ source "https://rubygems.org"
347
+ gem 'json', "~> 1.8"
348
+ gem 'rake', "~> 10.0"
349
+
350
+ group [:development, :test] do
351
+ gem 'sqlite3', '~> 1.3'
352
+ end
353
+ EOD
354
+
355
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
356
+ end
357
+
358
+
359
+ context "with a Gemfile containing multiple source statements" do
360
+ gemfile = <<-EOD
361
+ source "https://rubygems.org"
362
+ source 'https://somewhereelse.com'
363
+ EOD
364
+
365
+ lockfile = <<-EOD
366
+ GEM
367
+ remote: https://rubygems.org/
368
+ specs:
369
+ json (1.8.0)
370
+ EOD
371
+
372
+ result = <<-EOD
373
+ source "https://rubygems.org"
374
+ source 'https://somewhereelse.com'
375
+ EOD
376
+
377
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
378
+ end
379
+
380
+ context "with a Gemfile containing gems with options" do
381
+ gemfile = <<-EOD
382
+ source "https://somewhere-else.org"
383
+ gem 'metric_fu', :git => 'https://github.com/joonty/metric_fu.git', :branch => 'master'
384
+
385
+ gem "kaminari", :require => false
386
+ EOD
387
+
388
+ lockfile = <<-EOD
389
+ GIT
390
+ remote: https://github.com/joonty/metric_fu.git
391
+ revision: 8c481090ac928c78ed1f794b4e76b178e1ccf713
392
+ specs:
393
+ bf4-metric_fu (2.1.3.1)
394
+ activesupport (2.0.0)
395
+ arrayfields (= 4.7.4)
396
+ bluff
397
+ chronic (= 0.2.3)
398
+ churn (= 0.0.7)
399
+ coderay
400
+ fattr (= 2.2.1)
401
+ flay (= 1.2.1)
402
+ flog (= 2.3.0)
403
+ googlecharts
404
+ japgolly-Saikuro (1.1.1.0)
405
+ main (= 4.7.1)
406
+ map (= 6.2.0)
407
+ rails_best_practices (~> 0.6)
408
+ rcov (~> 0.8)
409
+ reek (= 1.2.12)
410
+ roodi (= 2.1.0)
411
+
412
+ GEM
413
+ remote: https://rubygems.org/
414
+ specs:
415
+ kaminari (0.14.1)
416
+ EOD
417
+
418
+ result = <<-EOD
419
+ source "https://somewhere-else.org"
420
+ gem 'metric_fu', :git => 'https://github.com/joonty/metric_fu.git', :branch => 'master'
421
+
422
+ gem "kaminari", "~> 0.14", :require => false
423
+ EOD
424
+
425
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
426
+ end
427
+
428
+ context "with a Gemfile that hasn't been installed" do
429
+ gemfile = <<-EOD
430
+ source "https://somewhere-else.org"
431
+ gem 'metric_fu', :git => 'https://github.com/joonty/metric_fu.git', :branch => 'master'
432
+
433
+ gem "kaminari", :require => false
434
+ EOD
435
+
436
+ lockfile = <<-EOD
437
+ GIT
438
+ remote: https://github.com/joonty/metric_fu.git
439
+ revision: 8c481090ac928c78ed1f794b4e76b178e1ccf713
440
+ specs:
441
+ bf4-metric_fu (2.1.3.1)
442
+ activesupport (2.0.0)
443
+ arrayfields (= 4.7.4)
444
+ bluff
445
+ chronic (= 0.2.3)
446
+ churn (= 0.0.7)
447
+ coderay
448
+ fattr (= 2.2.1)
449
+ flay (= 1.2.1)
450
+ flog (= 2.3.0)
451
+ googlecharts
452
+ japgolly-Saikuro (1.1.1.0)
453
+ main (= 4.7.1)
454
+ map (= 6.2.0)
455
+ rails_best_practices (~> 0.6)
456
+ rcov (~> 0.8)
457
+ reek (= 1.2.12)
458
+ roodi (= 2.1.0)
459
+
460
+ GEM
461
+ remote: https://rubygems.org/
462
+ specs:
463
+ kaminari (0.14.1)
464
+ EOD
465
+
466
+ result = <<-EOD
467
+ source "https://somewhere-else.org"
468
+ gem 'metric_fu', :git => 'https://github.com/joonty/metric_fu.git', :branch => 'master'
469
+
470
+ gem "kaminari", "~> 0.14", :require => false
471
+ EOD
472
+
473
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
474
+ end
475
+
476
+ context "with the option to use patch level constraints" do
477
+ gemfile = <<-EOD
478
+ source "https://rubygems.org"
479
+ gem 'json'
480
+ gem 'rake'
481
+
482
+ group :development, :test do
483
+ gem 'sqlite3', '>= 1.3.7'
484
+ end
485
+ EOD
486
+
487
+ lockfile = <<-EOD
488
+ GEM
489
+ remote: https://rubygems.org/
490
+ specs:
491
+ json (1.8.0)
492
+ rake (10.0.4)
493
+ sqlite3 (1.3.7)
494
+ EOD
495
+
496
+ result = <<-EOD
497
+ source "https://rubygems.org"
498
+ gem 'json', "~> 1.8.0"
499
+ gem 'rake', "~> 10.0.4"
500
+
501
+ group :development, :test do
502
+ gem 'sqlite3', '~> 1.3.7'
503
+ end
504
+ EOD
505
+
506
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result, '-c patch'
507
+ end
508
+
509
+ context "with the option to not have backups" do
510
+ gemfile = <<-EOD
511
+ source "https://rubygems.org"
512
+ gem 'json'
513
+ gem 'rake'
514
+
515
+ group :development, :test do
516
+ gem 'sqlite3', '>= 1.3.7'
517
+ end
518
+ EOD
519
+
520
+ lockfile = <<-EOD
521
+ GEM
522
+ remote: https://rubygems.org/
523
+ specs:
524
+ json (1.8.0)
525
+ rake (10.0.4)
526
+ sqlite3 (1.3.7)
527
+ EOD
528
+
529
+ result = <<-EOD
530
+ source "https://rubygems.org"
531
+ gem 'json', "~> 1.8"
532
+ gem 'rake', "~> 10.0"
533
+
534
+ group :development, :test do
535
+ gem 'sqlite3', '~> 1.3'
536
+ end
537
+ EOD
538
+
539
+ it_behaves_like "a working pessimizer without backups", gemfile, lockfile, result, '--no-backup'
540
+ end
541
+
542
+ context "with a Gemfile using new lines for gem definitions" do
543
+ gemfile = <<-EOD
544
+ source "https://rubygems.org"
545
+ gem 'json',
546
+ group: :production
547
+
548
+ gem 'pessimize',
549
+ github: "joonty/pessimize"
550
+
551
+ group :development, :test do
552
+ gem 'sqlite3',
553
+ '>= 1.3.7'
554
+ end
555
+ EOD
556
+
557
+ lockfile = <<-EOD
558
+ GIT
559
+ remote: git://github.com/joonty/pessimize.git
560
+ revision: 40f6ec6c7483a453b72e09efbba0e0d7de3b37ab
561
+ specs:
562
+ pessimize (0.2.0)
563
+ bundler
564
+ trollop
565
+
566
+ GEM
567
+ remote: https://rubygems.org/
568
+ specs:
569
+ json (1.8.0)
570
+ trollop (2.1.2)
571
+ sqlite3 (1.3.7)
572
+ EOD
573
+
574
+ result = <<-EOD
575
+ source "https://rubygems.org"
576
+ gem 'json', "~> 1.8",
577
+ group: :production
578
+
579
+ gem 'pessimize',
580
+ github: "joonty/pessimize"
581
+
582
+ group :development, :test do
583
+ gem 'sqlite3',
584
+ '~> 1.3'
585
+ end
586
+ EOD
587
+
588
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
589
+ end
590
+ end
@@ -0,0 +1,84 @@
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
+ require 'rspec'
4
+ require 'rspec/its'
5
+ require 'pessimize'
6
+ require 'open3'
7
+ require 'ripper'
8
+
9
+ def data_file(name)
10
+ File.new(File.dirname(__FILE__) + '/data/' + name)
11
+ end
12
+
13
+ RSpec.configure do |config|
14
+ config.filter_run_excluding :exclude_platform => lambda { |platform|
15
+ RUBY_PLATFORM.to_s == platform.to_s
16
+ }
17
+
18
+ config.expect_with(:rspec) { |c| c.syntax = :should }
19
+ end
20
+
21
+ module IntegrationHelper
22
+ def setup
23
+ Dir.mkdir('tmp')
24
+ Dir.chdir('tmp')
25
+ end
26
+
27
+ def tear_down
28
+ Dir.chdir(root_path)
29
+ system "rm -r tmp"
30
+ end
31
+
32
+ def root_path
33
+ File.realpath(File.dirname(__FILE__) + "/..")
34
+ end
35
+
36
+ def bin_path
37
+ root_path + "/bin/pessimize"
38
+ end
39
+
40
+ def tmp_path
41
+ root_path + "/tmp/"
42
+ end
43
+
44
+ def run(argument_string = '')
45
+ command = "ruby -I#{root_path}/lib #{bin_path} #{argument_string}"
46
+ Open3.popen3 command do |_, io_stdout, io_stderr, thr|
47
+ @stdout = io_stdout.read
48
+ @stderr = io_stderr.read
49
+ @status = thr.value if thr
50
+ end
51
+ end
52
+
53
+ def stdout
54
+ @stdout
55
+ end
56
+
57
+ def stderr
58
+ @stderr
59
+ end
60
+
61
+ def status
62
+ @status
63
+ end
64
+
65
+ def write_gemfile(data)
66
+ File.open(tmp_path + 'Gemfile', 'w') do |f|
67
+ f.write data
68
+ end
69
+ end
70
+
71
+ def write_gemfile_lock(data)
72
+ File.open(tmp_path + 'Gemfile.lock', 'w') do |f|
73
+ f.write data
74
+ end
75
+ end
76
+
77
+ def gemfile_backup_contents
78
+ File.read(tmp_path + 'Gemfile.backup')
79
+ end
80
+
81
+ def gemfile_contents
82
+ File.read(tmp_path + 'Gemfile')
83
+ end
84
+ end