polisher 0.10.2 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/bin/binary_gem_resolver.rb +2 -2
  3. data/bin/bundler2yum.rb +51 -0
  4. data/bin/check_ruby_spec.rb +32 -0
  5. data/bin/gem_dependency_checker.rb +13 -242
  6. data/bin/gem_mapper.rb +27 -0
  7. data/bin/gems2update.rb +27 -0
  8. data/bin/git_gem_diff.rb +48 -0
  9. data/bin/git_gem_updater.rb +3 -3
  10. data/bin/missing_deps.rb +29 -0
  11. data/bin/polisher-config.rb +17 -0
  12. data/bin/ruby_rpm_spec_updater.rb +23 -2
  13. data/lib/polisher.rb +5 -12
  14. data/lib/polisher/adaptors/checker_loader.rb +78 -0
  15. data/lib/polisher/{upstream.rb → adaptors/upstream.rb} +1 -0
  16. data/lib/polisher/adaptors/version_checker.rb +57 -0
  17. data/lib/polisher/adaptors/version_checker/bodhi.rb +29 -0
  18. data/lib/polisher/adaptors/version_checker/errata.rb +29 -0
  19. data/lib/polisher/adaptors/version_checker/fedora.rb +29 -0
  20. data/lib/polisher/adaptors/version_checker/gem.rb +27 -0
  21. data/lib/polisher/adaptors/version_checker/git.rb +29 -0
  22. data/lib/polisher/adaptors/version_checker/koji.rb +29 -0
  23. data/lib/polisher/adaptors/version_checker/yum.rb +29 -0
  24. data/lib/polisher/cli/all.rb +22 -0
  25. data/lib/polisher/cli/bin/gem_dependency_checker.rb +85 -0
  26. data/lib/polisher/cli/bin/gem_mapper.rb +37 -0
  27. data/lib/polisher/cli/bin/gems2update.rb +86 -0
  28. data/lib/polisher/cli/bin/missing_deps.rb +35 -0
  29. data/lib/polisher/cli/conf.rb +18 -0
  30. data/lib/polisher/cli/default.rb +25 -0
  31. data/lib/polisher/cli/format.rb +130 -0
  32. data/lib/polisher/cli/sources.rb +106 -0
  33. data/lib/polisher/cli/specifier.rb +30 -0
  34. data/lib/polisher/cli/status.rb +50 -0
  35. data/lib/polisher/cli/targets.rb +88 -0
  36. data/lib/polisher/gem.rb +41 -338
  37. data/lib/polisher/gem/attributes.rb +20 -0
  38. data/lib/polisher/gem/dependencies.rb +63 -0
  39. data/lib/polisher/gem/diff.rb +39 -0
  40. data/lib/polisher/gem/files.rb +111 -0
  41. data/lib/polisher/gem/parser.rb +85 -0
  42. data/lib/polisher/gem/retriever.rb +137 -0
  43. data/lib/polisher/{gem_state.rb → gem/state.rb} +6 -6
  44. data/lib/polisher/gem/versions.rb +131 -0
  45. data/lib/polisher/gemfile.rb +20 -89
  46. data/lib/polisher/gemfile/attributes.rb +19 -0
  47. data/lib/polisher/gemfile/deps.rb +43 -0
  48. data/lib/polisher/gemfile/parser.rb +45 -0
  49. data/lib/polisher/git/pkg.rb +33 -238
  50. data/lib/polisher/git/pkg/attributes.rb +60 -0
  51. data/lib/polisher/git/pkg/builder.rb +47 -0
  52. data/lib/polisher/git/pkg/repo.rb +82 -0
  53. data/lib/polisher/git/pkg/updater.rb +53 -0
  54. data/lib/polisher/git/pkg/versions.rb +40 -0
  55. data/lib/polisher/git/project.rb +1 -1
  56. data/lib/polisher/git/repo.rb +79 -76
  57. data/lib/polisher/{vendor.rb → mixins/vendored_deps.rb} +4 -7
  58. data/lib/polisher/mixins/versioned_dependencies.rb +86 -0
  59. data/lib/polisher/record.rb +2 -0
  60. data/lib/polisher/rpm.rb +23 -0
  61. data/lib/polisher/rpm/patch.rb +10 -8
  62. data/lib/polisher/rpm/requirement.rb +33 -189
  63. data/lib/polisher/rpm/requirement/attributes.rb +43 -0
  64. data/lib/polisher/rpm/requirement/comparison.rb +97 -0
  65. data/lib/polisher/rpm/requirement/gem_reference.rb +46 -0
  66. data/lib/polisher/rpm/requirement/parser.rb +41 -0
  67. data/lib/polisher/rpm/spec.rb +97 -436
  68. data/lib/polisher/rpm/spec/check.rb +14 -0
  69. data/lib/polisher/rpm/spec/comparison.rb +64 -0
  70. data/lib/polisher/rpm/spec/files.rb +15 -0
  71. data/lib/polisher/rpm/spec/gem_files.rb +65 -0
  72. data/lib/polisher/rpm/spec/gem_reference.rb +59 -0
  73. data/lib/polisher/rpm/spec/gem_requirements.rb +73 -0
  74. data/lib/polisher/rpm/spec/parser.rb +106 -0
  75. data/lib/polisher/rpm/spec/requirements.rb +31 -0
  76. data/lib/polisher/rpm/spec/subpackages.rb +23 -0
  77. data/lib/polisher/rpm/spec/updater.rb +268 -0
  78. data/lib/polisher/specifier.rb +13 -0
  79. data/lib/polisher/targets.rb +36 -0
  80. data/lib/polisher/{apt.rb → targets/apt.rb} +1 -1
  81. data/lib/polisher/targets/bodhi.rb +43 -0
  82. data/lib/polisher/{bugzilla.rb → targets/bugzilla.rb} +1 -1
  83. data/lib/polisher/targets/errata.rb +55 -0
  84. data/lib/polisher/targets/errata/build.rb +24 -0
  85. data/lib/polisher/targets/fedora.rb +47 -0
  86. data/lib/polisher/targets/koji.rb +39 -0
  87. data/lib/polisher/targets/koji/builder.rb +38 -0
  88. data/lib/polisher/targets/koji/diff.rb +39 -0
  89. data/lib/polisher/targets/koji/rpc.rb +43 -0
  90. data/lib/polisher/targets/koji/versions.rb +67 -0
  91. data/lib/polisher/targets/rhn.rb +12 -0
  92. data/lib/polisher/targets/yum.rb +36 -0
  93. data/lib/polisher/{component.rb → util/component.rb} +3 -3
  94. data/lib/polisher/util/conf_helpers.rb +77 -0
  95. data/lib/polisher/util/config.rb +45 -0
  96. data/lib/polisher/util/core_ext.rb +59 -0
  97. data/lib/polisher/{error.rb → util/error.rb} +0 -0
  98. data/lib/polisher/{gem_cache.rb → util/gem_cache.rb} +1 -1
  99. data/lib/polisher/{git_cache.rb → util/git_cache.rb} +0 -0
  100. data/lib/polisher/{logger.rb → util/logger.rb} +2 -0
  101. data/lib/polisher/{tag_mapper.rb → util/tag_mapper.rb} +1 -1
  102. data/lib/polisher/version.rb +1 -1
  103. data/spec/{upstream_spec.rb → adaptors/upstream_spec.rb} +1 -1
  104. data/spec/{version_checker_spec.rb → adaptors/version_checker_spec.rb} +1 -6
  105. data/spec/data/activesupport-4.1.4.gem +0 -0
  106. data/spec/data/rubygem-activesupport-with-doc.spec +247 -0
  107. data/spec/data/rubygem-activesupport-without-requires.spec +232 -0
  108. data/spec/data/rubygem-activesupport.spec +0 -122
  109. data/spec/fixtures/gem_json.rb +49 -0
  110. data/spec/fixtures/gem_spec.rb +13 -0
  111. data/spec/fixtures/gemfile.rb +10 -0
  112. data/spec/fixtures/local_gem.rb +62 -0
  113. data/spec/fixtures/rpm_spec.rb +91 -0
  114. data/spec/gem/attributes_spec.rb +17 -0
  115. data/spec/gem/diff_spec.rb +80 -0
  116. data/spec/gem/files_spec.rb +171 -0
  117. data/spec/gem/parser_spec.rb +44 -0
  118. data/spec/gem/retriever_spec.rb +124 -0
  119. data/spec/gem/state_spec.rb +79 -0
  120. data/spec/gem/versions_spec.rb +148 -0
  121. data/spec/gem_spec.rb +5 -347
  122. data/spec/gemfile/deps_spec.rb +20 -0
  123. data/spec/gemfile/parser_spec.rb +26 -0
  124. data/spec/gemfile_spec.rb +0 -34
  125. data/spec/git/pkg/attributes_spec.rb +128 -0
  126. data/spec/git/pkg/builder_spec.rb +63 -0
  127. data/spec/git/pkg/repo_spec.rb +146 -0
  128. data/spec/git/pkg/updater_spec.rb +86 -0
  129. data/spec/git/pkg/versions_spec.rb +42 -0
  130. data/spec/git/pkg_spec.rb +21 -0
  131. data/spec/git/project_spec.rb +21 -0
  132. data/spec/git/repo_spec.rb +160 -0
  133. data/spec/{vendor_spec.rb → mixins/vendored_deps_spec.rb} +2 -4
  134. data/spec/mixins/versioned_dependencies_spec.rb +48 -0
  135. data/spec/rpm/patch_spec.rb +48 -0
  136. data/spec/rpm/requirement/attributes_spec.rb +34 -0
  137. data/spec/rpm/requirement/comparison_spec.rb +286 -0
  138. data/spec/rpm/requirement/gem_spec.rb +49 -0
  139. data/spec/rpm/requirement/parser_spec.rb +31 -0
  140. data/spec/rpm/requirement_spec.rb +8 -334
  141. data/spec/rpm/spec/check_spec.rb +25 -0
  142. data/spec/rpm/spec/comparison_spec.rb +55 -0
  143. data/spec/rpm/spec/files_spec.rb +17 -0
  144. data/spec/rpm/spec/gem_files_spec.rb +112 -0
  145. data/spec/rpm/spec/gem_reference_spec.rb +99 -0
  146. data/spec/rpm/spec/gem_requirement_spec.rb +38 -0
  147. data/spec/rpm/spec/parser_spec.rb +64 -0
  148. data/spec/rpm/spec/requirements_spec.rb +10 -0
  149. data/spec/rpm/spec/subpackages_spec.rb +38 -0
  150. data/spec/rpm/spec/updater_spec.rb +486 -0
  151. data/spec/rpm/spec_spec.rb +27 -174
  152. data/spec/spec_helper.rb +7 -107
  153. data/spec/support/coveralls.rb +10 -0
  154. data/spec/support/fixtures.rb +8 -0
  155. data/spec/support/paths.rb +20 -0
  156. data/spec/support/rspec.rb +20 -0
  157. data/spec/support/vcr.rb +11 -0
  158. data/spec/{bodhi_spec.rb → targets/bodhi_spec.rb} +3 -1
  159. data/spec/{errata_spec.rb → targets/errata_spec.rb} +2 -2
  160. data/spec/{fedora_spec.rb → targets/fedora_spec.rb} +3 -3
  161. data/spec/targets/koji/builder_spec.rb +48 -0
  162. data/spec/targets/koji/diff_spec.rb +36 -0
  163. data/spec/targets/koji/rpc_spec.rb +28 -0
  164. data/spec/{koji_spec.rb → targets/koji/versions_spec.rb} +1 -59
  165. data/spec/targets/koji_spec.rb +11 -0
  166. data/spec/{yum_spec.rb → targets/yum_spec.rb} +1 -1
  167. data/spec/{component_spec.rb → util/component_spec.rb} +1 -1
  168. data/spec/{core_spec.rb → util/core_ext_spec.rb} +2 -3
  169. metadata +278 -88
  170. data/lib/polisher/bodhi.rb +0 -23
  171. data/lib/polisher/config.rb +0 -32
  172. data/lib/polisher/core.rb +0 -101
  173. data/lib/polisher/errata.rb +0 -75
  174. data/lib/polisher/fedora.rb +0 -46
  175. data/lib/polisher/git.rb +0 -8
  176. data/lib/polisher/koji.rb +0 -159
  177. data/lib/polisher/rhn.rb +0 -15
  178. data/lib/polisher/version_checker.rb +0 -177
  179. data/lib/polisher/yum.rb +0 -37
  180. data/spec/git_spec.rb +0 -445
