polisher 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  # Polisher Koji Spec
2
2
  #
3
3
  # Licensed under the MIT license
4
- # Copyright (C) 2013 Red Hat, Inc.
4
+ # Copyright (C) 2013-2014 Red Hat, Inc.
5
5
 
6
6
  require 'polisher/koji'
7
7
 
@@ -1,7 +1,7 @@
1
1
  # Polisher RPMSpec Specs
2
2
  #
3
3
  # Licensed under the MIT license
4
- # Copyright (C) 2013 Red Hat, Inc.
4
+ # Copyright (C) 2013-2014 Red Hat, Inc.
5
5
 
6
6
  require 'spec_helper'
7
7
 
@@ -9,6 +9,342 @@ require 'polisher/rpmspec'
9
9
  require 'polisher/gem'
10
10
 
11
11
  module Polisher
12
+ describe RPMSpec::Requirement do
13
+ describe "#str" do
14
+ it "returns requirement in string format" do
15
+ req = described_class.new :name => 'rubygem(activesupport)'
16
+ req.str.should == 'rubygem(activesupport)'
17
+
18
+ req = described_class.new :name => 'rubygem(activesupport)',
19
+ :condition => '>=', :version => '4.0'
20
+ req.str.should == 'rubygem(activesupport) >= 4.0'
21
+ end
22
+ end
23
+
24
+ describe "#specifier" do
25
+ it "returns specifier in string format" do
26
+ req = described_class.new :condition => '>=', :version => '10.0'
27
+ req.specifier.should == '>= 10.0'
28
+ end
29
+
30
+ context "version is nil" do
31
+ it "returns nil" do
32
+ req = described_class.new
33
+ req.specifier.should be_nil
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#parse" do
39
+ it "parses requirement string" do
40
+ req = described_class.parse "Requires: rubygem(foo)"
41
+ req.br.should be_false
42
+ req.name.should == "rubygem(foo)"
43
+ req.gem_name.should == "foo"
44
+ req.condition.should be_nil
45
+ req.version.should be_nil
46
+
47
+ req = described_class.parse "BuildRequires: rubygem(foo)"
48
+ req.br.should be_true
49
+
50
+ req = described_class.parse "rubygem(rake)"
51
+ req.br.should be_false
52
+ req.name.should == "rubygem(rake)"
53
+
54
+ req = described_class.parse "rubygem(rake) < 5"
55
+ req.condition.should == "<"
56
+ req.version.should == "5"
57
+ end
58
+ end
59
+
60
+ describe "#gcd" do
61
+ it "selects / returns max version less than local version" do
62
+ req = described_class.new :version => "5.0.0"
63
+ req.gcd(['1.0', '2.0', '5.0', '5.1', '6.1']).should == '2.0'
64
+ end
65
+ end
66
+
67
+ describe "#min_satisfying_version" do
68
+ context "no version req" do
69
+ it "returns 0" do
70
+ req = described_class.new
71
+ req.min_satisfying_version.should == "0.0"
72
+ end
73
+ end
74
+
75
+ context "= req" do
76
+ it "returns local version" do
77
+ req = described_class.new :condition => '=', :version => '5.0.0'
78
+ req.min_satisfying_version.should == '5.0.0'
79
+ end
80
+ end
81
+
82
+ context "> req" do
83
+ it "returns next version" do
84
+ req = described_class.new :condition => '>', :version => '5.0.0'
85
+ req.min_satisfying_version.should == '5.0.1'
86
+ end
87
+ end
88
+
89
+ context ">= req" do
90
+ it "returns local version" do
91
+ req = described_class.new :condition => '>=', :version => '5.0.0'
92
+ req.min_satisfying_version.should == '5.0.0'
93
+ end
94
+ end
95
+
96
+ context "< req" do
97
+ it "returns 0" do
98
+ req = described_class.new :condition => '<', :version => '5.0.0'
99
+ req.min_satisfying_version.should == "0.0"
100
+ end
101
+ end
102
+
103
+ context "<= req" do
104
+ it "returns 0" do
105
+ req = described_class.new :condition => '<=', :version => '5.0.0'
106
+ req.min_satisfying_version.should == "0.0"
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "#max_version_satisfying" do
112
+ context "no version req" do
113
+ it "returns infinity" do
114
+ req = described_class.new
115
+ req.max_satisfying_version.should == Float::INFINITY
116
+ end
117
+ end
118
+
119
+ context "= req" do
120
+ it "returns version" do
121
+ req = described_class.new :condition => '=', :version => '1.2.3'
122
+ req.max_satisfying_version.should == '1.2.3'
123
+ end
124
+ end
125
+
126
+ context "> req" do
127
+ it "returns infinity" do
128
+ req = described_class.new :condition => '>', :version => '1.2.3'
129
+ req.max_satisfying_version.should == Float::INFINITY
130
+ end
131
+ end
132
+
133
+ context ">= req" do
134
+ it "returns infinity" do
135
+ req = described_class.new :condition => '>=', :version => '1.2.3'
136
+ req.max_satisfying_version.should == Float::INFINITY
137
+ end
138
+ end
139
+
140
+ context "< req" do
141
+ context "versions list not specified" do
142
+ it "raises argument error" do
143
+ req = described_class.new :condition => '<', :version => '1.2.3'
144
+ lambda {
145
+ req.max_satisfying_version
146
+ }.should raise_error(ArgumentError)
147
+ end
148
+ end
149
+
150
+ it "returns gcd of list" do
151
+ req = described_class.new :condition => '<', :version => '1.2.3'
152
+ req.should_receive(:gcd).and_return('3')
153
+ req.max_satisfying_version(['1', '2']).should == '3'
154
+ end
155
+ end
156
+
157
+ context "<= req" do
158
+ it "returns version" do
159
+ req = described_class.new :condition => '<=', :version => '1.2.3'
160
+ req.max_satisfying_version.should == '1.2.3'
161
+ end
162
+ end
163
+ end
164
+
165
+ describe "#min_failing_version" do
166
+ context "no version req" do
167
+ it "raises argument error" do
168
+ req = described_class.new
169
+ lambda{
170
+ req.min_failing_version
171
+ }.should raise_error(ArgumentError)
172
+ end
173
+ end
174
+
175
+ context "= req" do
176
+ it "returns next version" do
177
+ req = described_class.new :condition => '=', :version => '5.0.0'
178
+ req.min_failing_version.should == '5.0.1'
179
+ end
180
+ end
181
+
182
+ context "> req" do
183
+ it "returns 0" do
184
+ req = described_class.new :condition => '>', :version => '5.0.0'
185
+ req.min_failing_version.should == '0.0'
186
+ end
187
+ end
188
+
189
+ context ">= req" do
190
+ it "returns 0" do
191
+ req = described_class.new :condition => '>=', :version => '5.0.0'
192
+ req.min_failing_version.should == '0.0'
193
+ end
194
+ end
195
+
196
+ context "< req" do
197
+ it "returns version" do
198
+ req = described_class.new :condition => '<', :version => '5.0.0'
199
+ req.min_failing_version.should == '5.0.0'
200
+ end
201
+ end
202
+
203
+ context "<= req" do
204
+ it "returns next version" do
205
+ req = described_class.new :condition => '<=', :version => '5.0.0'
206
+ req.min_failing_version.should == '5.0.1'
207
+ end
208
+ end
209
+ end
210
+
211
+ describe "#max_failing_version" do
212
+ context "no version req" do
213
+ it "raises argument error" do
214
+ req = described_class.new
215
+ lambda {
216
+ req.max_failing_version
217
+ }.should raise_error(ArgumentError)
218
+ end
219
+ end
220
+
221
+ context "= req" do
222
+ context "versions are nil" do
223
+ it "raises ArgumentError" do
224
+ req = described_class.new :condition => '=', :version => '2.0'
225
+ lambda {
226
+ req.max_failing_version
227
+ }.should raise_error(ArgumentError)
228
+ end
229
+ end
230
+
231
+ it "returns gcd of list" do
232
+ req = described_class.new :condition => '=', :version => '2.0'
233
+ req.should_receive(:gcd).and_return('abc')
234
+ req.max_failing_version(['1.2']).should == 'abc'
235
+ end
236
+ end
237
+
238
+ context "> req" do
239
+ it "returns version" do
240
+ req = described_class.new :condition => '>', :version => '2.0'
241
+ req.max_failing_version.should == '2.0'
242
+ end
243
+ end
244
+
245
+ context ">= req" do
246
+ context "versions are nil" do
247
+ it "raises ArgumentError" do
248
+ req = described_class.new :condition => '>=', :version => '2.0'
249
+ lambda {
250
+ req.max_failing_version
251
+ }.should raise_error(ArgumentError)
252
+ end
253
+ end
254
+
255
+ it "returns gcd of list" do
256
+ req = described_class.new :condition => '>=', :version => '2.0'
257
+ req.should_receive(:gcd).and_return('abc')
258
+ req.max_failing_version(['1.2']).should == 'abc'
259
+ end
260
+ end
261
+
262
+ context "< req" do
263
+ it "raises argument error" do
264
+ req = described_class.new :condition => '<', :version => '2.0'
265
+ lambda {
266
+ req.max_failing_version
267
+ }.should raise_error(ArgumentError)
268
+ end
269
+ end
270
+
271
+ context "<= req" do
272
+ it "raises argument error" do
273
+ req = described_class.new :condition => '<', :version => '2.0'
274
+ lambda {
275
+ req.max_failing_version
276
+ }.should raise_error(ArgumentError)
277
+ end
278
+ end
279
+ end
280
+
281
+ describe "#==" do
282
+ context "requirements are equal" do
283
+ it "returns true" do
284
+ req1 = described_class.new
285
+ req2 = described_class.new
286
+ req1.should == req2
287
+
288
+ req1 = described_class.parse 'rubygem(rails)'
289
+ req2 = described_class.parse 'rubygem(rails)'
290
+ req1.should == req2
291
+
292
+ req1 = described_class.parse 'rubygem(rails) >= 1.0.0'
293
+ req2 = described_class.parse 'rubygem(rails) >= 1.0.0'
294
+ req1.should == req2
295
+ end
296
+ end
297
+
298
+ context "requirements are not equal" do
299
+ it "returns true" do
300
+ req1 = described_class.parse 'rubygem(rails)'
301
+ req2 = described_class.parse 'rubygem(rake)'
302
+ req1.should_not == req2
303
+
304
+ req1 = described_class.parse 'rubygem(rake) > 1'
305
+ req2 = described_class.parse 'rubygem(rake) > 2'
306
+ req1.should_not == req2
307
+ end
308
+ end
309
+ end
310
+
311
+ describe "#matches?" do
312
+ context "requirement is same as dep requirement" do
313
+ it "returns true"
314
+ end
315
+
316
+ context "requirement is not same as dep requirement" do
317
+ it "returns false"
318
+ end
319
+ end
320
+
321
+ describe "#gem?" do
322
+ context "requirement matches gem dep matcher" do
323
+ it "returns true" do
324
+ described_class.parse("rubygem(rails)").gem?.should be_true
325
+ end
326
+ end
327
+
328
+ context "requirement does not match gem dep matcher" do
329
+ it "returns false" do
330
+ described_class.parse("something").gem?.should be_false
331
+ end
332
+ end
333
+ end
334
+
335
+ describe "#gem_name" do
336
+ it "returns gem name" do
337
+ described_class.parse("rubygem(rails)").gem_name.should == "rails"
338
+ end
339
+
340
+ context "requirement is not a gem" do
341
+ it "returns nil" do
342
+ described_class.parse("something").gem_name.should be_nil
343
+ end
344
+ end
345
+ end
346
+ end
347
+
12
348
  describe RPMSpec do
