File: constraint_spec.rb

package info (click to toggle)
ruby-semverse 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 216 kB
  • sloc: ruby: 1,146; makefile: 3
file content (711 lines) | stat: -rw-r--r-- 25,596 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
require 'spec_helper'

RSpec::Matchers.define :satisfies do |*args|
  match do |constraint|
    expect(constraint.satisfies?(*args)).to be true
  end
end

describe Semverse::Constraint do
  let(:valid_string) { ">= 0.0.0" }
  let(:invalid_string) { "x23u7089213.*" }

  describe "ClassMethods" do
    subject { Semverse::Constraint }

    describe "::new" do
      it "returns a new instance of Constraint" do
        expect(subject.new(valid_string)).to be_a(Semverse::Constraint)
      end

      it "assigns the parsed operator to the operator attribute" do
        expect(subject.new(valid_string).operator).to eq(">=")
      end

      it "assigns the parsed operator to the operator attribute with no separation between operator and version" do
        expect(subject.new(">=0.0.0").operator).to eq(">=")
      end

      it "assigns the parsed version string as an instance of Version to the version attribute" do
        result = subject.new(valid_string)

        expect(result.version).to be_a(Semverse::Version)
        expect(result.version.to_s).to eq("0.0.0")
      end

      it "falls back to a default constraint if nil is provided" do
        result = subject.new(nil)

        expect(result.version.to_s).to eq("0.0.0")
        expect(result.operator).to eq(">=")
      end

      it "fall sback to a default constraint if a blank string is provided" do
        result = subject.new("")

        expect(result.version.to_s).to eq("0.0.0")
        expect(result.operator).to eq(">=")
      end

      context "given a string that does not match the Constraint REGEXP" do
        it "raises an InvalidConstraintFormat error" do
          expect {
            subject.new(invalid_string)
          }.to raise_error(Semverse::InvalidConstraintFormat)
        end
      end

      context "given a constraint that does not include a minor version (~>)" do
        it "has a nil value for minor" do
          expect(subject.new("~> 1").minor).to be_nil
        end

        it "has a nil value for patch" do
          expect(subject.new("~> 1").patch).to be_nil
        end
      end

      context "given a constraint that does not include a minor version (=)" do
        it "has a 0 for minor" do
          expect(subject.new("= 1").minor).to eq(0)
        end
      end

      context "given a constraint that does not include a patch version (~>)" do
        it "has a nil value for patch" do
          expect(subject.new("~> 1.2").patch).to be_nil
        end
      end

      context "given a constraint that does not include a patch version (=)" do
        it "has a 0 for patch" do
          expect(subject.new("= 1.2").patch).to eq(0)
        end
      end

      context "given a constraint that does not include a build version" do
        it "has a nil value for build" do
          expect(subject.new(">= 1.2.3-alpha").build).to be_nil
        end
      end

      context "given a constraint that does not include a pre release version" do
        it "has a nil value for pre release" do
          expect(subject.new(">= 1.2.3+build").pre_release).to be_nil
        end
      end
    end

    describe "::split" do
      let(:constraint_string) { nil }

      subject { described_class.split(constraint_string) }

      context "given a constraint containing the elements (operator, major, minor, patch, pre_release, build)" do
        let(:constraint_string) { ">= 1.2.3-alpha+build" }

        it "returns an array with the constraint operator at index 0" do
          expect(subject[0]).to eq(">=")
        end

        it "returns an array with the major version in index 1" do
          expect(subject[1]).to eq(1)
        end

        it "returns an array with the minor version at index 2" do
          expect(subject[2]).to eq(2)
        end

        it "returns an array with the patch version at index 3" do
          expect(subject[3]).to eq(3)
        end

        it "returns an array with the pre release version at index 4" do
          expect(subject[4]).to eq("alpha")
        end

        it "returns an array with the build version at index 5" do
          expect(subject[5]).to eq("build")
        end
      end

      context "given a constraint containing the elements (operator, major, minor, patch, pre_release)" do
        let(:constraint_string) { ">= 1.2.3-alpha" }

        it "returns an array with the constraint operator at index 0" do
          expect(subject[0]).to eq(">=")
        end

        it "returns an array with the major version in index 1" do
          expect(subject[1]).to eq(1)
        end

        it "returns an array with the minor version at index 2" do
          expect(subject[2]).to eq(2)
        end

        it "returns an array with the patch version at index 3" do
          expect(subject[3]).to eq(3)
        end

        it "returns an array with the pre release version at index 4" do
          expect(subject[4]).to eq("alpha")
        end

        it "returns an array with a nil value at index 5" do
          expect(subject[5]).to be_nil
        end
      end

      context "given a constraint containing the elements (operator, major, minor, patch)" do
        let(:constraint_string) { ">= 1.2.3" }

        it "returns an array with the constraint operator at index 0" do
          expect(subject[0]).to eq(">=")
        end

        it "returns an array with the major version in index 1" do
          expect(subject[1]).to eq(1)
        end

        it "returns an array with the minor version at index 2" do
          expect(subject[2]).to eq(2)
        end

        it "returns an array with the patch version at index 3" do
          expect(subject[3]).to eq(3)
        end

        it "returns an array with a nil value at index 4" do
          expect(subject[4]).to be_nil
        end

        it "returns an array with a nil value at index 5" do
          expect(subject[5]).to be_nil
        end
      end

      context "given a constraint containing the elements (operator, major, minor)" do
        let(:constraint_string) { ">= 1.2" }

        it "returns an array with the constraint operator at index 0" do
          expect(subject[0]).to eq(">=")
        end

        it "returns an array with the major version in index 1" do
          expect(subject[1]).to eq(1)
        end

        it "returns an array with the minor version at index 2" do
          expect(subject[2]).to eq(2)
        end

        it "returns an array with a nil value at index 3" do
          expect(subject[3]).to be_nil
        end

        it "returns an array with a nil value at index 4" do
          expect(subject[4]).to be_nil
        end

        it "returns an array with a nil value at index 5" do
          expect(subject[5]).to be_nil
        end
      end

      context "given a constraint containing the elements (operator, major)" do
        let(:constraint_string) { ">= 1" }

        it "returns an array with the constraint operator at index 0" do
          expect(subject[0]).to eq(">=")
        end

        it "returns an array with the major version in index 1" do
          expect(subject[1]).to eq(1)
        end

        it "returns an array with a nil value at index 2" do
          expect(subject[2]).to be_nil
        end

        it "returns an array with a nil value at index 3" do
          expect(subject[3]).to be_nil
        end

        it "returns an array with a nil value at index 4" do
          expect(subject[4]).to be_nil
        end

        it "returns an array with a nil value at index 5" do
          expect(subject[5]).to be_nil
        end
      end

      context "given a constraint which is missing an operator" do
        let(:constraint_string) { "1.2.3" }

        it "returns an equality operator at index 0" do
          expect(subject[0]).to eq("=")
        end
      end

      context "given a string that does not match the Constraint REGEXP" do
        let(:constraint_string) { "x23u7089213.*" }

        it "raises an InvalidConstraintFormat error" do
          expect {
            subject.split(invalid_string)
          }.to raise_error(Semverse::InvalidConstraintFormat)
        end
      end

      context "given a string that does not contain an operator" do
        let(:constraint_string) { "1.2.3" }

        it "returns a constraint constraint with a default operator (=)" do
          expect(subject[0]).to eq("=")
        end
      end
    end
  end

  describe "#satisfies?" do
    subject { Semverse::Constraint.new("= 1.0.0") }

    it { should satisfies("1.0.0") }
    it { should satisfies(Semverse::Version.new("1.0.0")) }

    context "strictly greater than (>) pre-release constraint" do
      subject { Semverse::Constraint.new("> 1.0.0-alpha") }

      it { should_not satisfies("0.9.9+build") }
      it { should_not satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "strictly greater than (>)" do
      subject { Semverse::Constraint.new("> 1.0.0") }

      it { should_not satisfies("0.9.9+build") }
      it { should_not satisfies("1.0.0-alpha") }
      it { should_not satisfies("1.0.0-alpha.2") }
      it { should_not satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should_not satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "strictly greater than (>) build constraint" do
      subject { Semverse::Constraint.new("> 1.0.0+build") }

      it { should_not satisfies("0.9.9+build") }
      it { should_not satisfies("1.0.0-alpha") }
      it { should_not satisfies("1.0.0-alpha.2") }
      it { should_not satisfies("1.0.0") }
      it { should_not satisfies("1.0.0+build") }
      it { should_not satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "greater than or equal to (>) zero pre-release constraint" do
      subject { Semverse::Constraint.new("> 0.0.0-alpha") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "greater than or equal to (>) zero constraint" do
      subject { Semverse::Constraint.new("> 0.0.0") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "greater than or equal to (>) zero build constraint" do
      subject { Semverse::Constraint.new("> 0.0.0+build") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "strictly less than (<) pre-release constraint" do
      subject { Semverse::Constraint.new("< 1.0.0-alpha.3") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should_not satisfies("1.0.0") }
      it { should_not satisfies("1.0.0+build") }
      it { should_not satisfies("1.0.1-beta") }
      it { should_not satisfies("1.0.1") }
      it { should_not satisfies("1.0.1+build.2") }
      it { should_not satisfies("2.0.0") }
    end

    context "strictly less than (<)" do
      subject { Semverse::Constraint.new("< 1.0.0") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should_not satisfies("1.0.0") }
      it { should_not satisfies("1.0.0+build") }
      it { should_not satisfies("1.0.1-beta") }
      it { should_not satisfies("1.0.1") }
      it { should_not satisfies("1.0.1+build.2") }
      it { should_not satisfies("2.0.0") }
    end

    context "strictly less than (<) build constraint" do
      subject { Semverse::Constraint.new("< 1.0.0+build.20") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should_not satisfies("1.0.1-beta") }
      it { should_not satisfies("1.0.1") }
      it { should_not satisfies("1.0.1+build.2") }
      it { should_not satisfies("2.0.0") }
    end

    context "strictly equal to (=)" do
      subject { Semverse::Constraint.new("= 1.0.0") }

      it { should_not satisfies("0.9.9+build") }
      it { should satisfies("1.0.0") }
      it { should_not satisfies("1.0.1") }
      it { should_not satisfies("1.0.0-alpha") }
    end

    context "greater than or equal to (>=) pre-release constraint" do
      subject { Semverse::Constraint.new(">= 1.0.0-alpha") }

      it { should_not satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "greater than or equal to (>=)" do
      subject { Semverse::Constraint.new(">= 1.0.0") }

      it { should_not satisfies("0.9.9+build") }
      it { should_not satisfies("1.0.0-alpha") }
      it { should_not satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should_not satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "greater than or equal to (>=) build constraint" do
      subject { Semverse::Constraint.new(">= 1.0.0+build") }

      it { should_not satisfies("0.9.9+build") }
      it { should_not satisfies("1.0.0-alpha") }
      it { should_not satisfies("1.0.0-alpha.2") }
      it { should_not satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should_not satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "greater than or equal to (>=) zero pre-release constraint" do
      subject { Semverse::Constraint.new(">= 0.0.0-alpha") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "greater than or equal to (>=) zero constraint" do
      subject { Semverse::Constraint.new(">= 0.0.0") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "greater than or equal to (>=) zero build constraint" do
      subject { Semverse::Constraint.new(">= 0.0.0+build") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should satisfies("1.0.1-beta") }
      it { should satisfies("1.0.1") }
      it { should satisfies("1.0.1+build.2") }
      it { should satisfies("2.0.0") }
    end

    context "lower than or equal to (<=) pre-release constraint" do
      subject { Semverse::Constraint.new("<= 1.0.0") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should_not satisfies("1.0.0+build") }
      it { should_not satisfies("1.0.1-beta") }
      it { should_not satisfies("1.0.1") }
      it { should_not satisfies("1.0.1+build.2") }
      it { should_not satisfies("2.0.0") }
    end

    context "lower than or equal to (<=)" do
      subject { Semverse::Constraint.new("<= 1.0.0-alpha") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should_not satisfies("1.0.0-alpha.2") }
      it { should_not satisfies("1.0.0") }
      it { should_not satisfies("1.0.0+build") }
      it { should_not satisfies("1.0.1-beta") }
      it { should_not satisfies("1.0.1") }
      it { should_not satisfies("1.0.1+build.2") }
      it { should_not satisfies("2.0.0") }
    end

    context "lower than or equal to (<=) build constraint" do
      subject { Semverse::Constraint.new("<= 1.0.0+build") }

      it { should satisfies("0.9.9+build") }
      it { should satisfies("1.0.0-alpha") }
      it { should satisfies("1.0.0-alpha.2") }
      it { should satisfies("1.0.0") }
      it { should satisfies("1.0.0+build") }
      it { should_not satisfies("1.0.1-beta") }
      it { should_not satisfies("1.0.1") }
      it { should_not satisfies("1.0.1+build.2") }
      it { should_not satisfies("2.0.0") }
    end

    %w[~> ~].each do |operator|
      describe "aproximately (#{operator})" do
        context "when the last value in the constraint is for minor" do
          subject { Semverse::Constraint.new("#{operator} 1.2") }

          it { should_not satisfies("1.1.0") }
          it { should_not satisfies("1.2.0-alpha") }
          it { should satisfies("1.2.0") }
          it { should satisfies("1.2.3") }
          it { should satisfies("1.2.3+build") }
          it { should satisfies("1.3") }
          it { should satisfies("1.3.0") }
          it { should_not satisfies("2.0.0-0") }
          it { should_not satisfies("2.0.0") }
        end

        context "when the last value in the constraint is for patch" do
          subject { Semverse::Constraint.new("#{operator} 1.2.0") }

          it { should_not satisfies("1.1.0") }
          it { should_not satisfies("1.2.3-alpha") }
          it { should satisfies("1.2.2") }
          it { should satisfies("1.2.3") }
          it { should satisfies("1.2.5+build") }
          it { should_not satisfies("1.3.0-0") }
          it { should_not satisfies("1.3.0") }
        end

        context "when the last value in the constraint is for pre_release with a last numeric identifier" do
          subject { Semverse::Constraint.new("#{operator} 1.2.3-4") }

          it { should_not satisfies("1.2.3") }
          it { should satisfies("1.2.3-4") }
          it { should satisfies("1.2.3-10") }
          it { should satisfies("1.2.3-10.5+build.33") }
          it { should_not satisfies("1.2.3--") }
          it { should_not satisfies("1.2.3-alpha") }
          it { should_not satisfies("1.2.3") }
          it { should_not satisfies("1.2.4") }
          it { should_not satisfies("1.3.0") }
        end

        context "when the last value in the constraint is for pre_release with a last non-numeric identifier" do
          subject { Semverse::Constraint.new("#{operator} 1.2.3-alpha") }

          it { should_not satisfies("1.2.3-4") }
          it { should_not satisfies("1.2.3--") }
          it { should satisfies("1.2.3-alpha") }
          it { should satisfies("1.2.3-alpha.0") }
          it { should satisfies("1.2.3-beta") }
          it { should satisfies("1.2.3-omega") }
          it { should satisfies("1.2.3-omega.4") }
          it { should_not satisfies("1.2.3") }
          it { should_not satisfies("1.3.0") }
        end

        context "when the last value in the constraint is for build with a last numeric identifier and a pre-release" do
          subject { Semverse::Constraint.new("#{operator} 1.2.3-alpha+5") }

          it { should_not satisfies("1.2.3-alpha") }
          it { should_not satisfies("1.2.3-alpha.4") }
          it { should_not satisfies("1.2.3-alpha.4+4") }
          it { should satisfies("1.2.3-alpha+5") }
          it { should satisfies("1.2.3-alpha+5.5") }
          it { should satisfies("1.2.3-alpha+10") }
          it { should_not satisfies("1.2.3-alpha+-") }
          it { should_not satisfies("1.2.3-alpha+build") }
          it { should_not satisfies("1.2.3-beta") }
          it { should_not satisfies("1.2.3") }
          it { should_not satisfies("1.3.0") }
        end

        context "when the last value in the constraint is for build with a last non-numeric identifier and a pre-release" do
          subject { Semverse::Constraint.new("#{operator} 1.2.3-alpha+build") }

          it { should_not satisfies("1.2.3-alpha") }
          it { should_not satisfies("1.2.3-alpha.4") }
          it { should_not satisfies("1.2.3-alpha.4+4") }
          it { should satisfies("1.2.3-alpha+build") }
          it { should satisfies("1.2.3-alpha+build.5") }
          it { should satisfies("1.2.3-alpha+preview") }
          it { should satisfies("1.2.3-alpha+zzz") }
          it { should_not satisfies("1.2.3-alphb") }
          it { should_not satisfies("1.2.3-beta") }
          it { should_not satisfies("1.2.3") }
          it { should_not satisfies("1.3.0") }
        end

        context "when the last value in the constraint is for build with a last numeric identifier" do
          subject { Semverse::Constraint.new("#{operator} 1.2.3+5") }

          it { should_not satisfies("1.2.3") }
          it { should_not satisfies("1.2.3-alpha") }
          it { should_not satisfies("1.2.3+4") }
          it { should satisfies("1.2.3+5") }
          it { should satisfies("1.2.3+99") }
          it { should_not satisfies("1.2.3+5.build") }
          it { should_not satisfies("1.2.3+-") }
          it { should_not satisfies("1.2.3+build") }
          it { should_not satisfies("1.2.4") }
          it { should_not satisfies("1.3.0") }
        end

        context "when the last value in the constraint is for build with a last non-numeric identifier" do
          subject { Semverse::Constraint.new("#{operator} 1.2.3+build") }

          it { should_not satisfies("1.2.3-alpha") }
          it { should_not satisfies("1.2.3") }
          it { should_not satisfies("1.2.3+5") }
          it { should satisfies("1.2.3+build") }
          it { should satisfies("1.2.3+build.5") }
          it { should satisfies("1.2.3+preview") }
          it { should satisfies("1.2.3+zzz") }
          it { should_not satisfies("1.2.4-0") }
          it { should_not satisfies("1.2.4") }
          it { should_not satisfies("1.2.5") }
          it { should_not satisfies("1.3.0") }
        end
      end
    end
  end

  describe "#==" do
    subject { Semverse::Constraint.new("= 1.0.0") }

    it "returns true if the other object is a Semverse::Constraint with the same operator and version" do
      other = Semverse::Constraint.new("= 1.0.0")
      expect(subject).to eq(other)
    end

    it "returns false if the other object is a Semverse::Constraint with the same operator and different version" do
      other = Semverse::Constraint.new("= 9.9.9")
      expect(subject).to_not eq(other)
    end

    it "returns false if the other object is a Semverse::Constraint with the same version and different operator" do
      other = Semverse::Constraint.new("> 1.0.0")
      expect(subject).to_not eq(other)
    end

    it "returns false if the other object is not a Semverse::Constraint" do
      other = "chicken"
      expect(subject).to_not eq(other)
    end
  end

  describe "#to_s" do
    let(:constraint_string) { ">= 1.2.3-alpha+123" }
    subject { described_class.new(constraint_string).to_s }

    it { should eq(constraint_string) }

    context "when the constraint does not contain a minor or patch value" do
      let(:constraint_string) { "~> 1" }
      it { should eq(constraint_string) }
    end

    context "when the constraint does not contain a patch value" do
      let(:constraint_string) { "~> 1.2" }
      it { should eq(constraint_string) }
    end

    context "when the constraint does not contain a build value" do
      let(:constraint_string) { ">= 1.2.0-alpha"}
      it { should eq(constraint_string) }
    end

    context "when the constraint contains a pre_release value" do
      let(:constraint_string) { ">= 1.2.0+123"}
      it { should eq(constraint_string) }
    end
  end
end