solve 0.8.2 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,355 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Solve::Version do
4
- describe "ClassMethods" do
5
- subject { Solve::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
- @version.major.should eql(1)
13
- end
14
-
15
- it "assigns a minor value" do
16
- @version.minor.should eql(2)
17
- end
18
-
19
- it "assigns a patch value" do
20
- @version.patch.should eql(3)
21
- end
22
-
23
- it "assigns a pre_release value" do
24
- @version.pre_release.should eql('rc.1')
25
- end
26
-
27
- it "assigns a build value" do
28
- @version.build.should eql('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
- @version.major.should eql(1)
37
- end
38
-
39
- it "assigns a minor value" do
40
- @version.minor.should eql(2)
41
- end
42
-
43
- it "assigns a patch value" do
44
- @version.patch.should eql(3)
45
- end
46
-
47
- it "doesn't assigns a pre_release value" do
48
- @version.pre_release.should be_nil
49
- end
50
-
51
- it "assigns a build value" do
52
- @version.build.should eql('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
- @version.major.should eql(1)
61
- end
62
-
63
- it "assigns a minor value" do
64
- @version.minor.should eql(2)
65
- end
66
-
67
- it "assigns a patch value" do
68
- @version.patch.should eql(3)
69
- end
70
-
71
- it "doesn't assigns a pre_release value" do
72
- @version.pre_release.should be_nil
73
- end
74
-
75
- it "doesn't assigns a build value" do
76
- @version.build.should 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
- @version.major.should eql(1)
85
- end
86
-
87
- it "assigns a minor value" do
88
- @version.minor.should eql(2)
89
- end
90
-
91
- it "assigns a patch value" do
92
- @version.patch.should eql(3)
93
- end
94
-
95
- it "doesn't assigns a pre_release value" do
96
- @version.pre_release.should be_nil
97
- end
98
-
99
- it "assigns a build value" do
100
- @version.build.should eql('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
- @version.major.should eql(1)
109
- end
110
-
111
- it "assigns a minor value" do
112
- @version.minor.should eql(2)
113
- end
114
-
115
- it "assigns a patch value" do
116
- @version.patch.should eql(3)
117
- end
118
-
119
- it "assigns a pre_release value" do
120
- @version.pre_release.should eql('alpha.1')
121
- end
122
-
123
- it "doesn't assigns a build value" do
124
- @version.build.should 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
- @version.major.should eql(1)
133
- end
134
-
135
- it "assigns a minor value" do
136
- @version.minor.should eql(2)
137
- end
138
-
139
- it "assigns a patch value" do
140
- @version.patch.should eql(3)
141
- end
142
-
143
- it "doesn't assigns a pre_release value" do
144
- @version.pre_release.should be_nil
145
- end
146
-
147
- it "doesn't assigns a build value" do
148
- @version.build.should 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
- @version.major.should eql(1)
157
- end
158
-
159
- it "assigns a minor value" do
160
- @version.minor.should eql(2)
161
- end
162
-
163
- it "sets the patch value to 0 (zero)" do
164
- @version.patch.should eql(0)
165
- end
166
-
167
- it "doesn't assigns a pre_release value" do
168
- @version.pre_release.should be_nil
169
- end
170
-
171
- it "doesn't assigns a build value" do
172
- @version.build.should 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
- @version.major.should eql(1)
181
- end
182
-
183
- it "sets the minor value to 0 (zero)" do
184
- @version.minor.should eql(0)
185
- end
186
-
187
- it "sets the patch value to 0 (zero)" do
188
- @version.patch.should eql(0)
189
- end
190
-
191
- it "doesn't assigns a pre_release value" do
192
- @version.pre_release.should be_nil
193
- end
194
-
195
- it "doesn't assigns a build value" do
196
- @version.build.should 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
- @version.major.should eql(0)
205
- end
206
-
207
- it "sets the minor value to 0 (zero)" do
208
- @version.minor.should eql(0)
209
- end
210
-
211
- it "sets the patch value to 0 (zero)" do
212
- @version.patch.should eql(0)
213
- end
214
-
215
- it "doesn't assigns a pre_release value" do
216
- @version.pre_release.should be_nil
217
- end
218
-
219
- it "doesn't assigns a build value" do
220
- @version.build.should be_nil
221
- end
222
- end
223
- end
224
-
225
- describe "::split" do
226
- it "returns an array containing 5 elements" do
227
- subject.split("1.2.0-alpha.1").should have(5).items
228
- end
229
-
230
- context "given a string only containing a major, minor and patch version" do
231
- it "returns an array containing 4 elements" do
232
- subject.split("1.2.3").should have(5).items
233
- end
234
-
235
- it "returns nil as fourth element" do
236
- subject.split("1.2.3")[3].should be_nil
237
- end
238
-
239
- it "returns nil as fifth element" do
240
- subject.split("1.2.3")[4].should 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
- subject.split("1.2").should have(3).items
247
- end
248
-
249
- it "returns 0 as the third element" do
250
- subject.split("1.2")[2].should eql(0)
251
- end
252
-
253
- it "converts the third element to 0 if it's nil or blank" do
254
- subject.split("1.2.")[2].should eql(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
- subject.split("1").should have(3).items
261
- end
262
-
263
- it "returns 0 as the second element" do
264
- subject.split("1")[1].should eql(0)
265
- end
266
-
267
- it "returns 0 as the third element" do
268
- subject.split("1")[2].should eql(0)
269
- end
270
-
271
- it "converts the second element to 0 if it's nil or blank" do
272
- subject.split("1.")[1].should eql(0)
273
- end
274
- end
275
-
276
- context "given a string with an invalid version"
277
- it "raises an InvalidVersionFormat error" do
278
- lambda {
279
- subject.split("hello")
280
- }.should raise_error(Solve::Errors::InvalidVersionFormat)
281
- end
282
- end
283
- end
284
-
285
- describe "#pre_release?" do
286
- context "when a pre-release value is set" do
287
- subject { described_class.new("1.2.3-alpha").pre_release? }
288
- it { should be_true }
289
- end
290
-
291
- context "when no pre-release value is set" do
292
- subject { described_class.new("1.2.3").pre_release? }
293
- it { should be_false }
294
- end
295
- end
296
-
297
- describe "#zero?" do
298
- context "major, minor and patch are equal to 0" do
299
- subject { described_class.new("0.0.0").zero? }
300
- it { should be_true }
301
- end
302
-
303
- context "major is not equal to 0" do
304
- subject { described_class.new("1.0.0").zero? }
305
- it { should be_false }
306
- end
307
-
308
- context "minor is not equal to 0" do
309
- subject { described_class.new("0.1.0").zero? }
310
- it { should be_false }
311
- end
312
-
313
- context "patch is not equal to 0" do
314
- subject { described_class.new("0.0.1").zero? }
315
- it { should be_false }
316
- end
317
- end
318
-
319
- describe "#to_s" do
320
- subject { Solve::Version.new("1.0.0-rc.1+build.1") }
321
-
322
- it "returns a string containing the major.minor.patch-pre_release+build" do
323
- subject.to_s.should eql("1.0.0-rc.1+build.1")
324
- end
325
- end
326
-
327
- describe "#<=>" do
328
- it "compares versions" do
329
- versions_list = %w[
330
- 1.0.0-0
331
- 1.0.0-alpha
332
- 1.0.0-alpha.1
333
- 1.0.0-beta.2
334
- 1.0.0-beta.11
335
- 1.0.0-rc.1
336
- 1.0.0-rc.1+build.1
337
- 1.0.0
338
- 1.0.0+0.3.7
339
- 1.0.0+build
340
- 1.0.0+build.2.b8f12d7
341
- 1.0.0+build.11.e0f985a
342
- ]
343
- versions = versions_list.map { |version| Solve::Version.new(version) }
344
-
345
- 100.times do
346
- shuffled_versions = versions.shuffle
347
- while shuffled_versions == versions
348
- shuffled_versions = shuffled_versions.shuffle
349
- end
350
- shuffled_versions.sort.map(&:to_s).should == versions_list
351
- end
352
- end
353
- end
354
-
355
- end