13
349
  describe "#initialize" do
14
350
  it "sets gem metadata" do
@@ -24,6 +360,38 @@ module Polisher
24
360
  end
25
361
  end
26
362
 
363
+ describe "#has_check?" do
364
+ context "package spec has %check section" do
365
+ it "returns true" do
366
+ spec = described_class.new :has_check => true
367
+ spec.has_check?.should be_true
368
+ end
369
+ end
370
+
371
+ context "package spec does not have a %check section" do
372
+ it "returns false" do
373
+ spec = described_class.new
374
+ spec.has_check?.should be_false
375
+ end
376
+ end
377
+ end
378
+
379
+
380
+ describe "#requirements_for_gem" do
381
+ it "returns requirements for specified gem name" do
382
+ spec = Polisher::RPMSpec.new :requires =>
383
+ [Polisher::RPMSpec::Requirement.new(:name => 'rubygem(rake)')]
384
+ spec.requirements_for_gem('rake').should == [spec.requires.first]
385
+ end
386
+
387
+ context "spec has no requirement with specified name" do
388
+ it "returns empty array" do
389
+ spec = Polisher::RPMSpec.new
390
+ spec.requirements_for_gem('rake').should be_empty
391
+ end
392
+ end
393
+ end
394
+
27
395
  describe "#parse" do