@@ -0,0 +1,21 @@
1
+ #
2
+ # Licensed under the MIT license
3
+ # Copyright (C) 2013-2014 Red Hat, Inc.
4
+
5
+ require 'polisher/git/pkg'
6
+
7
+ module Polisher
8
+ describe Git::Pkg do
9
+ describe "#initialize" do
10
+ it "initializes name" do
11
+ pkg = described_class.new :name => 'pkg_name'
12
+ pkg.name.should == 'pkg_name'
13
+ end
14
+
15
+ it "initializes version" do
16
+ pkg = described_class.new :version => 'pkg_version'
17
+ pkg.version.should == 'pkg_version'
18
+ end
19
+ end
20
+ end # describe Git::Pkg
21
+ end # module Polisher
@@ -0,0 +1,21 @@
1
+ #
2
+ # Licensed under the MIT license
3
+ # Copyright (C) 2013-2014 Red Hat, Inc.
4
+
5
+ require 'polisher/git/project'
6
+
7
+ module Polisher
8
+ describe Git::Project do
9
+ describe "#vendored" do
10
+ context "repo not cloned" do
11
+ it "clones repo" do
12
+ git = described_class.new
13
+ git.should_receive(:cloned?).and_return(false)
14
+ git.should_receive(:clone)
15
+ git.should_receive(:vendored_file_paths).and_return([]) # stub out
16
+ git.vendored
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end # module Polisher
@@ -0,0 +1,160 @@
1
+ #
2
+ # Licensed under the MIT license
3
+ # Copyright (C) 2013-2014 Red Hat, Inc.
4
+
5
+ require 'awesome_spawn'
6
+ require 'polisher/git/repo'
7
+
8
+ module Polisher
9
+ describe Git::Repo do
10
+ describe "#initialize" do
11
+ it "initializes url" do
12
+ repo = described_class.new :url => 'repo_url'
13
+ repo.url.should == 'repo_url'
14
+ end
15
+ end
16
+
17
+ describe "#path" do
18
+ it "returns set path" do
19
+ repo = described_class.new :path => 'repo_path'
20
+ repo.path.should == 'repo_path'
21
+ end
22
+
23
+ it "returns git cache path for url" do
24
+ repo = described_class.new :url => 'repo_url'
25
+ Polisher::GitCache.should_receive(:path_for)
26
+ .with('repo_url')
27
+ .and_return('repo_path')
28
+ repo.path.should == 'repo_path'
29
+ end
30
+ end
31
+
32
+ describe "#clobber" do
33
+ it "rm -rf's path" do
34
+ repo = described_class.new :path => 'repo_path'
35
+ FileUtils.should_receive(:rm_rf).with('repo_path')
36
+ repo.clobber!
37
+ RSpec::Mocks.proxy_for(FileUtils).reset # XXX
38
+ end
39
+ end
40
+
41
+ describe "#clone" do
42
+ it "runs git clone" do
43
+ expected = "/usr/bin/git clone repo_url repo_path"
44
+ AwesomeSpawn.should_receive(:run!).with(expected)
45
+
46
+ repo = described_class.new :url => 'repo_url'
47
+ repo.should_receive(:path).and_return('repo_path')
48
+ repo.clone
49
+ end
50
+ end
51
+
52
+ describe "#cloned?" do
53
+ before(:each) do
54
+ @repo = described_class.new
55
+ @repo.should_receive(:path).and_return('repo_path')
56
+ end
57
+
58
+ context "repo path directory exists" do
59
+ it "returns true" do
60
+ File.should_receive(:directory?).with('repo_path').and_return(true)
61
+ @repo.should be_cloned
62
+ end
63
+ end
64
+
65
+ context "repo path directory does not exist" do
66
+ it "returns false" do
67
+ File.should_receive(:directory?).with('repo_path').and_return(false)
68
+ @repo.should_not be_cloned
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "#in_repo" do
74
+ it "chdir to repo path, invokes block, restores dir" do
75
+ repo = described_class.new
76
+ Dir.mktmpdir do |dir|
77
+ repo.should_receive(:path).and_return(dir)
78
+
79
+ expected = Pathname.new(dir).realpath.to_s
80
+ invoked = false
81
+ orig = Dir.pwd
82
+ repo.in_repo do
83
+ Dir.pwd.should == expected
84
+ invoked = true
85
+ end
86
+ Dir.pwd.should == orig
87
+ invoked.should be_true
88
+ end
89
+ end
90
+ end
91
+
92
+ describe "#file_paths" do
93
+ it "returns list of all first paths in git repo" do
94
+ expected = ['file1', 'dir1/file2', 'dir2']
95
+ repo = described_class.new
96
+ repo.should_receive(:in_repo).and_yield
97
+ Dir.should_receive(:[]).with('**/*').and_return(expected)
98
+ repo.file_paths.should == expected
99
+ end
100
+ end
101
+
102
+ describe "#include?" do
103
+ context "file paths includes file" do
104
+ it "returns true" do
105
+ repo = described_class.new
106
+ repo.should_receive(:file_paths).and_return(['foo'])
107
+ repo.include?('foo').should be_true
108
+ end
109
+ end
110
+
111
+ context "file paths does not include file" do
112
+ it "returns false" do
113
+ repo = described_class.new
114
+ repo.should_receive(:file_paths).and_return([])
115
+ repo.include?('foo').should be_false
116
+ end
117
+ end
118
+ end
119
+
120
+ describe "#reset!" do
121
+ it "resets git repo to head" do
122
+ expected = "/usr/bin/git reset HEAD~ --hard"
123
+ repo = described_class.new
124
+ repo.should_receive(:in_repo).and_yield
125
+ AwesomeSpawn.should_receive(:run!).with(expected)
126
+ repo.reset!
127
+ end
128
+ end
129
+
130
+ describe "#pull" do
131
+ it "git pulls" do
132
+ expected = "/usr/bin/git pull"
133
+ repo = described_class.new
134
+ repo.should_receive(:in_repo).and_yield
135
+ AwesomeSpawn.should_receive(:run!).with(expected)
136
+ repo.pull
137
+ end
138
+ end
139
+
140
+ describe "#checkout" do
141
+ it "git checks out target" do
142
+ expected = "/usr/bin/git checkout master"
143
+ repo = described_class.new
144
+ repo.should_receive(:in_repo).and_yield
145
+ AwesomeSpawn.should_receive(:run!).with(expected)
146
+ repo.checkout('master')
147
+ end
148
+ end
149
+
150
+ describe "#commit" do
151
+ it "git commits with message" do
152
+ expected = "/usr/bin/git commit -m 'msg'"
153
+ repo = described_class.new
154
+ repo.should_receive(:in_repo).and_yield
155
+ AwesomeSpawn.should_receive(:run!).with(expected)
156
+ repo.commit('msg')
157
+ end
158
+ end
159
+ end
160
+ end # module Polisher
@@ -3,9 +3,7 @@
3
3
  # Licensed under the MIT license
