pessimize 0.0.2

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,295 @@
1
+ require 'spec_helper'
2
+
3
+ describe "running pessimize" do
4
+ include IntegrationHelper
5
+
6
+ shared_examples "a working pessimizer" do |gemfile, lockfile, result|
7
+ before do
8
+ write_gemfile(gemfile)
9
+ write_gemfile_lock(lockfile)
10
+ run
11
+ end
12
+
13
+ context "after execution" do
14
+
15
+ context "the stderr" do
16
+ subject { stderr }
17
+ it { should == "" }
18
+ end
19
+
20
+ # exclude from jruby
21
+ context "the return code" 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.exists?(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
+ before do
45
+ setup
46
+ end
47
+
48
+ after do
49
+ tear_down
50
+ end
51
+
52
+ context "with no Gemfile" do
53
+ before do
54
+ run
55
+ end
56
+
57
+ context "the exit status", :platform => :java do
58
+ subject { status.exitstatus }
59
+
60
+ it { should == 1 }
61
+ end
62
+
63
+ context "the error output" do
64
+ subject { stderr }
65
+
66
+ it { should include("no Gemfile exists") }
67
+ end
68
+ end
69
+
70
+ context "with no Gemfile.lock" do
71
+ before do
72
+ write_gemfile "cheese"
73
+ run
74
+ end
75
+
76
+ context "the exit status", :platform => :java do
77
+ subject { status.exitstatus }
78
+
79
+ it { should == 2 }
80
+ end
81
+
82
+ context "the error output" do
83
+ subject { stderr }
84
+
85
+ it { should include("no Gemfile.lock exists") }
86
+ it { should include("Please run `bundle install`") }
87
+ end
88
+ end
89
+
90
+ context "with an unreadable Gemfile" do
91
+ before do
92
+ write_gemfile "cheese"
93
+ write_gemfile_lock "cheese"
94
+ system "chmod 222 Gemfile"
95
+ run
96
+ end
97
+
98
+ context "the exit status", :platform => :java do
99
+ subject { status.exitstatus }
100
+
101
+ it { should == 3 }
102
+ end
103
+
104
+ context "the error output" do
105
+ subject { stderr }
106
+
107
+ it { should include("failed to backup existing Gemfile, exiting") }
108
+ end
109
+ end
110
+
111
+ context "with an unreadable Gemfile.lock" do
112
+ before do
113
+ write_gemfile "cheese"
114
+ write_gemfile_lock "cheese"
115
+ system "chmod 222 Gemfile.lock"
116
+ run
117
+ end
118
+
119
+ context "the exit status", :platform => :java do
120
+ subject { status.exitstatus }
121
+
122
+ it { should == 4 }
123
+ end
124
+
125
+ context "the error output" do
126
+ subject { stderr }
127
+
128
+ it { should include("failed to backup existing Gemfile.lock, exiting") }
129
+ end
130
+ end
131
+
132
+ context "with a simple Gemfile and Gemfile.lock" do
133
+ gemfile = <<-EOD
134
+ source "https://rubygems.org"
135
+ gem 'json'
136
+ gem 'rake'
137
+ EOD
138
+
139
+ lockfile = <<-EOD
140
+ GEM
141
+ remote: https://rubygems.org/
142
+ specs:
143
+ json (1.8.0)
144
+ rake (10.0.4)
145
+ EOD
146
+
147
+ result = <<-EOD
148
+ source "https://rubygems.org"
149
+
150
+ gem "json", "~> 1.8.0"
151
+ gem "rake", "~> 10.0.4"
152
+ EOD
153
+
154
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
155
+ end
156
+
157
+ context "with a Gemfile containing groups" do
158
+ gemfile = <<-EOD
159
+ source "https://rubygems.org"
160
+ gem 'json'
161
+ gem 'rake'
162
+
163
+ group :development do
164
+ gem 'sqlite3', '>= 1.3.7'
165
+ end
166
+
167
+ group :production do
168
+ gem 'pg', '>= 0.15.0', '<= 0.15.2'
169
+ end
170
+ EOD
171
+
172
+ lockfile = <<-EOD
173
+ GEM
174
+ remote: https://rubygems.org/
175
+ specs:
176
+ json (1.8.0)
177
+ rake (10.0.4)
178
+ pg (>= 0.15.0)
179
+ sqlite3 (>= 1.3.7)
180
+ EOD
181
+
182
+ result = <<-EOD
183
+ source "https://rubygems.org"
184
+
185
+ group :development do
186
+ gem "sqlite3", "~> 1.3.7"
187
+ end
188
+
189
+ group :production do
190
+ gem "pg", "~> 0.15.0"
191
+ end
192
+
193
+ gem "json", "~> 1.8.0"
194
+ gem "rake", "~> 10.0.4"
195
+ EOD
196
+
197
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
198
+ end
199
+
200
+ context "with a Gemfile containing gems with options" do
201
+ gemfile = <<-EOD
202
+ source "https://somewhere-else.org"
203
+ gem 'metric_fu', :git => 'https://github.com/joonty/metric_fu.git', :branch => 'master'
204
+
205
+ gem "kaminari", :require => false
206
+ EOD
207
+
208
+ lockfile = <<-EOD
209
+ GIT
210
+ remote: https://github.com/joonty/metric_fu.git
211
+ revision: 8c481090ac928c78ed1f794b4e76b178e1ccf713
212
+ specs:
213
+ bf4-metric_fu (2.1.3.1)
214
+ activesupport (>= 2.0.0)
215
+ arrayfields (= 4.7.4)
216
+ bluff
217
+ chronic (= 0.2.3)
218
+ churn (= 0.0.7)
219
+ coderay
220
+ fattr (= 2.2.1)
221
+ flay (= 1.2.1)
222
+ flog (= 2.3.0)
223
+ googlecharts
224
+ japgolly-Saikuro (>= 1.1.1.0)
225
+ main (= 4.7.1)
226
+ map (= 6.2.0)
227
+ rails_best_practices (~> 0.6)
228
+ rcov (~> 0.8)
229
+ reek (= 1.2.12)
230
+ roodi (= 2.1.0)
231
+
232
+ GEM
233
+ remote: https://rubygems.org/
234
+ specs:
235
+ kaminari (0.14.1)
236
+ EOD
237
+
238
+ result = <<-EOD
239
+ source "https://somewhere-else.org"
240
+
241
+ gem "metric_fu", {:git=>"https://github.com/joonty/metric_fu.git", :branch=>"master"}
242
+ gem "kaminari", "~> 0.14.1", {:require=>false}
243
+ EOD
244
+
245
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
246
+ end
247
+
248
+ context "with a Gemfile that hasn't been installed" do
249
+ gemfile = <<-EOD
250
+ source "https://somewhere-else.org"
251
+ gem 'metric_fu', :git => 'https://github.com/joonty/metric_fu.git', :branch => 'master'
252
+
253
+ gem "kaminari", :require => false
254
+ EOD
255
+
256
+ lockfile = <<-EOD
257
+ GIT
258
+ remote: https://github.com/joonty/metric_fu.git
259
+ revision: 8c481090ac928c78ed1f794b4e76b178e1ccf713
260
+ specs:
261
+ bf4-metric_fu (2.1.3.1)
262
+ activesupport (>= 2.0.0)
263
+ arrayfields (= 4.7.4)
264
+ bluff
265
+ chronic (= 0.2.3)
266
+ churn (= 0.0.7)
267
+ coderay
268
+ fattr (= 2.2.1)
269
+ flay (= 1.2.1)
270
+ flog (= 2.3.0)
271
+ googlecharts
272
+ japgolly-Saikuro (>= 1.1.1.0)
273
+ main (= 4.7.1)
274
+ map (= 6.2.0)
275
+ rails_best_practices (~> 0.6)
276
+ rcov (~> 0.8)
277
+ reek (= 1.2.12)
278
+ roodi (= 2.1.0)
279
+
280
+ GEM
281
+ remote: https://rubygems.org/
282
+ specs:
283
+ kaminari (0.14.1)
284
+ EOD
285
+
286
+ result = <<-EOD
287
+ source "https://somewhere-else.org"
288
+
289
+ gem "metric_fu", {:git=>"https://github.com/joonty/metric_fu.git", :branch=>"master"}
290
+ gem "kaminari", "~> 0.14.1", {:require=>false}
291
+ EOD
292
+
293
+ it_behaves_like "a working pessimizer", gemfile, lockfile, result
294
+ end
295
+ end
@@ -0,0 +1,77 @@
1
+ require 'rspec'
2
+ require 'pessimize'
3
+ require 'open3'
4
+
5
+ def data_file(name)
6
+ File.new(File.dirname(__FILE__) + '/data/' + name)
7
+ end
8
+
9
+ RSpec.configure do |c|
10
+ c.filter_run_excluding :platform => lambda { |platform|
11
+ RUBY_PLATFORM.to_s == platform.to_s
12
+ }
13
+ end
14
+
15
+ module IntegrationHelper
16
+ def setup
17
+ Dir.mkdir('tmp')
18
+ Dir.chdir('tmp')
19
+ end
20
+
21
+ def tear_down
22
+ Dir.chdir(root_path)
23
+ system "rm -r tmp"
24
+ end
25
+
26
+ def root_path
27
+ File.realpath(File.dirname(__FILE__) + "/..")
28
+ end
29
+
30
+ def bin_path
31
+ root_path + "/bin/pessimize"
32
+ end
33
+
34
+ def tmp_path
35
+ root_path + "/tmp/"
36
+ end
37
+
38
+ def run(argument_string = '')
39
+ Open3.popen3 "ruby -I#{root_path}/lib #{bin_path} #{argument_string} > /dev/null" do |_, io_stdout, io_stderr, thr|
40
+ @stdout = io_stdout.read
41
+ @stderr = io_stderr.read
42
+ @status = thr.value if thr
43
+ end
44
+ end
45
+
46
+ def stdout
47
+ @stdout
48
+ end
49
+
50
+ def stderr
51
+ @stderr
52
+ end
53
+
54
+ def status
55
+ @status
56
+ end
57
+
58
+ def write_gemfile(data)
59
+ File.open(tmp_path + 'Gemfile', 'w') do |f|
60
+ f.write data
61
+ end
62
+ end
63
+
64
+ def write_gemfile_lock(data)
65
+ File.open(tmp_path + 'Gemfile.lock', 'w') do |f|
66
+ f.write data
67
+ end
68
+ end
69
+
70
+ def gemfile_backup_contents
71
+ File.read(tmp_path + 'Gemfile.backup')
72
+ end
73
+
74
+ def gemfile_contents
75
+ File.read(tmp_path + 'Gemfile')
76
+ end
77
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'pessimize/version_mapper'
3
+ require 'pessimize/gem'
4
+
5
+ module Pessimize
6
+ describe VersionMapper do
7
+ context "with a gem and version hash" do
8
+ let(:gems) { [ Gem.new('example') ] }
9
+ let(:versions) { { 'example' => '2.2.3' } }
10
+ let(:mapper) { VersionMapper.new }
11
+
12
+ before do
13
+ mapper.call gems, versions
14
+ end
15
+
16
+ subject { gems.first }
17
+
18
+ its(:version) { should == '~> 2.2.3' }
19
+ end
20
+
21
+ context "with multiple gems and version hash" do
22
+ let(:gems) { [ Gem.new('example'), Gem.new('fish', '1.3.2') ] }
23
+ let(:versions) { { 'example' => '1.4.9', 'fish' => '2.3.0' } }
24
+ let(:mapper) { VersionMapper.new }
25
+
26
+ before do
27
+ mapper.call gems, versions
28
+ end
29
+
30
+ context "the first gem" do
31
+ subject { gems.first }
32
+
33
+ its(:version) { should == '~> 1.4.9' }
34
+ end
35
+
36
+ context "the second gem" do
37
+ subject { gems[1] }
38
+
39
+ its(:version) { should == '~> 2.3.0' }
40
+ end
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pessimize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jon Cairns
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.13.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.13.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 10.0.3
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 10.0.3
46
+ description: ! 'Add the pessimistic constraint operator to all gems in your Gemfile,
47
+ restricting the maximum update version.
48
+
49
+
50
+ This is for people who work with projects that use bundler, such as rails projects.
51
+ The pessimistic constraint operator (~>) allows you to specify the maximum version
52
+ that a gem can be updated, and reduces potential breakages when running `bundle
53
+ update`. Pessimize automatically retrieves the current versions of your gems, then
54
+ adds them to your Gemfile (so you don''t have to do it by hand).'
55
+ email:
56
+ - jon@joncairns.com
57
+ executables:
58
+ - pessimize
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/pessimize
69
+ - lib/pessimize.rb
70
+ - lib/pessimize/declaration.rb
71
+ - lib/pessimize/dsl.rb
72
+ - lib/pessimize/file_manager.rb
73
+ - lib/pessimize/gem.rb
74
+ - lib/pessimize/gem_collection.rb
75
+ - lib/pessimize/gemfile_lock_version_parser.rb
76
+ - lib/pessimize/pessimizer.rb
77
+ - lib/pessimize/shell.rb
78
+ - lib/pessimize/version.rb
79
+ - lib/pessimize/version_mapper.rb
80
+ - pessimize.gemspec
81
+ - spec/data/Gemfile.lock.example
82
+ - spec/data/Gemfile.lock.example2
83
+ - spec/declaration_spec.rb
84
+ - spec/dsl_spec.rb
85
+ - spec/gem_collection_spec.rb
86
+ - spec/gem_spec.rb
87
+ - spec/gemfile_lock_version_parser_spec.rb
88
+ - spec/integration_spec.rb
89
+ - spec/spec_helper.rb
90
+ - spec/version_mapper_spec.rb
91
+ homepage: https://github.com/joonty/pessimize
92
+ licenses: []
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: -3427935743038499316
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ segments:
113
+ - 0
114
+ hash: -3427935743038499316
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.25
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Add the pessimistic constraint operator to all gems in your Gemfile, restricting
121
+ the maximum update version.
122
+ test_files:
123
+ - spec/data/Gemfile.lock.example
124
+ - spec/data/Gemfile.lock.example2
125
+ - spec/declaration_spec.rb
126
+ - spec/dsl_spec.rb
127
+ - spec/gem_collection_spec.rb
128
+ - spec/gem_spec.rb
129
+ - spec/gemfile_lock_version_parser_spec.rb
130
+ - spec/integration_spec.rb
131
+ - spec/spec_helper.rb
132
+ - spec/version_mapper_spec.rb