28
396
  before(:each) do
29
397
  @spec = Polisher::Test::RPM_SPEC
@@ -70,25 +438,39 @@ module Polisher
70
438
  pspec = Polisher::RPMSpec.parse @spec[:contents]
71
439
  pspec.files.should == @spec[:files]
72
440
  end
441
+
442
+ it "parses %check from spec" do
443
+ pspec = Polisher::RPMSpec.parse @spec[:contents]
444
+ pspec.has_check?.should be_true
445
+
446
+ pspec = Polisher::RPMSpec.parse ""
447
+ pspec.has_check?.should be_false
448
+ end
73
449
  end
74
450
 
75
451
  describe "#update_to" do
76
452
  it "updates dependencies from gem" do
77
- spec = Polisher::RPMSpec.new :requires => ['rubygem(rake)', 'rubygem(activerecord)'],
453
+ spec = Polisher::RPMSpec.new :requires => [Polisher::RPMSpec::Requirement.parse('rubygem(rake)'),
454
+ Polisher::RPMSpec::Requirement.parse('rubygem(activerecord)')],
78
455
  :build_requires => []
79
456
  gem = Polisher::Gem.new :deps => [::Gem::Dependency.new('rake'),
80
457
  ::Gem::Dependency.new('rails', '~> 10')],
