semverse 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +28 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +6 -0
- data/lib/semverse.rb +8 -0
- data/lib/semverse/constraint.rb +255 -0
- data/lib/semverse/errors.rb +29 -0
- data/lib/semverse/gem_version.rb +3 -0
- data/lib/semverse/version.rb +166 -0
- data/semverse.gemspec +24 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/unit/semverse/constraint_spec.rb +697 -0
- data/spec/unit/semverse/version_spec.rb +370 -0
- data/spec/unit/semverse_spec.rb +4 -0
- metadata +95 -0
@@ -0,0 +1,370 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Semverse::Version do
|
4
|
+
describe "ClassMethods" do
|
5
|
+
subject { Semverse::Version }
|
6
|
+
|
7
|
+
describe "::new" do
|
8
|
+
context "a string containing a major, minor and patch separated by periods a pre-release and a build" do
|
9
|
+
before(:each) { @version = subject.new("1.2.3-rc.1+build.1") }
|
10
|
+
|
11
|
+
it "assigns a major value" do
|
12
|
+
expect(@version.major).to eq(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "assigns a minor value" do
|
16
|
+
expect(@version.minor).to eq(2)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "assigns a patch value" do
|
20
|
+
expect(@version.patch).to eq(3)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "assigns a pre_release value" do
|
24
|
+
expect(@version.pre_release).to eq('rc.1')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "assigns a build value" do
|
28
|
+
expect(@version.build).to eq('build.1')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "a string containing a major, minor and patch separated by periods and a build" do
|
33
|
+
before(:each) { @version = subject.new("1.2.3+pre-build.11.e0f985a") }
|
34
|
+
|
35
|
+
it "assigns a major value" do
|
36
|
+
expect(@version.major).to eq(1)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "assigns a minor value" do
|
40
|
+
expect(@version.minor).to eq(2)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "assigns a patch value" do
|
44
|
+
expect(@version.patch).to eq(3)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "doesn't assigns a pre_release value" do
|
48
|
+
expect(@version.pre_release).to be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "assigns a build value" do
|
52
|
+
expect(@version.build).to eq('pre-build.11.e0f985a')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "a string containing a major, minor, and patch separated by periods" do
|
57
|
+
before(:each) { @version = subject.new("1.2.3") }
|
58
|
+
|
59
|
+
it "assigns a major value" do
|
60
|
+
expect(@version.major).to eq(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "assigns a minor value" do
|
64
|
+
expect(@version.minor).to eq(2)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "assigns a patch value" do
|
68
|
+
expect(@version.patch).to eq(3)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "doesn't assigns a pre_release value" do
|
72
|
+
expect(@version.pre_release).to be_nil
|
73
|
+
end
|
74
|
+
|
75
|
+
it "doesn't assigns a build value" do
|
76
|
+
expect(@version.build).to be_nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "a five element array" do
|
81
|
+
before(:each) { @version = subject.new([1,2,3,nil,'build.1']) }
|
82
|
+
|
83
|
+
it "assigns a major value" do
|
84
|
+
expect(@version.major).to eq(1)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "assigns a minor value" do
|
88
|
+
expect(@version.minor).to eq(2)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "assigns a patch value" do
|
92
|
+
expect(@version.patch).to eq(3)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "doesn't assigns a pre_release value" do
|
96
|
+
expect(@version.pre_release).to be_nil
|
97
|
+
end
|
98
|
+
|
99
|
+
it "assigns a build value" do
|
100
|
+
expect(@version.build).to eq('build.1')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "a four element array" do
|
105
|
+
before(:each) { @version = subject.new([1,2,3,'alpha.1']) }
|
106
|
+
|
107
|
+
it "assigns a major value" do
|
108
|
+
expect(@version.major).to eq(1)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "assigns a minor value" do
|
112
|
+
expect(@version.minor).to eq(2)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "assigns a patch value" do
|
116
|
+
expect(@version.patch).to eq(3)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "assigns a pre_release value" do
|
120
|
+
expect(@version.pre_release).to eq('alpha.1')
|
121
|
+
end
|
122
|
+
|
123
|
+
it "doesn't assigns a build value" do
|
124
|
+
expect(@version.build).to be_nil
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "a three element array" do
|
129
|
+
before(:each) { @version = subject.new([1,2,3]) }
|
130
|
+
|
131
|
+
it "assigns a major value" do
|
132
|
+
expect(@version.major).to eq(1)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "assigns a minor value" do
|
136
|
+
expect(@version.minor).to eq(2)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "assigns a patch value" do
|
140
|
+
expect(@version.patch).to eq(3)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "doesn't assigns a pre_release value" do
|
144
|
+
expect(@version.pre_release).to be_nil
|
145
|
+
end
|
146
|
+
|
147
|
+
it "doesn't assigns a build value" do
|
148
|
+
expect(@version.build).to be_nil
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "a two element array" do
|
153
|
+
before(:each) { @version = subject.new([1,2]) }
|
154
|
+
|
155
|
+
it "assigns a major value" do
|
156
|
+
expect(@version.major).to eq(1)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "assigns a minor value" do
|
160
|
+
expect(@version.minor).to eq(2)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "sets the patch value to 0 (zero)" do
|
164
|
+
expect(@version.patch).to eq(0)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "doesn't assigns a pre_release value" do
|
168
|
+
expect(@version.pre_release).to be_nil
|
169
|
+
end
|
170
|
+
|
171
|
+
it "doesn't assigns a build value" do
|
172
|
+
expect(@version.build).to be_nil
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "a one element array" do
|
177
|
+
before(:each) { @version = subject.new([1]) }
|
178
|
+
|
179
|
+
it "assigns the major value" do
|
180
|
+
expect(@version.major).to eq(1)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "sets the minor value to 0 (zero)" do
|
184
|
+
expect(@version.minor).to eq(0)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "sets the patch value to 0 (zero)" do
|
188
|
+
expect(@version.patch).to eq(0)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "doesn't assigns a pre_release value" do
|
192
|
+
expect(@version.pre_release).to be_nil
|
193
|
+
end
|
194
|
+
|
195
|
+
it "doesn't assigns a build value" do
|
196
|
+
expect(@version.build).to be_nil
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context "an empty array" do
|
201
|
+
before(:each) { @version = subject.new(Array.new) }
|
202
|
+
|
203
|
+
it "sets the majro value to 0 (zero)" do
|
204
|
+
expect(@version.major).to eq(0)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "sets the minor value to 0 (zero)" do
|
208
|
+
expect(@version.minor).to eq(0)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "sets the patch value to 0 (zero)" do
|
212
|
+
expect(@version.patch).to eq(0)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "doesn't assigns a pre_release value" do
|
216
|
+
expect(@version.pre_release).to be_nil
|
217
|
+
end
|
218
|
+
|
219
|
+
it "doesn't assigns a build value" do
|
220
|
+
expect(@version.build).to be_nil
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "::split" do
|
226
|
+
it "returns an array containing 5 elements" do
|
227
|
+
expect(subject.split("1.2.0-alpha.1")).to have(5).items
|
228
|
+
end
|
229
|
+
|
230
|
+
context "given a string only containing a major, minor and patch version" do
|
231
|
+
it "returns an array containing 4 elements" do
|
232
|
+
expect(subject.split("1.2.3")).to have(5).items
|
233
|
+
end
|
234
|
+
|
235
|
+
it "returns nil as fourth element" do
|
236
|
+
expect(subject.split("1.2.3")[3]).to be_nil
|
237
|
+
end
|
238
|
+
|
239
|
+
it "returns nil as fifth element" do
|
240
|
+
expect(subject.split("1.2.3")[4]).to be_nil
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "given a string only containing a major and minor version" do
|
245
|
+
it "returns an array containing 4 elements" do
|
246
|
+
expect(subject.split("1.2")).to have(3).items
|
247
|
+
end
|
248
|
+
|
249
|
+
it "returns 0 as the third element" do
|
250
|
+
expect(subject.split("1.2")[2]).to eq(0)
|
251
|
+
end
|
252
|
+
|
253
|
+
it "converts the third element to 0 if it's nil or blank" do
|
254
|
+
expect(subject.split("1.2.")[2]).to eq(0)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context "given a string with only a major version" do
|
259
|
+
it "returns an array containing 3 elements" do
|
260
|
+
expect(subject.split("1")).to have(3).items
|
261
|
+
end
|
262
|
+
|
263
|
+
it "returns 0 as the second element" do
|
264
|
+
expect(subject.split("1")[1]).to eq(0)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "returns 0 as the third element" do
|
268
|
+
expect(subject.split("1")[2]).to eq(0)
|
269
|
+
end
|
270
|
+
|
271
|
+
it "converts the second element to 0 if it's nil or blank" do
|
272
|
+
expect(subject.split("1.")[1]).to eq(0)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context "given a string with an invalid version"
|
277
|
+
it "raises an InvalidVersionFormat error" do
|
278
|
+
expect {
|
279
|
+
subject.split("hello")
|
280
|
+
}.to raise_error(Semverse::InvalidVersionFormat)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "::coerce" do
|
285
|
+
|
286
|
+
it "coerces a String to a Version object" do
|
287
|
+
subject.coerce("1.0.0").should eql(subject.new("1.0.0"))
|
288
|
+
end
|
289
|
+
|
290
|
+
it "returns an object of the desired class without any additional processing" do
|
291
|
+
version = subject.new("1.0.0")
|
292
|
+
# we want object equality here to prove that the exact object was returned
|
293
|
+
subject.coerce(version).should equal(version)
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
|
300
|
+
describe "#pre_release?" do
|
301
|
+
context "when a pre-release value is set" do
|
302
|
+
subject { described_class.new("1.2.3-alpha").pre_release? }
|
303
|
+
it { should be_true }
|
304
|
+
end
|
305
|
+
|
306
|
+
context "when no pre-release value is set" do
|
307
|
+
subject { described_class.new("1.2.3").pre_release? }
|
308
|
+
it { should be_false }
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
describe "#zero?" do
|
313
|
+
context "major, minor and patch are equal to 0" do
|
314
|
+
subject { described_class.new("0.0.0").zero? }
|
315
|
+
it { should be_true }
|
316
|
+
end
|
317
|
+
|
318
|
+
context "major is not equal to 0" do
|
319
|
+
subject { described_class.new("1.0.0").zero? }
|
320
|
+
it { should be_false }
|
321
|
+
end
|
322
|
+
|
323
|
+
context "minor is not equal to 0" do
|
324
|
+
subject { described_class.new("0.1.0").zero? }
|
325
|
+
it { should be_false }
|
326
|
+
end
|
327
|
+
|
328
|
+
context "patch is not equal to 0" do
|
329
|
+
subject { described_class.new("0.0.1").zero? }
|
330
|
+
it { should be_false }
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
describe "#to_s" do
|
335
|
+
subject { Semverse::Version.new("1.0.0-rc.1+build.1") }
|
336
|
+
|
337
|
+
it "returns a string containing the major.minor.patch-pre_release+build" do
|
338
|
+
subject.to_s.should eq("1.0.0-rc.1+build.1")
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
describe "#<=>" do
|
343
|
+
it "compares versions" do
|
344
|
+
versions_list = %w[
|
345
|
+
1.0.0-0
|
346
|
+
1.0.0-alpha
|
347
|
+
1.0.0-alpha.1
|
348
|
+
1.0.0-beta.2
|
349
|
+
1.0.0-beta.11
|
350
|
+
1.0.0-rc.1
|
351
|
+
1.0.0-rc.1+build.1
|
352
|
+
1.0.0
|
353
|
+
1.0.0+0.3.7
|
354
|
+
1.0.0+build
|
355
|
+
1.0.0+build.2.b8f12d7
|
356
|
+
1.0.0+build.11.e0f985a
|
357
|
+
]
|
358
|
+
versions = versions_list.map { |version| Semverse::Version.new(version) }
|
359
|
+
|
360
|
+
100.times do
|
361
|
+
shuffled_versions = versions.shuffle
|
362
|
+
while shuffled_versions == versions
|
363
|
+
shuffled_versions = shuffled_versions.shuffle
|
364
|
+
end
|
365
|
+
expect(shuffled_versions.sort.map(&:to_s)).to eq(versions_list)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: semverse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamie Winsor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: An elegant library for representing and comparing SemVer versions and
|
42
|
+
constraints
|
43
|
+
email:
|
44
|
+
- jamie@vialstudios.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".travis.yml"
|
51
|
+
- Gemfile
|
52
|
+
- Guardfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/semverse.rb
|
57
|
+
- lib/semverse/constraint.rb
|
58
|
+
- lib/semverse/errors.rb
|
59
|
+
- lib/semverse/gem_version.rb
|
60
|
+
- lib/semverse/version.rb
|
61
|
+
- semverse.gemspec
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- spec/unit/semverse/constraint_spec.rb
|
64
|
+
- spec/unit/semverse/version_spec.rb
|
65
|
+
- spec/unit/semverse_spec.rb
|
66
|
+
homepage: https://github.com/berkshelf/semverse
|
67
|
+
licenses:
|
68
|
+
- Apache 2.0
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.9.1
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.2.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: An elegant library for representing and comparing SemVer versions and constraints
|
90
|
+
test_files:
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
- spec/unit/semverse/constraint_spec.rb
|
93
|
+
- spec/unit/semverse/version_spec.rb
|
94
|
+
- spec/unit/semverse_spec.rb
|
95
|
+
has_rdoc:
|