semverse 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/semverse/gem_version.rb +1 -1
- metadata +8 -51
- data/.gitignore +0 -17
- data/.travis.yml +0 -13
- data/Gemfile +0 -29
- data/Guardfile +0 -11
- data/README.md +0 -40
- data/Rakefile +0 -6
- data/semverse.gemspec +0 -24
- data/spec/spec_helper.rb +0 -24
- data/spec/unit/semverse/constraint_spec.rb +0 -711
- data/spec/unit/semverse/version_spec.rb +0 -370
- data/spec/unit/semverse_spec.rb +0 -4
@@ -1,370 +0,0 @@
|
|
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").size).to eq(5)
|
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").size).to eq(5)
|
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").size).to eq(3)
|
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").size).to eq(3)
|
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
|
-
expect(subject.coerce("1.0.0")).to 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
|
-
expect(subject.coerce(version)).to 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
|
-
expect(subject.to_s).to 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
|
data/spec/unit/semverse_spec.rb
DELETED