semverse 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/semverse.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'semverse/gem_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "semverse"
8
+ spec.version = Semverse::VERSION
9
+ spec.authors = ["Jamie Winsor"]
10
+ spec.email = ["jamie@vialstudios.com"]
11
+ spec.summary = %q{An elegant library for representing and comparing SemVer versions and constraints}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/berkshelf/semverse"
14
+ spec.license = "Apache 2.0"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = ">= 1.9.1"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'spork'
4
+
5
+ Spork.prefork do
6
+ require 'rspec'
7
+
8
+ APP_ROOT = File.expand_path('../../', __FILE__)
9
+
10
+ Dir[File.join(APP_ROOT, "spec/support/**/*.rb")].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ config.mock_with :rspec
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.filter_run focus: true
16
+ config.run_all_when_everything_filtered = true
17
+
18
+ # Run specs in a random order
19
+ config.order = :random
20
+ end
21
+ end
22
+
23
+ Spork.each_run do
24
+ require 'semverse'
25
+ end
@@ -0,0 +1,697 @@
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
+ context "given a string that does not match the Constraint REGEXP" do
37
+ it "raises an InvalidConstraintFormat error" do
38
+ expect {
39
+ subject.new(invalid_string)
40
+ }.to raise_error(Semverse::InvalidConstraintFormat)
41
+ end
42
+ end
43
+
44
+ context "given a constraint that does not include a minor version (~>)" do
45
+ it "has a nil value for minor" do
46
+ expect(subject.new("~> 1").minor).to be_nil
47
+ end
48
+
49
+ it "has a nil value for patch" do
50
+ expect(subject.new("~> 1").patch).to be_nil
51
+ end
52
+ end
53
+
54
+ context "given a constraint that does not include a minor version (=)" do
55
+ it "has a 0 for minor" do
56
+ expect(subject.new("= 1").minor).to eq(0)
57
+ end
58
+ end
59
+
60
+ context "given a constraint that does not include a patch version (~>)" do
61
+ it "has a nil value for patch" do
62
+ expect(subject.new("~> 1.2").patch).to be_nil
63
+ end
64
+ end
65
+
66
+ context "given a constraint that does not include a patch version (=)" do
67
+ it "has a 0 for patch" do
68
+ expect(subject.new("= 1.2").patch).to eq(0)
69
+ end
70
+ end
71
+
72
+ context "given a constraint that does not include a build version" do
73
+ it "has a nil value for build" do
74
+ expect(subject.new(">= 1.2.3-alpha").build).to be_nil
75
+ end
76
+ end
77
+
78
+ context "given a constraint that does not include a pre release version" do
79
+ it "has a nil value for pre release" do
80
+ expect(subject.new(">= 1.2.3+build").pre_release).to be_nil
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "::split" do
86
+ let(:constraint_string) { nil }
87
+
88
+ subject { described_class.split(constraint_string) }
89
+
90
+ context "given a constraint containing the elements (operator, major, minor, patch, pre_release, build)" do
91
+ let(:constraint_string) { ">= 1.2.3-alpha+build" }
92
+
93
+ it "returns an array with the constraint operator at index 0" do
94
+ expect(subject[0]).to eq(">=")
95
+ end
96
+
97
+ it "returns an array with the major version in index 1" do
98
+ expect(subject[1]).to eq(1)
99
+ end
100
+
101
+ it "returns an array with the minor version at index 2" do
102
+ expect(subject[2]).to eq(2)
103
+ end
104
+
105
+ it "returns an array with the patch version at index 3" do
106
+ expect(subject[3]).to eq(3)
107
+ end
108
+
109
+ it "returns an array with the pre release version at index 4" do
110
+ expect(subject[4]).to eq("alpha")
111
+ end
112
+
113
+ it "returns an array with the build version at index 5" do
114
+ expect(subject[5]).to eq("build")
115
+ end
116
+ end
117
+
118
+ context "given a constraint containing the elements (operator, major, minor, patch, pre_release)" do
119
+ let(:constraint_string) { ">= 1.2.3-alpha" }
120
+
121
+ it "returns an array with the constraint operator at index 0" do
122
+ expect(subject[0]).to eq(">=")
123
+ end
124
+
125
+ it "returns an array with the major version in index 1" do
126
+ expect(subject[1]).to eq(1)
127
+ end
128
+
129
+ it "returns an array with the minor version at index 2" do
130
+ expect(subject[2]).to eq(2)
131
+ end
132
+
133
+ it "returns an array with the patch version at index 3" do
134
+ expect(subject[3]).to eq(3)
135
+ end
136
+
137
+ it "returns an array with the pre release version at index 4" do
138
+ expect(subject[4]).to eq("alpha")
139
+ end
140
+
141
+ it "returns an array with a nil value at index 5" do
142
+ expect(subject[5]).to be_nil
143
+ end
144
+ end
145
+
146
+ context "given a constraint containing the elements (operator, major, minor, patch)" do
147
+ let(:constraint_string) { ">= 1.2.3" }
148
+
149
+ it "returns an array with the constraint operator at index 0" do
150
+ expect(subject[0]).to eq(">=")
151
+ end
152
+
153
+ it "returns an array with the major version in index 1" do
154
+ expect(subject[1]).to eq(1)
155
+ end
156
+
157
+ it "returns an array with the minor version at index 2" do
158
+ expect(subject[2]).to eq(2)
159
+ end
160
+
161
+ it "returns an array with the patch version at index 3" do
162
+ expect(subject[3]).to eq(3)
163
+ end
164
+
165
+ it "returns an array with a nil value at index 4" do
166
+ expect(subject[4]).to be_nil
167
+ end
168
+
169
+ it "returns an array with a nil value at index 5" do
170
+ expect(subject[5]).to be_nil
171
+ end
172
+ end
173
+
174
+ context "given a constraint containing the elements (operator, major, minor)" do
175
+ let(:constraint_string) { ">= 1.2" }
176
+
177
+ it "returns an array with the constraint operator at index 0" do
178
+ expect(subject[0]).to eq(">=")
179
+ end
180
+
181
+ it "returns an array with the major version in index 1" do
182
+ expect(subject[1]).to eq(1)
183
+ end
184
+
185
+ it "returns an array with the minor version at index 2" do
186
+ expect(subject[2]).to eq(2)
187
+ end
188
+
189
+ it "returns an array with a nil value at index 3" do
190
+ expect(subject[3]).to be_nil
191
+ end
192
+
193
+ it "returns an array with a nil value at index 4" do
194
+ expect(subject[4]).to be_nil
195
+ end
196
+
197
+ it "returns an array with a nil value at index 5" do
198
+ expect(subject[5]).to be_nil
199
+ end
200
+ end
201
+
202
+ context "given a constraint containing the elements (operator, major)" do
203
+ let(:constraint_string) { ">= 1" }
204
+
205
+ it "returns an array with the constraint operator at index 0" do
206
+ expect(subject[0]).to eq(">=")
207
+ end
208
+
209
+ it "returns an array with the major version in index 1" do
210
+ expect(subject[1]).to eq(1)
211
+ end
212
+
213
+ it "returns an array with a nil value at index 2" do
214
+ expect(subject[2]).to be_nil
215
+ end
216
+
217
+ it "returns an array with a nil value at index 3" do
218
+ expect(subject[3]).to be_nil
219
+ end
220
+
221
+ it "returns an array with a nil value at index 4" do
222
+ expect(subject[4]).to be_nil
223
+ end
224
+
225
+ it "returns an array with a nil value at index 5" do
226
+ expect(subject[5]).to be_nil
227
+ end
228
+ end
229
+
230
+ context "given a constraint which is missing an operator" do
231
+ let(:constraint_string) { "1.2.3" }
232
+
233
+ it "returns an equality operator at index 0" do
234
+ expect(subject[0]).to eq("=")
235
+ end
236
+ end
237
+
238
+ context "given a string that does not match the Constraint REGEXP" do
239
+ let(:constraint_string) { "x23u7089213.*" }
240
+
241
+ it "raises an InvalidConstraintFormat error" do
242
+ expect {
243
+ subject.split(invalid_string)
244
+ }.to raise_error(Semverse::InvalidConstraintFormat)
245
+ end
246
+ end
247
+
248
+ context "given a string that does not contain an operator" do
249
+ let(:constraint_string) { "1.2.3" }
250
+
251
+ it "returns a constraint constraint with a default operator (=)" do
252
+ expect(subject[0]).to eq("=")
253
+ end
254
+ end
255
+ end
256
+ end
257
+
258
+ describe "#satisfies?" do
259
+ subject { Semverse::Constraint.new("= 1.0.0") }
260
+
261
+ it { should satisfies("1.0.0") }
262
+ it { should satisfies(Semverse::Version.new("1.0.0")) }
263
+
264
+ context "strictly greater than (>) pre-release constraint" do
265
+ subject { Semverse::Constraint.new("> 1.0.0-alpha") }
266
+
267
+ it { should_not satisfies("0.9.9+build") }
268
+ it { should_not satisfies("1.0.0-alpha") }
269
+ it { should satisfies("1.0.0-alpha.2") }
270
+ it { should satisfies("1.0.0") }
271
+ it { should satisfies("1.0.0+build") }
272
+ it { should satisfies("1.0.1-beta") }
273
+ it { should satisfies("1.0.1") }
274
+ it { should satisfies("1.0.1+build.2") }
275
+ it { should satisfies("2.0.0") }
276
+ end
277
+
278
+ context "strictly greater than (>)" do
279
+ subject { Semverse::Constraint.new("> 1.0.0") }
280
+
281
+ it { should_not satisfies("0.9.9+build") }
282
+ it { should_not satisfies("1.0.0-alpha") }
283
+ it { should_not satisfies("1.0.0-alpha.2") }
284
+ it { should_not satisfies("1.0.0") }
285
+ it { should satisfies("1.0.0+build") }
286
+ it { should_not 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 (>) build constraint" do
293
+ subject { Semverse::Constraint.new("> 1.0.0+build") }
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_not 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 "greater than or equal to (>) zero pre-release constraint" do
307
+ subject { Semverse::Constraint.new("> 0.0.0-alpha") }
308
+
309
+ it { should satisfies("0.9.9+build") }
310
+ it { should satisfies("1.0.0-alpha") }
311
+ it { should satisfies("1.0.0-alpha.2") }
312
+ it { should satisfies("1.0.0") }
313
+ it { should satisfies("1.0.0+build") }
314
+ it { should 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 constraint" do
321
+ subject { Semverse::Constraint.new("> 0.0.0") }
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 build constraint" do
335
+ subject { Semverse::Constraint.new("> 0.0.0+build") }
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 "strictly less than (<) pre-release constraint" do
349
+ subject { Semverse::Constraint.new("< 1.0.0-alpha.3") }
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_not satisfies("1.0.0") }
355
+ it { should_not satisfies("1.0.0+build") }
356
+ it { should_not satisfies("1.0.1-beta") }
357
+ it { should_not satisfies("1.0.1") }
358
+ it { should_not satisfies("1.0.1+build.2") }
359
+ it { should_not satisfies("2.0.0") }
360
+ end
361
+
362
+ context "strictly less than (<)" do
363
+ subject { Semverse::Constraint.new("< 1.0.0") }
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 (<) build constraint" do
377
+ subject { Semverse::Constraint.new("< 1.0.0+build.20") }
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 satisfies("1.0.0") }
383
+ it { should 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 equal to (=)" do
391
+ subject { Semverse::Constraint.new("= 1.0.0") }
392
+
393
+ it { should_not satisfies("0.9.9+build") }
394
+ it { should satisfies("1.0.0") }
395
+ it { should_not satisfies("1.0.1") }
396
+ it { should_not satisfies("1.0.0-alpha") }
397
+ end
398
+
399
+ context "greater than or equal to (>=) pre-release constraint" do
400
+ subject { Semverse::Constraint.new(">= 1.0.0-alpha") }
401
+
402
+ it { should_not satisfies("0.9.9+build") }
403
+ it { should satisfies("1.0.0-alpha") }
404
+ it { should satisfies("1.0.0-alpha.2") }
405
+ it { should satisfies("1.0.0") }
406
+ it { should satisfies("1.0.0+build") }
407
+ it { should satisfies("1.0.1-beta") }
408
+ it { should satisfies("1.0.1") }
409
+ it { should satisfies("1.0.1+build.2") }
410
+ it { should satisfies("2.0.0") }
411
+ end
412
+
413
+ context "greater than or equal to (>=)" do
414
+ subject { Semverse::Constraint.new(">= 1.0.0") }
415
+
416
+ it { should_not satisfies("0.9.9+build") }
417
+ it { should_not satisfies("1.0.0-alpha") }
418
+ it { should_not satisfies("1.0.0-alpha.2") }
419
+ it { should satisfies("1.0.0") }
420
+ it { should satisfies("1.0.0+build") }
421
+ it { should_not 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 (>=) build constraint" do
428
+ subject { Semverse::Constraint.new(">= 1.0.0+build") }
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_not 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 (>=) zero pre-release constraint" do
442
+ subject { Semverse::Constraint.new(">= 0.0.0-alpha") }
443
+
444
+ it { should satisfies("0.9.9+build") }
445
+ it { should satisfies("1.0.0-alpha") }
446
+ it { should satisfies("1.0.0-alpha.2") }
447
+ it { should satisfies("1.0.0") }
448
+ it { should satisfies("1.0.0+build") }
449
+ it { should 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 constraint" do
456
+ subject { Semverse::Constraint.new(">= 0.0.0") }
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 build constraint" do
470
+ subject { Semverse::Constraint.new(">= 0.0.0+build") }
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 "lower than or equal to (<=) pre-release constraint" do
484
+ subject { Semverse::Constraint.new("<= 1.0.0") }
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_not satisfies("1.0.0+build") }
491
+ it { should_not satisfies("1.0.1-beta") }
492
+ it { should_not satisfies("1.0.1") }
493
+ it { should_not satisfies("1.0.1+build.2") }
494
+ it { should_not satisfies("2.0.0") }
495
+ end
496
+
497
+ context "lower than or equal to (<=)" do
498
+ subject { Semverse::Constraint.new("<= 1.0.0-alpha") }
499
+
500
+ it { should satisfies("0.9.9+build") }
501
+ it { should satisfies("1.0.0-alpha") }
502
+ it { should_not satisfies("1.0.0-alpha.2") }
503
+ it { should_not 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 (<=) build constraint" do
512
+ subject { Semverse::Constraint.new("<= 1.0.0+build") }
513
+
514
+ it { should satisfies("0.9.9+build") }
515
+ it { should satisfies("1.0.0-alpha") }
516
+ it { should satisfies("1.0.0-alpha.2") }
517
+ it { should satisfies("1.0.0") }
518
+ it { should 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
+ %w[~> ~].each do |operator|
526
+ describe "aproximately (#{operator})" do
527
+ context "when the last value in the constraint is for minor" do
528
+ subject { Semverse::Constraint.new("#{operator} 1.2") }
529
+
530
+ it { should_not satisfies("1.1.0") }
531
+ it { should_not satisfies("1.2.0-alpha") }
532
+ it { should satisfies("1.2.0") }
533
+ it { should satisfies("1.2.3") }
534
+ it { should satisfies("1.2.3+build") }
535
+ it { should satisfies("1.3") }
536
+ it { should satisfies("1.3.0") }
537
+ it { should_not satisfies("2.0.0-0") }
538
+ it { should_not satisfies("2.0.0") }
539
+ end
540
+
541
+ context "when the last value in the constraint is for patch" do
542
+ subject { Semverse::Constraint.new("#{operator} 1.2.0") }
543
+
544
+ it { should_not satisfies("1.1.0") }
545
+ it { should_not satisfies("1.2.3-alpha") }
546
+ it { should satisfies("1.2.2") }
547
+ it { should satisfies("1.2.3") }
548
+ it { should satisfies("1.2.5+build") }
549
+ it { should_not satisfies("1.3.0-0") }
550
+ it { should_not satisfies("1.3.0") }
551
+ end
552
+
553
+ context "when the last value in the constraint is for pre_release with a last numeric identifier" do
554
+ subject { Semverse::Constraint.new("#{operator} 1.2.3-4") }
555
+
556
+ it { should_not satisfies("1.2.3") }
557
+ it { should satisfies("1.2.3-4") }
558
+ it { should satisfies("1.2.3-10") }
559
+ it { should satisfies("1.2.3-10.5+build.33") }
560
+ it { should_not satisfies("1.2.3--") }
561
+ it { should_not satisfies("1.2.3-alpha") }
562
+ it { should_not satisfies("1.2.3") }
563
+ it { should_not satisfies("1.2.4") }
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 non-numeric identifier" do
568
+ subject { Semverse::Constraint.new("#{operator} 1.2.3-alpha") }
569
+
570
+ it { should_not satisfies("1.2.3-4") }
571
+ it { should_not satisfies("1.2.3--") }
572
+ it { should satisfies("1.2.3-alpha") }
573
+ it { should satisfies("1.2.3-alpha.0") }
574
+ it { should satisfies("1.2.3-beta") }
575
+ it { should satisfies("1.2.3-omega") }
576
+ it { should satisfies("1.2.3-omega.4") }
577
+ it { should_not satisfies("1.2.3") }
578
+ it { should_not satisfies("1.3.0") }
579
+ end
580
+
581
+ context "when the last value in the constraint is for build with a last numeric identifier and a pre-release" do
582
+ subject { Semverse::Constraint.new("#{operator} 1.2.3-alpha+5") }
583
+
584
+ it { should_not satisfies("1.2.3-alpha") }
585
+ it { should_not satisfies("1.2.3-alpha.4") }
586
+ it { should_not satisfies("1.2.3-alpha.4+4") }
587
+ it { should satisfies("1.2.3-alpha+5") }
588
+ it { should satisfies("1.2.3-alpha+5.5") }
589
+ it { should satisfies("1.2.3-alpha+10") }
590
+ it { should_not satisfies("1.2.3-alpha+-") }
591
+ it { should_not satisfies("1.2.3-alpha+build") }
592
+ it { should_not satisfies("1.2.3-beta") }
593
+ it { should_not satisfies("1.2.3") }
594
+ it { should_not satisfies("1.3.0") }
595
+ end
596
+
597
+ context "when the last value in the constraint is for build with a last non-numeric identifier and a pre-release" do
598
+ subject { Semverse::Constraint.new("#{operator} 1.2.3-alpha+build") }
599
+
600
+ it { should_not satisfies("1.2.3-alpha") }
601
+ it { should_not satisfies("1.2.3-alpha.4") }
602
+ it { should_not satisfies("1.2.3-alpha.4+4") }
603
+ it { should satisfies("1.2.3-alpha+build") }
604
+ it { should satisfies("1.2.3-alpha+build.5") }
605
+ it { should satisfies("1.2.3-alpha+preview") }
606
+ it { should satisfies("1.2.3-alpha+zzz") }
607
+ it { should_not satisfies("1.2.3-alphb") }
608
+ it { should_not satisfies("1.2.3-beta") }
609
+ it { should_not satisfies("1.2.3") }
610
+ it { should_not satisfies("1.3.0") }
611
+ end
612
+
613
+ context "when the last value in the constraint is for build with a last numeric identifier" do
614
+ subject { Semverse::Constraint.new("#{operator} 1.2.3+5") }
615
+
616
+ it { should_not satisfies("1.2.3") }
617
+ it { should_not satisfies("1.2.3-alpha") }
618
+ it { should_not satisfies("1.2.3+4") }
619
+ it { should satisfies("1.2.3+5") }
620
+ it { should satisfies("1.2.3+99") }
621
+ it { should_not satisfies("1.2.3+5.build") }
622
+ it { should_not satisfies("1.2.3+-") }
623
+ it { should_not satisfies("1.2.3+build") }
624
+ it { should_not satisfies("1.2.4") }
625
+ it { should_not satisfies("1.3.0") }
626
+ end
627
+
628
+ context "when the last value in the constraint is for build with a last non-numeric identifier" do
629
+ subject { Semverse::Constraint.new("#{operator} 1.2.3+build") }
630
+
631
+ it { should_not satisfies("1.2.3-alpha") }
632
+ it { should_not satisfies("1.2.3") }
633
+ it { should_not satisfies("1.2.3+5") }
634
+ it { should satisfies("1.2.3+build") }
635
+ it { should satisfies("1.2.3+build.5") }
636
+ it { should satisfies("1.2.3+preview") }
637
+ it { should satisfies("1.2.3+zzz") }
638
+ it { should_not satisfies("1.2.4-0") }
639
+ it { should_not satisfies("1.2.4") }
640
+ it { should_not satisfies("1.2.5") }
641
+ it { should_not satisfies("1.3.0") }
642
+ end
643
+ end
644
+ end
645
+ end
646
+
647
+ describe "#==" do
648
+ subject { Semverse::Constraint.new("= 1.0.0") }
649
+
650
+ it "returns true if the other object is a Semverse::Constraint with the same operator and version" do
651
+ other = Semverse::Constraint.new("= 1.0.0")
652
+ expect(subject).to eq(other)
653
+ end
654
+
655
+ it "returns false if the other object is a Semverse::Constraint with the same operator and different version" do
656
+ other = Semverse::Constraint.new("= 9.9.9")
657
+ expect(subject).to_not eq(other)
658
+ end
659
+
660
+ it "returns false if the other object is a Semverse::Constraint with the same version and different operator" do
661
+ other = Semverse::Constraint.new("> 1.0.0")
662
+ expect(subject).to_not eq(other)
663
+ end
664
+
665
+ it "returns false if the other object is not a Semverse::Constraint" do
666
+ other = "chicken"
667
+ expect(subject).to_not eq(other)
668
+ end
669
+ end
670
+
671
+ describe "#to_s" do
672
+ let(:constraint_string) { ">= 1.2.3-alpha+123" }
673
+ subject { described_class.new(constraint_string).to_s }
674
+
675
+ it { should eq(constraint_string) }
676
+
677
+ context "when the constraint does not contain a minor or patch value" do
678
+ let(:constraint_string) { "~> 1" }
679
+ it { should eq(constraint_string) }
680
+ end
681
+
682
+ context "when the constraint does not contain a patch value" do
683
+ let(:constraint_string) { "~> 1.2" }
684
+ it { should eq(constraint_string) }
685
+ end
686
+
687
+ context "when the constraint does not contain a build value" do
688
+ let(:constraint_string) { ">= 1.2.0-alpha"}
689
+ it { should eq(constraint_string) }
690
+ end
691
+
692
+ context "when the constraint contains a pre_release value" do
693
+ let(:constraint_string) { ">= 1.2.0+123"}
694
+ it { should eq(constraint_string) }
695
+ end
696
+ end
697
+ end