semverse 1.2.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,711 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec::Matchers.define :satisfies do |*args|
4
- match do |constraint|
5
- constraint.satisfies?(*args).should be_true
6
- end
7
- end
8
-
9
- describe Semverse::Constraint do
10
- let(:valid_string) { ">= 0.0.0" }
11
- let(:invalid_string) { "x23u7089213.*" }
12
-
13
- describe "ClassMethods" do
14
- subject { Semverse::Constraint }
15
-
16
- describe "::new" do
17
- it "returns a new instance of Constraint" do
18
- expect(subject.new(valid_string)).to be_a(Semverse::Constraint)
19
- end
20
-
21
- it "assigns the parsed operator to the operator attribute" do
22
- expect(subject.new(valid_string).operator).to eq(">=")
23
- end
24
-
25
- it "assigns the parsed operator to the operator attribute with no separation between operator and version" do
26
- expect(subject.new(">=0.0.0").operator).to eq(">=")
27
- end
28
-
29
- it "assigns the parsed version string as an instance of Version to the version attribute" do
30
- result = subject.new(valid_string)
31
-
32
- expect(result.version).to be_a(Semverse::Version)
33
- expect(result.version.to_s).to eq("0.0.0")
34
- end
35
-
36
- it "falls back to a default constraint if nil is provided" do
37
- result = subject.new(nil)
38
-
39
- expect(result.version.to_s).to eq("0.0.0")
40
- expect(result.operator).to eq(">=")
41
- end
42
-
43
- it "fall sback to a default constraint if a blank string is provided" do
44
- result = subject.new("")
45
-
46
- expect(result.version.to_s).to eq("0.0.0")
47
- expect(result.operator).to eq(">=")
48
- end
49
-
50
- context "given a string that does not match the Constraint REGEXP" do
51
- it "raises an InvalidConstraintFormat error" do
52
- expect {
53
- subject.new(invalid_string)
54
- }.to raise_error(Semverse::InvalidConstraintFormat)
55
- end
56
- end
57
-
58
- context "given a constraint that does not include a minor version (~>)" do
59
- it "has a nil value for minor" do
60
- expect(subject.new("~> 1").minor).to be_nil
61
- end
62
-
63
- it "has a nil value for patch" do
64
- expect(subject.new("~> 1").patch).to be_nil
65
- end
66
- end
67
-
68
- context "given a constraint that does not include a minor version (=)" do
69
- it "has a 0 for minor" do
70
- expect(subject.new("= 1").minor).to eq(0)
71
- end
72
- end
73
-
74
- context "given a constraint that does not include a patch version (~>)" do
75
- it "has a nil value for patch" do
76
- expect(subject.new("~> 1.2").patch).to be_nil
77
- end
78
- end
79
-
80
- context "given a constraint that does not include a patch version (=)" do
81
- it "has a 0 for patch" do
82
- expect(subject.new("= 1.2").patch).to eq(0)
83
- end
84
- end
85
-
86
- context "given a constraint that does not include a build version" do
87
- it "has a nil value for build" do
88
- expect(subject.new(">= 1.2.3-alpha").build).to be_nil
89
- end
90
- end
91
-
92
- context "given a constraint that does not include a pre release version" do
93
- it "has a nil value for pre release" do
94
- expect(subject.new(">= 1.2.3+build").pre_release).to be_nil
95
- end
96
- end
97
- end
98
-
99
- describe "::split" do
100
- let(:constraint_string) { nil }
101
-
102
- subject { described_class.split(constraint_string) }
103
-
104
- context "given a constraint containing the elements (operator, major, minor, patch, pre_release, build)" do
105
- let(:constraint_string) { ">= 1.2.3-alpha+build" }
106
-
107
- it "returns an array with the constraint operator at index 0" do
108
- expect(subject[0]).to eq(">=")
109
- end
110
-
111
- it "returns an array with the major version in index 1" do
112
- expect(subject[1]).to eq(1)
113
- end
114
-
115
- it "returns an array with the minor version at index 2" do
116
- expect(subject[2]).to eq(2)
117
- end
118
-
119
- it "returns an array with the patch version at index 3" do
120
- expect(subject[3]).to eq(3)
121
- end
122
-
123
- it "returns an array with the pre release version at index 4" do
124
- expect(subject[4]).to eq("alpha")
125
- end
126
-
127
- it "returns an array with the build version at index 5" do
128
- expect(subject[5]).to eq("build")
129
- end
130
- end
131
-
132
- context "given a constraint containing the elements (operator, major, minor, patch, pre_release)" do
133
- let(:constraint_string) { ">= 1.2.3-alpha" }
134
-
135
- it "returns an array with the constraint operator at index 0" do
136
- expect(subject[0]).to eq(">=")
137
- end
138
-
139
- it "returns an array with the major version in index 1" do
140
- expect(subject[1]).to eq(1)
141
- end
142
-
143
- it "returns an array with the minor version at index 2" do
144
- expect(subject[2]).to eq(2)
145
- end
146
-
147
- it "returns an array with the patch version at index 3" do
148
- expect(subject[3]).to eq(3)
149
- end
150
-
151
- it "returns an array with the pre release version at index 4" do
152
- expect(subject[4]).to eq("alpha")
153
- end
154
-
155
- it "returns an array with a nil value at index 5" do
156
- expect(subject[5]).to be_nil
157
- end
158
- end
159
-
160
- context "given a constraint containing the elements (operator, major, minor, patch)" do
161
- let(:constraint_string) { ">= 1.2.3" }
162
-
163
- it "returns an array with the constraint operator at index 0" do
164
- expect(subject[0]).to eq(">=")
165
- end
166
-
167
- it "returns an array with the major version in index 1" do
168
- expect(subject[1]).to eq(1)
169
- end
170
-
171
- it "returns an array with the minor version at index 2" do
172
- expect(subject[2]).to eq(2)
173
- end
174
-
175
- it "returns an array with the patch version at index 3" do
176
- expect(subject[3]).to eq(3)
177
- end
178
-
179
- it "returns an array with a nil value at index 4" do
180
- expect(subject[4]).to be_nil
181
- end
182
-
183
- it "returns an array with a nil value at index 5" do
184
- expect(subject[5]).to be_nil
185
- end
186
- end
187
-
188
- context "given a constraint containing the elements (operator, major, minor)" do
189
- let(:constraint_string) { ">= 1.2" }
190
-
191
- it "returns an array with the constraint operator at index 0" do
192
- expect(subject[0]).to eq(">=")
193
- end
194
-
195
- it "returns an array with the major version in index 1" do
196
- expect(subject[1]).to eq(1)
197
- end
198
-
199
- it "returns an array with the minor version at index 2" do
200
- expect(subject[2]).to eq(2)
201
- end
202
-
203
- it "returns an array with a nil value at index 3" do
204
- expect(subject[3]).to be_nil
205
- end
206
-
207
- it "returns an array with a nil value at index 4" do
208
- expect(subject[4]).to be_nil
209
- end
210
-
211
- it "returns an array with a nil value at index 5" do
212
- expect(subject[5]).to be_nil
213
- end
214
- end
215
-
216
- context "given a constraint containing the elements (operator, major)" do
217
- let(:constraint_string) { ">= 1" }
218
-
219
- it "returns an array with the constraint operator at index 0" do
220
- expect(subject[0]).to eq(">=")
221
- end
222
-
223
- it "returns an array with the major version in index 1" do
224
- expect(subject[1]).to eq(1)
225
- end
226
-
227
- it "returns an array with a nil value at index 2" do
228
- expect(subject[2]).to be_nil
229
- end
230
-
231
- it "returns an array with a nil value at index 3" do
232
- expect(subject[3]).to be_nil
233
- end
234
-
235
- it "returns an array with a nil value at index 4" do
236
- expect(subject[4]).to be_nil
237
- end
238
-
239
- it "returns an array with a nil value at index 5" do
240
- expect(subject[5]).to be_nil
241
- end
242
- end
243
-
244
- context "given a constraint which is missing an operator" do
245
- let(:constraint_string) { "1.2.3" }
246
-
247
- it "returns an equality operator at index 0" do
248
- expect(subject[0]).to eq("=")
249
- end
250
- end
251
-
252
- context "given a string that does not match the Constraint REGEXP" do
253
- let(:constraint_string) { "x23u7089213.*" }
254
-
255
- it "raises an InvalidConstraintFormat error" do
256
- expect {
257
- subject.split(invalid_string)
258
- }.to raise_error(Semverse::InvalidConstraintFormat)
259
- end
260
- end
261
-
262
- context "given a string that does not contain an operator" do
263
- let(:constraint_string) { "1.2.3" }
264
-
265
- it "returns a constraint constraint with a default operator (=)" do
266
- expect(subject[0]).to eq("=")
267
- end
268
- end
269
- end
270
- end
271
-
272
- describe "#satisfies?" do
273
- subject { Semverse::Constraint.new("= 1.0.0") }
274
-
275
- it { should satisfies("1.0.0") }
276
- it { should satisfies(Semverse::Version.new("1.0.0")) }
277
-
278
- context "strictly greater than (>) pre-release constraint" do
279
- subject { Semverse::Constraint.new("> 1.0.0-alpha") }
280
-
281
- it { should_not satisfies("0.9.9+build") }
282
- it { should_not satisfies("1.0.0-alpha") }
283
- it { should satisfies("1.0.0-alpha.2") }
284
- it { should satisfies("1.0.0") }
285
- it { should satisfies("1.0.0+build") }
286
- it { should satisfies("1.0.1-beta") }
287
- it { should satisfies("1.0.1") }
288
- it { should satisfies("1.0.1+build.2") }
289
- it { should satisfies("2.0.0") }
290
- end
291
-
292
- context "strictly greater than (>)" do
293
- subject { Semverse::Constraint.new("> 1.0.0") }
294
-
295
- it { should_not satisfies("0.9.9+build") }
296
- it { should_not satisfies("1.0.0-alpha") }
297
- it { should_not satisfies("1.0.0-alpha.2") }
298
- it { should_not satisfies("1.0.0") }
299
- it { should satisfies("1.0.0+build") }
300
- it { should_not satisfies("1.0.1-beta") }
301
- it { should satisfies("1.0.1") }
302
- it { should satisfies("1.0.1+build.2") }
303
- it { should satisfies("2.0.0") }
304
- end
305
-
306
- context "strictly greater than (>) build constraint" do
307
- subject { Semverse::Constraint.new("> 1.0.0+build") }
308
-
309
- it { should_not satisfies("0.9.9+build") }
310
- it { should_not satisfies("1.0.0-alpha") }
311
- it { should_not satisfies("1.0.0-alpha.2") }
312
- it { should_not satisfies("1.0.0") }
313
- it { should_not satisfies("1.0.0+build") }
314
- it { should_not satisfies("1.0.1-beta") }
315
- it { should satisfies("1.0.1") }
316
- it { should satisfies("1.0.1+build.2") }
317
- it { should satisfies("2.0.0") }
318
- end
319
-
320
- context "greater than or equal to (>) zero pre-release constraint" do
321
- subject { Semverse::Constraint.new("> 0.0.0-alpha") }
322
-
323
- it { should satisfies("0.9.9+build") }
324
- it { should satisfies("1.0.0-alpha") }
325
- it { should satisfies("1.0.0-alpha.2") }
326
- it { should satisfies("1.0.0") }
327
- it { should satisfies("1.0.0+build") }
328
- it { should satisfies("1.0.1-beta") }
329
- it { should satisfies("1.0.1") }
330
- it { should satisfies("1.0.1+build.2") }
331
- it { should satisfies("2.0.0") }
332
- end
333
-
334
- context "greater than or equal to (>) zero constraint" do
335
- subject { Semverse::Constraint.new("> 0.0.0") }
336
-
337
- it { should satisfies("0.9.9+build") }
338
- it { should satisfies("1.0.0-alpha") }
339
- it { should satisfies("1.0.0-alpha.2") }
340
- it { should satisfies("1.0.0") }
341
- it { should satisfies("1.0.0+build") }
342
- it { should satisfies("1.0.1-beta") }
343
- it { should satisfies("1.0.1") }
344
- it { should satisfies("1.0.1+build.2") }
345
- it { should satisfies("2.0.0") }
346
- end
347
-
348
- context "greater than or equal to (>) zero build constraint" do
349
- subject { Semverse::Constraint.new("> 0.0.0+build") }
350
-
351
- it { should satisfies("0.9.9+build") }
352
- it { should satisfies("1.0.0-alpha") }
353
- it { should satisfies("1.0.0-alpha.2") }
354
- it { should satisfies("1.0.0") }
355
- it { should satisfies("1.0.0+build") }
356
- it { should satisfies("1.0.1-beta") }
357
- it { should satisfies("1.0.1") }
358
- it { should satisfies("1.0.1+build.2") }
359
- it { should satisfies("2.0.0") }
360
- end
361
-
362
- context "strictly less than (<) pre-release constraint" do
363
- subject { Semverse::Constraint.new("< 1.0.0-alpha.3") }
364
-
365
- it { should satisfies("0.9.9+build") }
366
- it { should satisfies("1.0.0-alpha") }
367
- it { should satisfies("1.0.0-alpha.2") }
368
- it { should_not satisfies("1.0.0") }
369
- it { should_not satisfies("1.0.0+build") }
370
- it { should_not satisfies("1.0.1-beta") }
371
- it { should_not satisfies("1.0.1") }
372
- it { should_not satisfies("1.0.1+build.2") }
373
- it { should_not satisfies("2.0.0") }
374
- end
375
-
376
- context "strictly less than (<)" do
377
- subject { Semverse::Constraint.new("< 1.0.0") }
378
-
379
- it { should satisfies("0.9.9+build") }
380
- it { should satisfies("1.0.0-alpha") }
381
- it { should satisfies("1.0.0-alpha.2") }
382
- it { should_not satisfies("1.0.0") }
383
- it { should_not satisfies("1.0.0+build") }
384
- it { should_not satisfies("1.0.1-beta") }
385
- it { should_not satisfies("1.0.1") }
386
- it { should_not satisfies("1.0.1+build.2") }
387
- it { should_not satisfies("2.0.0") }
388
- end
389
-
390
- context "strictly less than (<) build constraint" do
391
- subject { Semverse::Constraint.new("< 1.0.0+build.20") }
392
-
393
- it { should satisfies("0.9.9+build") }
394
- it { should satisfies("1.0.0-alpha") }
395
- it { should satisfies("1.0.0-alpha.2") }
396
- it { should satisfies("1.0.0") }
397
- it { should satisfies("1.0.0+build") }
398
- it { should_not satisfies("1.0.1-beta") }
399
- it { should_not satisfies("1.0.1") }
400
- it { should_not satisfies("1.0.1+build.2") }
401
- it { should_not satisfies("2.0.0") }
402
- end
403
-
404
- context "strictly equal to (=)" do
405
- subject { Semverse::Constraint.new("= 1.0.0") }
406
-
407
- it { should_not satisfies("0.9.9+build") }
408
- it { should satisfies("1.0.0") }
409
- it { should_not satisfies("1.0.1") }
410
- it { should_not satisfies("1.0.0-alpha") }
411
- end
412
-
413
- context "greater than or equal to (>=) pre-release constraint" do
414
- subject { Semverse::Constraint.new(">= 1.0.0-alpha") }
415
-
416
- it { should_not satisfies("0.9.9+build") }
417
- it { should satisfies("1.0.0-alpha") }
418
- it { should satisfies("1.0.0-alpha.2") }
419
- it { should satisfies("1.0.0") }
420
- it { should satisfies("1.0.0+build") }
421
- it { should satisfies("1.0.1-beta") }
422
- it { should satisfies("1.0.1") }
423
- it { should satisfies("1.0.1+build.2") }
424
- it { should satisfies("2.0.0") }
425
- end
426
-
427
- context "greater than or equal to (>=)" do
428
- subject { Semverse::Constraint.new(">= 1.0.0") }
429
-
430
- it { should_not satisfies("0.9.9+build") }
431
- it { should_not satisfies("1.0.0-alpha") }
432
- it { should_not satisfies("1.0.0-alpha.2") }
433
- it { should satisfies("1.0.0") }
434
- it { should satisfies("1.0.0+build") }
435
- it { should_not satisfies("1.0.1-beta") }
436
- it { should satisfies("1.0.1") }
437
- it { should satisfies("1.0.1+build.2") }
438
- it { should satisfies("2.0.0") }
439
- end
440
-
441
- context "greater than or equal to (>=) build constraint" do
442
- subject { Semverse::Constraint.new(">= 1.0.0+build") }
443
-
444
- it { should_not satisfies("0.9.9+build") }
445
- it { should_not satisfies("1.0.0-alpha") }
446
- it { should_not satisfies("1.0.0-alpha.2") }
447
- it { should_not satisfies("1.0.0") }
448
- it { should satisfies("1.0.0+build") }
449
- it { should_not satisfies("1.0.1-beta") }
450
- it { should satisfies("1.0.1") }
451
- it { should satisfies("1.0.1+build.2") }
452
- it { should satisfies("2.0.0") }
453
- end
454
-
455
- context "greater than or equal to (>=) zero pre-release constraint" do
456
- subject { Semverse::Constraint.new(">= 0.0.0-alpha") }
457
-
458
- it { should satisfies("0.9.9+build") }
459
- it { should satisfies("1.0.0-alpha") }
460
- it { should satisfies("1.0.0-alpha.2") }
461
- it { should satisfies("1.0.0") }
462
- it { should satisfies("1.0.0+build") }
463
- it { should satisfies("1.0.1-beta") }
464
- it { should satisfies("1.0.1") }
465
- it { should satisfies("1.0.1+build.2") }
466
- it { should satisfies("2.0.0") }
467
- end
468
-
469
- context "greater than or equal to (>=) zero constraint" do
470
- subject { Semverse::Constraint.new(">= 0.0.0") }
471
-
472
- it { should satisfies("0.9.9+build") }
473
- it { should satisfies("1.0.0-alpha") }
474
- it { should satisfies("1.0.0-alpha.2") }
475
- it { should satisfies("1.0.0") }
476
- it { should satisfies("1.0.0+build") }
477
- it { should satisfies("1.0.1-beta") }
478
- it { should satisfies("1.0.1") }
479
- it { should satisfies("1.0.1+build.2") }
480
- it { should satisfies("2.0.0") }
481
- end
482
-
483
- context "greater than or equal to (>=) zero build constraint" do
484
- subject { Semverse::Constraint.new(">= 0.0.0+build") }
485
-
486
- it { should satisfies("0.9.9+build") }
487
- it { should satisfies("1.0.0-alpha") }
488
- it { should satisfies("1.0.0-alpha.2") }
489
- it { should satisfies("1.0.0") }
490
- it { should satisfies("1.0.0+build") }
491
- it { should satisfies("1.0.1-beta") }
492
- it { should satisfies("1.0.1") }
493
- it { should satisfies("1.0.1+build.2") }
494
- it { should satisfies("2.0.0") }
495
- end
496
-
497
- context "lower than or equal to (<=) pre-release constraint" do
498
- subject { Semverse::Constraint.new("<= 1.0.0") }
499
-
500
- it { should satisfies("0.9.9+build") }
501
- it { should satisfies("1.0.0-alpha") }
502
- it { should satisfies("1.0.0-alpha.2") }
503
- it { should satisfies("1.0.0") }
504
- it { should_not satisfies("1.0.0+build") }
505
- it { should_not satisfies("1.0.1-beta") }
506
- it { should_not satisfies("1.0.1") }
507
- it { should_not satisfies("1.0.1+build.2") }
508
- it { should_not satisfies("2.0.0") }
509
- end
510
-
511
- context "lower than or equal to (<=)" do
512
- subject { Semverse::Constraint.new("<= 1.0.0-alpha") }
513
-
514
- it { should satisfies("0.9.9+build") }
515
- it { should satisfies("1.0.0-alpha") }
516
- it { should_not satisfies("1.0.0-alpha.2") }
517
- it { should_not satisfies("1.0.0") }
518
- it { should_not satisfies("1.0.0+build") }
519
- it { should_not satisfies("1.0.1-beta") }
520
- it { should_not satisfies("1.0.1") }
521
- it { should_not satisfies("1.0.1+build.2") }
522
- it { should_not satisfies("2.0.0") }
523
- end
524
-
525
- context "lower than or equal to (<=) build constraint" do
526
- subject { Semverse::Constraint.new("<= 1.0.0+build") }
527
-
528
- it { should satisfies("0.9.9+build") }
529
- it { should satisfies("1.0.0-alpha") }
530
- it { should satisfies("1.0.0-alpha.2") }
531
- it { should satisfies("1.0.0") }
532
- it { should satisfies("1.0.0+build") }
533
- it { should_not satisfies("1.0.1-beta") }
534
- it { should_not satisfies("1.0.1") }
535
- it { should_not satisfies("1.0.1+build.2") }
536
- it { should_not satisfies("2.0.0") }
537
- end
538
-
539
- %w[~> ~].each do |operator|
540
- describe "aproximately (#{operator})" do
541
- context "when the last value in the constraint is for minor" do
542
- subject { Semverse::Constraint.new("#{operator} 1.2") }
543
-
544
- it { should_not satisfies("1.1.0") }
545
- it { should_not satisfies("1.2.0-alpha") }
546
- it { should satisfies("1.2.0") }
547
- it { should satisfies("1.2.3") }
548
- it { should satisfies("1.2.3+build") }
549
- it { should satisfies("1.3") }
550
- it { should satisfies("1.3.0") }
551
- it { should_not satisfies("2.0.0-0") }
552
- it { should_not satisfies("2.0.0") }
553
- end
554
-
555
- context "when the last value in the constraint is for patch" do
556
- subject { Semverse::Constraint.new("#{operator} 1.2.0") }
557
-
558
- it { should_not satisfies("1.1.0") }
559
- it { should_not satisfies("1.2.3-alpha") }
560
- it { should satisfies("1.2.2") }
561
- it { should satisfies("1.2.3") }
562
- it { should satisfies("1.2.5+build") }
563
- it { should_not satisfies("1.3.0-0") }
564
- it { should_not satisfies("1.3.0") }
565
- end
566
-
567
- context "when the last value in the constraint is for pre_release with a last numeric identifier" do
568
- subject { Semverse::Constraint.new("#{operator} 1.2.3-4") }
569
-
570
- it { should_not satisfies("1.2.3") }
571
- it { should satisfies("1.2.3-4") }
572
- it { should satisfies("1.2.3-10") }
573
- it { should satisfies("1.2.3-10.5+build.33") }
574
- it { should_not satisfies("1.2.3--") }
575
- it { should_not satisfies("1.2.3-alpha") }
576
- it { should_not satisfies("1.2.3") }
577
- it { should_not satisfies("1.2.4") }
578
- it { should_not satisfies("1.3.0") }
579
- end
580
-
581
- context "when the last value in the constraint is for pre_release with a last non-numeric identifier" do
582
- subject { Semverse::Constraint.new("#{operator} 1.2.3-alpha") }
583
-
584
- it { should_not satisfies("1.2.3-4") }
585
- it { should_not satisfies("1.2.3--") }
586
- it { should satisfies("1.2.3-alpha") }
587
- it { should satisfies("1.2.3-alpha.0") }
588
- it { should satisfies("1.2.3-beta") }
589
- it { should satisfies("1.2.3-omega") }
590
- it { should satisfies("1.2.3-omega.4") }
591
- it { should_not satisfies("1.2.3") }
592
- it { should_not satisfies("1.3.0") }
593
- end
594
-
595
- context "when the last value in the constraint is for build with a last numeric identifier and a pre-release" do
596
- subject { Semverse::Constraint.new("#{operator} 1.2.3-alpha+5") }
597
-
598
- it { should_not satisfies("1.2.3-alpha") }
599
- it { should_not satisfies("1.2.3-alpha.4") }
600
- it { should_not satisfies("1.2.3-alpha.4+4") }
601
- it { should satisfies("1.2.3-alpha+5") }
602
- it { should satisfies("1.2.3-alpha+5.5") }
603
- it { should satisfies("1.2.3-alpha+10") }
604
- it { should_not satisfies("1.2.3-alpha+-") }
605
- it { should_not satisfies("1.2.3-alpha+build") }
606
- it { should_not satisfies("1.2.3-beta") }
607
- it { should_not satisfies("1.2.3") }
608
- it { should_not satisfies("1.3.0") }
609
- end
610
-
611
- context "when the last value in the constraint is for build with a last non-numeric identifier and a pre-release" do
612
- subject { Semverse::Constraint.new("#{operator} 1.2.3-alpha+build") }
613
-
614
- it { should_not satisfies("1.2.3-alpha") }
615
- it { should_not satisfies("1.2.3-alpha.4") }
616
- it { should_not satisfies("1.2.3-alpha.4+4") }
617
- it { should satisfies("1.2.3-alpha+build") }
618
- it { should satisfies("1.2.3-alpha+build.5") }
619
- it { should satisfies("1.2.3-alpha+preview") }
620
- it { should satisfies("1.2.3-alpha+zzz") }
621
- it { should_not satisfies("1.2.3-alphb") }
622
- it { should_not satisfies("1.2.3-beta") }
623
- it { should_not satisfies("1.2.3") }
624
- it { should_not satisfies("1.3.0") }
625
- end
626
-
627
- context "when the last value in the constraint is for build with a last numeric identifier" do
628
- subject { Semverse::Constraint.new("#{operator} 1.2.3+5") }
629
-
630
- it { should_not satisfies("1.2.3") }
631
- it { should_not satisfies("1.2.3-alpha") }
632
- it { should_not satisfies("1.2.3+4") }
633
- it { should satisfies("1.2.3+5") }
634
- it { should satisfies("1.2.3+99") }
635
- it { should_not satisfies("1.2.3+5.build") }
636
- it { should_not satisfies("1.2.3+-") }
637
- it { should_not satisfies("1.2.3+build") }
638
- it { should_not satisfies("1.2.4") }
639
- it { should_not satisfies("1.3.0") }
640
- end
641
-
642
- context "when the last value in the constraint is for build with a last non-numeric identifier" do
643
- subject { Semverse::Constraint.new("#{operator} 1.2.3+build") }
644
-
645
- it { should_not satisfies("1.2.3-alpha") }
646
- it { should_not satisfies("1.2.3") }
647
- it { should_not satisfies("1.2.3+5") }
648
- it { should satisfies("1.2.3+build") }
649
- it { should satisfies("1.2.3+build.5") }
650
- it { should satisfies("1.2.3+preview") }
651
- it { should satisfies("1.2.3+zzz") }
652
- it { should_not satisfies("1.2.4-0") }
653
- it { should_not satisfies("1.2.4") }
654
- it { should_not satisfies("1.2.5") }
655
- it { should_not satisfies("1.3.0") }
656
- end
657
- end
658
- end
659
- end
660
-
661
- describe "#==" do
662
- subject { Semverse::Constraint.new("= 1.0.0") }
663
-
664
- it "returns true if the other object is a Semverse::Constraint with the same operator and version" do
665
- other = Semverse::Constraint.new("= 1.0.0")
666
- expect(subject).to eq(other)
667
- end
668
-
669
- it "returns false if the other object is a Semverse::Constraint with the same operator and different version" do
670
- other = Semverse::Constraint.new("= 9.9.9")
671
- expect(subject).to_not eq(other)
672
- end
673
-
674
- it "returns false if the other object is a Semverse::Constraint with the same version and different operator" do
675
- other = Semverse::Constraint.new("> 1.0.0")
676
- expect(subject).to_not eq(other)
677
- end
678
-
679
- it "returns false if the other object is not a Semverse::Constraint" do
680
- other = "chicken"
681
- expect(subject).to_not eq(other)
682
- end
683
- end
684
-
685
- describe "#to_s" do
686
- let(:constraint_string) { ">= 1.2.3-alpha+123" }
687
- subject { described_class.new(constraint_string).to_s }
688
-
689
- it { should eq(constraint_string) }
690
-
691
- context "when the constraint does not contain a minor or patch value" do
692
- let(:constraint_string) { "~> 1" }
693
- it { should eq(constraint_string) }
694
- end
695
-
696
- context "when the constraint does not contain a patch value" do
697
- let(:constraint_string) { "~> 1.2" }
698
- it { should eq(constraint_string) }
699
- end
700
-
701
- context "when the constraint does not contain a build value" do
702
- let(:constraint_string) { ">= 1.2.0-alpha"}
703
- it { should eq(constraint_string) }
704
- end
705
-
706
- context "when the constraint contains a pre_release value" do
707
- let(:constraint_string) { ">= 1.2.0+123"}
708
- it { should eq(constraint_string) }
709
- end
710
- end
711
- end