pessimize 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +13 -0
- data/README.md +8 -1
- data/lib/pessimize/dsl.rb +11 -8
- data/lib/pessimize/pessimizer.rb +2 -2
- data/lib/pessimize/version.rb +1 -1
- data/spec/dsl_spec.rb +32 -0
- data/spec/integration_spec.rb +99 -0
- metadata +5 -4
data/HISTORY
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
=== Pessimize 0.0.3
|
2
|
+
|
3
|
+
Bug fixes:
|
4
|
+
* Fix bug with multiple arguments to `group` not being recognised (issue #1)
|
5
|
+
* Fix missing newlines between statements in Gemfile (issue #2)
|
6
|
+
|
7
|
+
Features:
|
8
|
+
* Better error messages when evaluating a Gemfile with errors (thanks @deepak, #3)
|
9
|
+
|
10
|
+
=== Pessimize 0.0.2
|
11
|
+
|
12
|
+
Features:
|
13
|
+
* Was born (we don't talk about v0.0.1)
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Anyone who works with a Gemfile, i.e. a project that uses [bundler][1].
|
|
9
9
|
Pessimize adds version numbers with the pessimistic constraint operator (`~>`, a.k.a. "spermy" operator) to all gems in your `Gemfile`.
|
10
10
|
|
11
11
|
### Why?
|
12
|
-
You should be using `~> x.x.x` to limit the version numbers of your gems, otherwise `bundle update` could potentially break your application. Read the section on "why bundle update can be dangerous" for a more detailed description, or take a look at the [rubygems explanation][
|
12
|
+
You should be using `~> x.x.x` to limit the version numbers of your gems, otherwise `bundle update` could potentially break your application. Read the section on "why bundle update can be dangerous" for a more detailed description, or take a look at the [rubygems explanation][2].
|
13
13
|
|
14
14
|
### But why a gem?
|
15
15
|
|
@@ -37,6 +37,12 @@ This backs up the existing `Gemfile` and creates a new one with everything neatl
|
|
37
37
|
|
38
38
|
And that's it!
|
39
39
|
|
40
|
+
## Known issues
|
41
|
+
|
42
|
+
Pessimize evaluates the Gemfile as executable ruby code. That means that anything method-like will be retained in the output (e.g. `gem "nokogiri"`, or `source "https://rubygems.org"`), but anything else such as conditional statements will not.
|
43
|
+
|
44
|
+
There are plans to fix this: [see this issue][3] for tracking the progress.
|
45
|
+
|
40
46
|
## Why `bundle update` can be dangerous
|
41
47
|
|
42
48
|
If you add gems to your Gemfile without specifying a version, bundler will attempt to get the latest stable version for that gem. When you first run `bundle install`, bundler will get and install the latest versions, then create a `Gemfile.lock` which specifies the versions used.
|
@@ -55,3 +61,4 @@ The pessimistic constraint operator will only allow the final number of the vers
|
|
55
61
|
|
56
62
|
[1]: http://gembundler.com
|
57
63
|
[2]: http://docs.rubygems.org/read/chapter/16#page74
|
64
|
+
[3]: https://github.com/joonty/pessimize/issues/5
|
data/lib/pessimize/dsl.rb
CHANGED
@@ -2,11 +2,11 @@ module Pessimize
|
|
2
2
|
class DSL
|
3
3
|
def initialize(collector)
|
4
4
|
@collector = collector
|
5
|
-
@
|
5
|
+
@current_groups = nil
|
6
6
|
end
|
7
7
|
|
8
8
|
def parse(definition)
|
9
|
-
instance_eval definition
|
9
|
+
instance_eval definition, __FILE__, __LINE__
|
10
10
|
end
|
11
11
|
|
12
12
|
def method_missing(name, *args)
|
@@ -15,21 +15,24 @@ module Pessimize
|
|
15
15
|
|
16
16
|
protected
|
17
17
|
attr_reader :collector
|
18
|
-
attr_accessor :
|
18
|
+
attr_accessor :current_groups
|
19
19
|
|
20
20
|
def gem(*args)
|
21
|
-
if
|
22
|
-
|
21
|
+
if current_groups
|
22
|
+
current_groups.each do |group|
|
23
|
+
collector.add_grouped_gem(group, *args)
|
24
|
+
end
|
23
25
|
else
|
24
26
|
collector.add_gem(*args)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
def group(
|
30
|
+
def group(group, *others)
|
31
|
+
groups = [group].flatten + others
|
29
32
|
if block_given?
|
30
|
-
self.
|
33
|
+
self.current_groups = groups
|
31
34
|
yield
|
32
|
-
self.
|
35
|
+
self.current_groups = nil
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
data/lib/pessimize/pessimizer.rb
CHANGED
@@ -43,9 +43,9 @@ module Pessimize
|
|
43
43
|
File.delete(file_manager.gemfile)
|
44
44
|
File.open(file_manager.gemfile, 'w') do |f|
|
45
45
|
collection.declarations.each do |dec|
|
46
|
-
f.write(dec.to_code)
|
46
|
+
f.write(dec.to_code + sep)
|
47
47
|
end
|
48
|
-
f.write sep(
|
48
|
+
f.write sep(1)
|
49
49
|
gem_groups = collection.gems
|
50
50
|
global_gems = gem_groups[:global]
|
51
51
|
gem_groups.delete :global
|
data/lib/pessimize/version.rb
CHANGED
data/spec/dsl_spec.rb
CHANGED
@@ -75,6 +75,38 @@ gem 'ostriches', '0.0.1'
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
context "with a string containing a group definition with multiple arguments" do
|
79
|
+
let(:definition) { <<-EOD
|
80
|
+
group :development, :test do
|
81
|
+
gem 'ponies', '>= 3.0.0'
|
82
|
+
end
|
83
|
+
EOD
|
84
|
+
}
|
85
|
+
context "the collector" do
|
86
|
+
it "should receive the grouped gem message with correct arguments" do
|
87
|
+
collector.should_receive(:add_grouped_gem).with(:development, 'ponies', '>= 3.0.0')
|
88
|
+
collector.should_receive(:add_grouped_gem).with(:test, 'ponies', '>= 3.0.0')
|
89
|
+
dsl.parse definition
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "with a string containing a group definition with an array of groups" do
|
95
|
+
let(:definition) { <<-EOD
|
96
|
+
group [:development, :test] do
|
97
|
+
gem 'ponies', '>= 3.0.0'
|
98
|
+
end
|
99
|
+
EOD
|
100
|
+
}
|
101
|
+
context "the collector" do
|
102
|
+
it "should receive the grouped gem message with correct arguments" do
|
103
|
+
collector.should_receive(:add_grouped_gem).with(:development, 'ponies', '>= 3.0.0')
|
104
|
+
collector.should_receive(:add_grouped_gem).with(:test, 'ponies', '>= 3.0.0')
|
105
|
+
dsl.parse definition
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
78
110
|
context "with a string containing a source declaration and a gem" do
|
79
111
|
let(:definition) { <<-EOD
|
80
112
|
source "https://rubygems.org"
|
data/spec/integration_spec.rb
CHANGED
@@ -197,6 +197,105 @@ gem "rake", "~> 10.0.4"
|
|
197
197
|
it_behaves_like "a working pessimizer", gemfile, lockfile, result
|
198
198
|
end
|
199
199
|
|
200
|
+
context "with a Gemfile containing a group with multiple arguments" do
|
201
|
+
gemfile = <<-EOD
|
202
|
+
source "https://rubygems.org"
|
203
|
+
gem 'json'
|
204
|
+
gem 'rake'
|
205
|
+
|
206
|
+
group :development, :test do
|
207
|
+
gem 'sqlite3', '>= 1.3.7'
|
208
|
+
end
|
209
|
+
EOD
|
210
|
+
|
211
|
+
lockfile = <<-EOD
|
212
|
+
GEM
|
213
|
+
remote: https://rubygems.org/
|
214
|
+
specs:
|
215
|
+
json (1.8.0)
|
216
|
+
rake (10.0.4)
|
217
|
+
sqlite3 (>= 1.3.7)
|
218
|
+
EOD
|
219
|
+
|
220
|
+
result = <<-EOD
|
221
|
+
source "https://rubygems.org"
|
222
|
+
|
223
|
+
group :development do
|
224
|
+
gem "sqlite3", "~> 1.3.7"
|
225
|
+
end
|
226
|
+
|
227
|
+
group :test do
|
228
|
+
gem "sqlite3", "~> 1.3.7"
|
229
|
+
end
|
230
|
+
|
231
|
+
gem "json", "~> 1.8.0"
|
232
|
+
gem "rake", "~> 10.0.4"
|
233
|
+
EOD
|
234
|
+
|
235
|
+
it_behaves_like "a working pessimizer", gemfile, lockfile, result
|
236
|
+
end
|
237
|
+
|
238
|
+
context "with a Gemfile containing a group with an array argument" do
|
239
|
+
gemfile = <<-EOD
|
240
|
+
source "https://rubygems.org"
|
241
|
+
gem 'json'
|
242
|
+
gem 'rake'
|
243
|
+
|
244
|
+
group [:development, :test] do
|
245
|
+
gem 'sqlite3', '>= 1.3.7'
|
246
|
+
end
|
247
|
+
EOD
|
248
|
+
|
249
|
+
lockfile = <<-EOD
|
250
|
+
GEM
|
251
|
+
remote: https://rubygems.org/
|
252
|
+
specs:
|
253
|
+
json (1.8.0)
|
254
|
+
rake (10.0.4)
|
255
|
+
sqlite3 (>= 1.3.7)
|
256
|
+
EOD
|
257
|
+
|
258
|
+
result = <<-EOD
|
259
|
+
source "https://rubygems.org"
|
260
|
+
|
261
|
+
group :development do
|
262
|
+
gem "sqlite3", "~> 1.3.7"
|
263
|
+
end
|
264
|
+
|
265
|
+
group :test do
|
266
|
+
gem "sqlite3", "~> 1.3.7"
|
267
|
+
end
|
268
|
+
|
269
|
+
gem "json", "~> 1.8.0"
|
270
|
+
gem "rake", "~> 10.0.4"
|
271
|
+
EOD
|
272
|
+
|
273
|
+
it_behaves_like "a working pessimizer", gemfile, lockfile, result
|
274
|
+
end
|
275
|
+
|
276
|
+
|
277
|
+
context "with a Gemfile containing multiple source statements" do
|
278
|
+
gemfile = <<-EOD
|
279
|
+
source "https://rubygems.org"
|
280
|
+
source 'https://somewhereelse.com'
|
281
|
+
EOD
|
282
|
+
|
283
|
+
lockfile = <<-EOD
|
284
|
+
GEM
|
285
|
+
remote: https://rubygems.org/
|
286
|
+
specs:
|
287
|
+
json (1.8.0)
|
288
|
+
EOD
|
289
|
+
|
290
|
+
result = <<-EOD
|
291
|
+
source "https://rubygems.org"
|
292
|
+
source "https://somewhereelse.com"
|
293
|
+
|
294
|
+
EOD
|
295
|
+
|
296
|
+
it_behaves_like "a working pessimizer", gemfile, lockfile, result
|
297
|
+
end
|
298
|
+
|
200
299
|
context "with a Gemfile containing gems with options" do
|
201
300
|
gemfile = <<-EOD
|
202
301
|
source "https://somewhere-else.org"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pessimize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- .gitignore
|
63
63
|
- .travis.yml
|
64
64
|
- Gemfile
|
65
|
+
- HISTORY
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
@@ -102,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
103
|
version: '0'
|
103
104
|
segments:
|
104
105
|
- 0
|
105
|
-
hash: -
|
106
|
+
hash: -3777369686549972789
|
106
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
108
|
none: false
|
108
109
|
requirements:
|
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
112
|
version: '0'
|
112
113
|
segments:
|
113
114
|
- 0
|
114
|
-
hash: -
|
115
|
+
hash: -3777369686549972789
|
115
116
|
requirements: []
|
116
117
|
rubyforge_project:
|
117
118
|
rubygems_version: 1.8.25
|