4
4
  # Copyright (C) 2014 Red Hat, Inc.
5
5
 
6
- require 'spec_helper'
7
-
8
- require 'polisher/vendor'
6
+ require 'polisher/mixins/vendored_deps'
9
7
 
10
8
  module Polisher
11
9
  describe HasVendoredDeps do
@@ -16,7 +14,7 @@ module Polisher
16
14
 
17
15
  describe "#vendored_file_paths" do
18
16
  it "returns file marks in gem marked as vendored" do
19
- expected = [ 'vendor/foo.rb', 'vendor/bar/foo.rb']
17
+ expected = ['vendor/foo.rb', 'vendor/bar/foo.rb']
20
18
  paths = ['foo.rb'] + expected
21
19
  gem = Polisher::Gem.new
22
20
  gem.should_receive(:file_paths).and_return(paths)
@@ -0,0 +1,48 @@
1
+ # Polisher VersionedDependencies Spec
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2013-2014 Red Hat, Inc.
5
+
6
+ require 'polisher/mixins/versioned_dependencies'
7
+
8
+ module Polisher
9
+ describe VersionedDependencies do
10
+ before(:each) do
11
+ @obj = Object.new
12
+ @obj.extend(VersionedDependencies)
13
+ end
14
+
15
+ it "retrieves versions of each dependency in configured targets"
16
+ it "invokes block with targets / versions"
17
+
18
+ describe "#dependency_for" do
19
+ it "returns dependency w/ the specified name" do
20
+ dep1 = ::Gem::Dependency.new 'dep1'
21
+ dep2 = ::Gem::Dependency.new 'dep2'
22
+ @obj.should_receive(:deps).twice.and_return([dep1, dep2])
23
+ @obj.dependency_for('dep1').should == dep1
24
+ @obj.dependency_for('dep2').should == dep2
25
+ end
26
+ end
27
+
28
+ describe "#missing_dependencies" do
29
+ it "returns dependencies with no matching target versions"
30
+ end
31
+
32
+ describe "#dependencies_satisfied?" do
33
+ context "no missing dependencies" do
34
+ it "returns true" do
35
+ @obj.should_receive(:missing_dependencies).and_return([])
36
+ @obj.dependencies_satisfied?.should be_true
37
+ end
38
+ end
39
+
40
+ context "missing dependencies found" do
41
+ it "returns false" do
42
+ @obj.should_receive(:missing_dependencies).and_return(['rails'])
43
+ @obj.dependencies_satisfied?.should be_false
44
+ end
45
+ end
46
+ end
47
+ end # described VersionedDependencies
48
+ end # module Polisher
@@ -0,0 +1,48 @@
1
+ # Polisher RPM Patch Specs
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2014 Red Hat, Inc.
5
+
6
+ require 'polisher/rpm/patch'
7
+
8
+ module Polisher::RPM
9
+ describe Patch do
10
+ let(:patch) { described_class.new }
11
+
12
+ describe "#initialize" do
13
+ it "initializes patch attributes" do
14
+ patch.title = 'title'
15
+ patch.content = 'content'
16
+ end
17
+ end
18
+
19
+ describe "#spec_line" do
20
+ it "returns spec patch line" do
21
+ patch.title = 'title'
22
+ patch.spec_line(1).should == "Patch1: title"
23
+ end
24
+ end
25
+
26
+ describe "::from" do
27
+ it "returns patch for each file modified in diff" do
28
+ diff = "diff -r file1.rb file2.rb\ncontents\ncontents\n" \
29
+ "diff -r file2.rb file3.rb\nmore contents"
30
+ result = described_class.from(diff)
31
+
32
+ result.size.should == 2
33
+ result[0].should be_an_instance_of(Patch)
34
+ result[0].title.should == 'file1.rb'
35
+ result[0].content.should == "contents\ncontents\n"
36
+ result[1].should be_an_instance_of(Patch)
37
+ result[1].title.should == 'file2.rb'
38
+ result[1].content.should == "more contents"
39
+ end
40
+
41
+ it "skips 'Only In Lines'" do
42
+ diff = "diff -r file1.rb file2.rb\ncontents\nOnly in foo.rb"
43
+ result = described_class.from(diff)
44
+ result[0].content.should == "contents\n"
45
+ end
46
+ end
47
+ end # describe Patch
48
+ end # module Polisher::RPM
@@ -0,0 +1,34 @@
1
+ #
2
+ # Licensed under the MIT license
3
+ # Copyright (C) 2014 Red Hat, Inc.
4
+
5
+ require 'polisher/rpm/requirement'
6
+
7
+ module Polisher::RPM
8
+ describe Requirement do
9
+ describe "#str" do
10
+ it "returns requirement in string format" do
11
+ req = described_class.new :name => 'rubygem(activesupport)'
12
+ req.str.should == 'rubygem(activesupport)'
13
+
14
+ req = described_class.new :name => 'rubygem(activesupport)',
15
+ :condition => '>=', :version => '4.0'
16
+ req.str.should == 'rubygem(activesupport) >= 4.0'
17
+ end
18
+ end
19
+
20
+ describe "#specifier" do
21
+ it "returns specifier in string format" do
22
+ req = described_class.new :condition => '>=', :version => '10.0'
23
+ req.specifier.should == '>= 10.0'
24
+ end
25
+
26
+ context "version is nil" do
27
+ it "returns nil" do
28
+ req = described_class.new
29
+ req.specifier.should be_nil
30
+ end
31
+ end
32
+ end
33
+ end # describe Requirement
34
+ end # module Polisher::RPM
@@ -0,0 +1,286 @@
1
+ #
2
+ # Licensed under the MIT license
3
+ # Copyright (C) 2014 Red Hat, Inc.
4
+
5
+ require 'polisher/rpm/spec'
6
+ require 'polisher/rpm/requirement'
7
+
8
+ module Polisher::RPM
9
+ describe Requirement do
10
+ describe "#==" do
11
+ context "requirements are equal" do
12
+ it "returns true" do
13
+ req1 = described_class.new
14
+ req2 = described_class.new
15
+ req1.should == req2
16
+
17
+ req1 = described_class.parse 'rubygem(rails)'
18
+ req2 = described_class.parse 'rubygem(rails)'
19
+ req1.should == req2
20
+
21
+ req1 = described_class.parse 'rubygem(rails) >= 1.0.0'
22
+ req2 = described_class.parse 'rubygem(rails) >= 1.0.0'
23
+ req1.should == req2
24
+ end
25
+ end
26
+
27
+ context "requirements are not equal" do
28
+ it "returns true" do
29
+ req1 = described_class.parse 'rubygem(rails)'
30
+ req2 = described_class.parse 'rubygem(rake)'
31
+ req1.should_not == req2
32
+
33
+ req1 = described_class.parse 'rubygem(rake) > 1'
34
+ req2 = described_class.parse 'rubygem(rake) > 2'
35
+ req1.should_not == req2
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#gcd" do
41
+ it "selects / returns max version less than local version" do
42
+ req = described_class.new :version => "5.0.0"
43
+ req.gcd(['1.0', '2.0', '5.0', '5.1', '6.1']).should == '2.0'
44
+ end
45
+ end
46
+
47
+ describe "#min_satisfying_version" do
48
+ context "no version req" do
49
+ it "returns 0" do
50
+ req = described_class.new
51
+ req.min_satisfying_version.should == "0.0"
52
+ end
53
+ end
54
+
55
+ context "= req" do
56
+ it "returns local version" do
57
+ req = described_class.new :condition => '=', :version => '5.0.0'
58
+ req.min_satisfying_version.should == '5.0.0'
59
+ end
60
+ end
61
+
62
+ context "> req" do
63
+ it "returns next version" do
64
+ req = described_class.new :condition => '>', :version => '5.0.0'
65
+ req.min_satisfying_version.should == '5.0.1'
66
+ end
67
+ end
68
+
69
+ context ">= req" do
70
+ it "returns local version" do
71
+ req = described_class.new :condition => '>=', :version => '5.0.0'
72
+ req.min_satisfying_version.should == '5.0.0'
73
+ end
74
+ end
75
+
76
+ context "< req" do
77
+ it "returns 0" do
78
+ req = described_class.new :condition => '<', :version => '5.0.0'
79
+ req.min_satisfying_version.should == "0.0"
80
+ end
81
+ end
82
+
83
+ context "<= req" do
84
+ it "returns 0" do
85
+ req = described_class.new :condition => '<=', :version => '5.0.0'
86
+ req.min_satisfying_version.should == "0.0"
87
+ end
88
+ end
89
+ end
90
+
91
+ describe "#max_version_satisfying" do
92
+ context "no version req" do
93
+ it "returns infinity" do
94
+ req = described_class.new
95
+ req.max_satisfying_version.should == Float::INFINITY
96
+ end
97
+ end
98
+
99
+ context "= req" do
100
+ it "returns version" do
101
+ req = described_class.new :condition => '=', :version => '1.2.3'
102
+ req.max_satisfying_version.should == '1.2.3'
103
+ end
104
+ end
105
+
106
+ context "> req" do
107
+ it "returns infinity" do
108
+ req = described_class.new :condition => '>', :version => '1.2.3'
109
+ req.max_satisfying_version.should == Float::INFINITY
110
+ end
111
+ end
112
+
113
+ context ">= req" do
114
+ it "returns infinity" do
115
+ req = described_class.new :condition => '>=', :version => '1.2.3'
116
+ req.max_satisfying_version.should == Float::INFINITY
117
+ end
118
+ end
119
+
120
+ context "< req" do
121
+ context "versions list not specified" do
122
+ it "raises argument error" do
123
+ req = described_class.new :condition => '<', :version => '1.2.3'
124
+ lambda {
125
+ req.max_satisfying_version
126
+ }.should raise_error(ArgumentError)
127
+ end
128
+ end
129
+
130
+ it "returns gcd of list" do
131
+ req = described_class.new :condition => '<', :version => '1.2.3'
132
+ req.should_receive(:gcd).and_return('3')
133
+ req.max_satisfying_version(['1', '2']).should == '3'
134
+ end
135
+ end
136
+
137
+ context "<= req" do
138
+ it "returns version" do
139
+ req = described_class.new :condition => '<=', :version => '1.2.3'
140
+ req.max_satisfying_version.should == '1.2.3'
141
+ end
142
+ end
143
+ end
144
+
145
+ describe "#min_failing_version" do
146
+ context "no version req" do
147
+ it "raises argument error" do
148
+ req = described_class.new
149
+ lambda{
150
+ req.min_failing_version
151
+ }.should raise_error(ArgumentError)
152
+ end
153
+ end
154
+
155
+ context "= req" do
156
+ it "returns next version" do
157
+ req = described_class.new :condition => '=', :version => '5.0.0'
158
+ req.min_failing_version.should == '5.0.1'
159
+ end
160
+ end
161
+
162
+ context "> req" do
163
+ it "returns 0" do
164
+ req = described_class.new :condition => '>', :version => '5.0.0'
165
+ req.min_failing_version.should == '0.0'
166
+ end
167
+ end
168
+
169
+ context ">= req" do
170
+ it "returns 0" do
171
+ req = described_class.new :condition => '>=', :version => '5.0.0'
172
+ req.min_failing_version.should == '0.0'
173
+ end
174
+ end
175
+
176
+ context "< req" do
177
+ it "returns version" do
178
+ req = described_class.new :condition => '<', :version => '5.0.0'
179
+ req.min_failing_version.should == '5.0.0'
180
+ end
181
+ end
182
+
183
+ context "<= req" do
184
+ it "returns next version" do
185
+ req = described_class.new :condition => '<=', :version => '5.0.0'
186
+ req.min_failing_version.should == '5.0.1'
187
+ end
188
+ end
189
+ end
190
+
191
+ describe "#max_failing_version" do
192
+ context "no version req" do
193
+ it "raises argument error" do
194
+ req = described_class.new
195
+ lambda {
196
+ req.max_failing_version
197
+ }.should raise_error(ArgumentError)
198
+ end
199
+ end
200
+
201
+ context "= req" do
202
+ context "versions are nil" do
203
+ it "raises ArgumentError" do
204
+ req = described_class.new :condition => '=', :version => '2.0'
205
+ lambda {
206
+ req.max_failing_version
207
+ }.should raise_error(ArgumentError)
208
+ end
209
+ end
210
+
211
+ it "returns gcd of list" do
212
+ req = described_class.new :condition => '=', :version => '2.0'
213
+ req.should_receive(:gcd).and_return('abc')
214
+ req.max_failing_version(['1.2']).should == 'abc'
215
+ end
216
+ end
217
+
218
+ context "> req" do
219
+ it "returns version" do
220
+ req = described_class.new :condition => '>', :version => '2.0'
221
+ req.max_failing_version.should == '2.0'
222
+ end
223
+ end
224
+
225
+ context ">= req" do
226
+ context "versions are nil" do
227
+ it "raises ArgumentError" do
228
+ req = described_class.new :condition => '>=', :version => '2.0'
229
+ lambda {
230
+ req.max_failing_version
231
+ }.should raise_error(ArgumentError)
232
+ end
233
+ end
234
+
235
+ it "returns gcd of list" do
236
+ req = described_class.new :condition => '>=', :version => '2.0'
237
+ req.should_receive(:gcd).and_return('abc')
238
+ req.max_failing_version(['1.2']).should == 'abc'
239
+ end
240
+ end
241
+
242
+ context "< req" do
243
+ it "raises argument error" do
244
+ req = described_class.new :condition => '<', :version => '2.0'
245
+ lambda {
246
+ req.max_failing_version
247
+ }.should raise_error(ArgumentError)
248
+ end
249
+ end
250
+
251
+ context "<= req" do
252
+ it "raises argument error" do
253
+ req = described_class.new :condition => '<', :version => '2.0'
254
+ lambda {
255
+ req.max_failing_version
256
+ }.should raise_error(ArgumentError)
257
+ end
258
+ end
259
+ end
260
+
261
+ describe "#matches?" do
262
+ context "requirement is same as dep requirement" do
263
+ it "returns true" do
264
+ dep = ::Gem::Dependency.new 'rails', '~> 1.0.0'
265
+ req = described_class.new :name => 'rubygem(rails)',
266
+ :condition => '=>',
267
+ :version => '1.0.0'
268
+ req.matches?(dep).should be_true
269
+
270
+ req.condition = '<'
271
+ req.version = '1.1'
272
+ req.matches?(dep).should be_true
273
+ end
274
+ end
275
+
276
+ context "requirement is not same as dep requirement" do
277
+ it "returns false" do
278
+ dep = ::Gem::Dependency.new 'rails'
279
+ req = described_class.new :name => 'rake'
280
+
281
+ req.matches?(dep).should be_false
282
+ end
283
+ end
284
+ end
285
+ end # describe Requirement
286
+ end # module Polisher::RPM