81
458
  :dev_deps => [::Gem::Dependency.new('rspec', :development)]
82
459
 
460
+ spec.should_receive(:update_files_from) # stub out files update
83
461
  spec.update_to(gem)
84
- spec.requires.should == ['rubygem(activerecord)', 'rubygem(rake) >= 0',
85
- 'rubygem(rails) => 10', 'rubygem(rails) < 11']
86
- spec.build_requires.should == ['rubygem(rspec) >= 0']
462
+ spec.requires.should == [Polisher::RPMSpec::Requirement.parse('rubygem(activerecord)'),
463
+ Polisher::RPMSpec::Requirement.parse('rubygem(rake) >= 0'),
464
+ Polisher::RPMSpec::Requirement.parse('rubygem(rails) => 10'),
465
+ Polisher::RPMSpec::Requirement.parse('rubygem(rails) < 11')]
466
+ spec.build_requires.should == [Polisher::RPMSpec::Requirement.parse('rubygem(rspec) >= 0', :br => true)]
87
467
  end
88
468
 
89
469
  it "adds new files from gem" do
90
470
  spec = Polisher::RPMSpec.new :files => {'pkg' => ['/foo']}
91
- gem = Polisher::Gem.new :files => ['/foo', '/foo/bar', '/baz']
471
+ gem = Polisher::Gem.new
472
+ gem.should_receive(:file_paths).at_least(:once).
473
+ and_return(['/foo', '/foo/bar', '/baz'])
92
474
  spec.update_to(gem)
93
475
  spec.new_files.should == ['/baz']
94
476
  end
@@ -96,6 +478,7 @@ module Polisher
96
478
  it "updates metadata from gem" do
97
479
  spec = Polisher::RPMSpec.new
98
480
  gem = Polisher::Gem.new :version => '1.0.0'
481
+ spec.should_receive(:update_files_from) # stub out files update
99
482
  spec.update_to(gem)
100
483
  spec.version.should == '1.0.0'
101
484
  spec.release.should == '1%{?dist}'
@@ -107,5 +490,51 @@ module Polisher
107
490
  describe "#to_string" do
108
491
  it "returns string representation of spec"
109
492
  end
493
+
494
+ describe "#compare" do
495
+ it "returns requirements in spec but not in gem" do
496
+ req = Polisher::RPMSpec::Requirement.parse 'rubygem(rails) > 3.0.0'
497
+ spec = Polisher::RPMSpec.new :requires => [req]
498
+ gem = Polisher::Gem.new
499
+
500
+ spec.compare(gem).should ==
501
+ {:same => {}, :diff => {'rails' =>
502
+ {:spec => '> 3.0.0', :upstream => nil}}}
503
+ end
504
+
505
+ it "returns requirements in gem but not in spec" do
506
+ req = ::Gem::Dependency.new('rails', '> 3.0.0')
507
+ spec = Polisher::RPMSpec.new
508
+ gem = Polisher::Gem.new :deps => [req]
509
+
510
+ spec.compare(gem).should ==
511
+ {:same => {}, :diff => {'rails' =>
512
+ {:spec => nil, :upstream => '> 3.0.0'}}}
513
+ end
514
+
515
+ it "returns shared requirements with different specifiers" do
516
+ greq = ::Gem::Dependency.new('rails', '< 5.0.0')
517
+ gem = Polisher::Gem.new :deps => [greq]
518
+
519
+ sreq = Polisher::RPMSpec::Requirement.parse 'rubygem(rails) > 3.0.0'
520
+ spec = Polisher::RPMSpec.new :requires => [sreq]
521
+
522
+ spec.compare(gem).should ==
523
+ {:same => {}, :diff => {'rails' =>
524
+ {:spec => '> 3.0.0', :upstream => '< 5.0.0'}}}
525
+ end
526
+
527
+ it "returns shared requirements" do
528
+ greq = ::Gem::Dependency.new('rails', '< 3.0.0')
529
+ gem = Polisher::Gem.new :deps => [greq]
530
+
531
+ sreq = Polisher::RPMSpec::Requirement.parse 'rubygem(rails) < 3.0.0'
532
+ spec = Polisher::RPMSpec.new :requires => [sreq]
533
+
534
+ spec.compare(gem).should ==
535
+ {:diff => {}, :same => {'rails' =>
536
+ {:spec => '< 3.0.0', :upstream => '< 3.0.0'}}}
537
+ end
538
+ end
110
539
  end # describe RPMSpec
111
540
  end # module Polisher