polisher 0.9.1 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ # Polisher Tag Mapper, simple mechanism to associate
2
+ # tags with each other
3
+ #
4
+ # Licensed under the MIT license
5
+ # Copyright (C) 2013-2014 Red Hat, Inc.
6
+
7
+ require 'polisher/core'
8
+
9
+ module Polisher
10
+ class TagMapper
11
+ extend ConfHelpers
12
+
13
+ def self.method_missing(id, *args)
14
+ set(id.to_s, args.first)
15
+ end
16
+
17
+ def self.set(tag, value)
18
+ @tags ||= {}
19
+ @tags[tag] = value
20
+ end
21
+
22
+ def self.map(tag)
23
+ @tags ||= {}
24
+ @tags[tag]
25
+ end
26
+ end # class TagMapper
27
+ end # module Polisher
@@ -1,3 +1,3 @@
1
1
  module Polisher
2
- VERSION = "0.9.1"
2
+ VERSION = "0.10.1"
3
3
  end
@@ -4,9 +4,12 @@
4
4
  # Copyright (C) 2013-2014 Red Hat, Inc.
5
5
 
6
6
  require 'polisher/gem'
7
+ require 'polisher/logger'
7
8
 
8
9
  module Polisher
9
10
  class VersionChecker
11
+ extend Logging
12
+
10
13
  GEM_TARGET = :gem
11
14
  KOJI_TARGET = :koji
12
15
  FEDORA_TARGET = :fedora
@@ -20,7 +23,7 @@ module Polisher
20
23
  # Enable the specified target(s) in the list of target to check
21
24
  def self.check(*target)
22
25
  @check_list ||= []
23
- target.each { |t| @check_list << t }
26
+ target.flatten.each { |t| @check_list << t }
24
27
  end
25
28
 
26
29
  def self.should_check?(target)
@@ -40,37 +43,88 @@ module Polisher
40
43
  versions = {}
41
44
 
42
45
  if should_check?(GEM_TARGET)
43
- versions.merge! :gem => Gem.local_versions_for(name, &bl)
46
+ logger.debug "versions_for<gem>(#{name})..."
47
+ gem_versions = Gem.local_versions_for(name, &bl)
48
+ logger.debug gem_versions
49
+ versions.merge! :gem => gem_versions
44
50
  end
45
51
 
46
52
  if should_check?(FEDORA_TARGET)
47
- require 'polisher/fedora'
48
- versions.merge! :fedora => Fedora.versions_for(name, &bl)
53
+ begin
54
+ require 'polisher/fedora'
55
+ logger.debug "versions_for<fedora>(#{name})..."
56
+ fedora_versions = Fedora.versions_for(name, &bl)
57
+ logger.debug fedora_versions
58
+ versions.merge! :fedora => fedora_versions
59
+ rescue
60
+ logger.debug 'unknown'
61
+ versions.merge! :fedora => unknown_version(:fedora, name, &bl)
62
+ end
49
63
  end
50
64
 
51
65
  if should_check?(KOJI_TARGET)
52
- require 'polisher/koji'
53
- versions.merge! :koji => Koji.versions_for(name, &bl)
66
+ begin
67
+ require 'polisher/koji'
68
+ logger.debug "versions_for<koji>(#{name})..."
69
+ koji_versions = Koji.versions_for(name, &bl)
70
+ logger.debug koji_versions
71
+ versions.merge! :koji => koji_versions
72
+ rescue
73
+ logger.debug 'unknown'
74
+ versions.merge! :koji => unknown_version(:koji, name, &bl)
75
+ end
54
76
  end
55
77
 
56
78
  if should_check?(GIT_TARGET)
57
- require 'polisher/git/pkg'
58
- versions.merge! :git => [Git::Pkg.version_for(name, &bl)]
79
+ begin
80
+ require 'polisher/git/pkg'
81
+ logger.debug "versions_for<git>(#{name})..."
82
+ git_versions = Git::Pkg.versions_for(name, &bl)
83
+ logger.debug git_versions
84
+ versions.merge! :git => git_versions
85
+ rescue
86
+ logger.debug 'unknown'
87
+ versions.merge! :git => unknown_version(:git, name, &bl)
88
+ end
59
89
  end
60
90
 
61
91
  if should_check?(YUM_TARGET)
62
- require 'polisher/yum'
63
- versions.merge! :yum => [Yum.version_for(name, &bl)]
92
+ begin
93
+ require 'polisher/yum'
94
+ logger.debug "versions_for<yum>(#{name})..."
95
+ yum_versions = [Yum.version_for(name, &bl)]
96
+ versions.merge! :yum => yum_versions
97
+ logger.debug yum_versions
98
+ rescue
99
+ logger.debug 'unknown'
100
+ versions.merge! :yum => unknown_version(:yum, name, &bl)
101
+ end
64
102
  end
65
103
 
66
104
  if should_check?(BODHI_TARGET)
67
- require 'polisher/bodhi'
68
- versions.merge! :bodhi => Bodhi.versions_for(name, &bl)
105
+ begin
106
+ require 'polisher/bodhi'
107
+ logger.debug "versions_for<bodhi>(#{name})..."
108
+ bodhi_versions = Bodhi.versions_for(name, &bl)
109
+ versions.merge! :bodhi => bodhi_versions
110
+ logger.debug bodhi_versions
111
+ rescue
112
+ logger.debug 'unknown'
113
+ versions.merge! :bodhi => unknown_version(:bodhi, name, &bl)
114
+ end
69
115
  end
70
116
 
71
117
  if should_check?(ERRATA_TARGET)
72
- require 'polisher/errata'
73
- versions.merge! :errata => Errata.versions_for(name, &bl)
118
+ begin
119
+ require 'polisher/errata'
120
+ logger.debug "versions_for<errata>(#{name})..."
121
+ errata_versions = Errata.versions_for(name, &bl)
122
+ versions.merge! :errata => errata_versions
123
+ logger.debug errata_versions
124
+ rescue
125
+ logger.debug 'unknown'
126
+ versions.merge! :errata => unknown_version(:errata, name, &bl)
127
+ end
74
128
  end
75
129
 
76
130
  versions
@@ -81,7 +135,12 @@ module Polisher
81
135
  # returns the max.
82
136
  def self.version_for(name)
83
137
  versions = self.versions_for(name).values
84
- versions.inject(Hasn.new(0)) { |total, i| total[i] += 1; total }.first
138
+ versions.inject(Hash.new(0)) { |total, i| total[i] += 1; total }.first
139
+ end
140
+
141
+ # Invoke block for specified target w/ an 'unknown' version
142
+ def self.unknown_version(tgt, name)
143
+ yield tgt, name, [:unknown]
85
144
  end
86
145
  end
87
146
 
@@ -98,11 +157,21 @@ module Polisher
98
157
  def dependency_versions(args = {}, &bl)
99
158
  args = {:recursive => true, :dev_deps => true}.merge(args)
100
159
  versions = {}
101
- self.deps.each do |dep|
102
- gem = Polisher::Gem.retrieve(dep)
160
+ deps.each do |dep|
161
+ gem = Polisher::Gem.retrieve(dep.name)
103
162
  versions.merge!(gem.versions(args, &bl))
104
163
  end
105
164
  versions
106
165
  end
166
+
167
+ # Return list of states which gem dependencies are in
168
+ def dependency_states
169
+ states = {}
170
+ deps.each do |dep|
171
+ gem = Polisher::Gem.new :name => dep.name
172
+ states.merge dep.name => gem.state(:check => dep)
173
+ end
174
+ states
175
+ end
107
176
  end
108
177
  end
@@ -3,28 +3,35 @@
3
3
  # Licensed under the MIT license
4
4
  # Copyright (C) 2013-2014 Red Hat, Inc.
5
5
 
6
- require 'awesome_spawn'
6
+ require 'polisher/core'
7
+ require 'polisher/component'
7
8
 
8
9
  module Polisher
9
- class Yum
10
- YUM_CMD = '/usr/bin/yum'
10
+ Component.verify("Yum", 'awesome_spawn') do
11
+ class Yum
12
+ include ConfHelpers
11
13
 
12
- # Retrieve version of gem available in yum
13
- #
14
- # @param [String] name name of gem to loopup
15
- # @param [Callable] bl optional callback to invoke with version retrieved
16
- # @returns [String] version of gem in yum or nil if not found
17
- def self.version_for(name, &bl)
18
- version = nil
19
- result = AwesomeSpawn.run "#{YUM_CMD} info rubygem-#{name}"
20
- out = result.output
14
+ conf_attr :yum_cmd, '/usr/bin/yum'
21
15
 
22
- if out.include?("Version")
23
- version = out.lines.to_a.find { |l| l =~ /^Version.*/ }
24
- version = version.split(':').last.strip
16
+ # Retrieve version of gem available in yum
17
+ #
18
+ # @param [String] name name of gem to loopup
19
+ # @param [Callable] bl optional callback to invoke with version retrieved
20
+ # @returns [String] version of gem in yum or nil if not found
21
+ def self.version_for(name, &bl)
22
+ require_cmd! yum_cmd
23
+
24
+ version = nil
25
+ result = AwesomeSpawn.run "#{yum_cmd} info rubygem-#{name}"
26
+ out = result.output
27
+
28
+ if out.include?("Version")
29
+ version = out.lines.to_a.detect { |l| l =~ /^Version.*/ }
30
+ version = version.split(':').last.strip
31
+ end
32
+ bl.call(:yum, name, [version]) unless bl.nil?
33
+ version
25
34
  end
26
- bl.call(:yum, name, [version]) unless(bl.nil?)
27
- version
28
35
  end
29
- end
30
- end
36
+ end # Component.verify("Yum")
37
+ end # module Polisher
@@ -0,0 +1,53 @@
1
+ require 'polisher/component'
2
+
3
+ module Polisher
4
+ describe Component do
5
+ describe ".verify" do
6
+ it "executes block for no missing gems" do
7
+ silence_stream(STDERR) do
8
+ described_class.verify("Z", "rubygems", "rspec") do
9
+ module ::Polisher
10
+ class Z
11
+ def self.yielded_block_executed
12
+ true
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ expect(Polisher::Z.yielded_block_executed).to be_true
20
+ end
21
+
22
+ describe "missing" do
23
+ subject do
24
+ silence_stream(STDERR) do
25
+ described_class.verify(@test_class, "missing_gem") {}
26
+ end
27
+ end
28
+
29
+ it "A" do
30
+ @test_class = "A"
31
+ subject
32
+ expect(Polisher::A).to eql Polisher::Component::Missing
33
+ expect { Polisher::A.new }.to raise_error
34
+ end
35
+
36
+ it "A::B" do
37
+ @test_class = "A::B"
38
+ subject
39
+ expect(Polisher::A).to eql Polisher::Component::Missing
40
+ expect(Polisher::A::B).to eql Polisher::Component::Missing
41
+ end
42
+
43
+ it "A::B::C" do
44
+ @test_class = "A::B::C"
45
+ subject
46
+ expect(Polisher::A).to eql Polisher::Component::Missing
47
+ expect(Polisher::A::B).to eql Polisher::Component::Missing
48
+ expect(Polisher::A::B::C).to eql Polisher::Component::Missing
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -60,5 +60,11 @@ describe String do
60
60
  it "returns string with rpm macros swapped in" do
61
61
  "bin".rpmize.should == "%{_bindir}"
62
62
  end
63
+
64
+ it "prefixes %{gem_instdir} to non-special files" do
65
+ "spec".rpmize.should == "%{gem_instdir}/spec"
66
+ "lib".rpmize.should == "%{gem_libdir}"
67
+ "%{gem_instdir}/foo".rpmize.should == "%{gem_instdir}/foo"
68
+ end
63
69
  end
64
70
  end # describe String
@@ -9,12 +9,20 @@ require 'polisher/gem'
9
9
 
10
10
  module Polisher
11
11
  describe Gem do
12
+ describe "#file_name" do
13
+ it "returns name-version.gem" do
14
+ expected = 'rails-4.0.0.gem'
15
+ Polisher::Gem.new(:name => 'rails', :version => '4.0.0')
16
+ .file_name.should == expected
17
+ end
18
+ end
19
+
12
20
  describe "#initialize" do
13
21
  it "sets gem attributes" do
14
- gem = Polisher::Gem.new :name => 'rails',
15
- :version => '4.0.0',
16
- :deps => ['activesupport', 'activerecord'],
17
- :dev_deps => ['rake']
22
+ gem = described_class.new :name => 'rails',
23
+ :version => '4.0.0',
24
+ :deps => %w(activesupport activerecord),
25
+ :dev_deps => ['rake']
18
26
  gem.name.should == 'rails'
19
27
  gem.version.should == '4.0.0'
20
28
  gem.deps.should == ['activesupport', 'activerecord']
@@ -25,33 +33,67 @@ module Polisher
25
33
  describe "#ignorable_file?" do
26
34
  context "args matches an ignorable file" do
27
35
  it "returns true" do
28
- Polisher::Gem.ignorable_file?('foo.gemspec').should be_true
29
- Polisher::Gem.ignorable_file?('Gemfile').should be_true
36
+ described_class.ignorable_file?('foo.gemspec').should be_true
37
+ described_class.ignorable_file?('Gemfile').should be_true
30
38
  end
31
39
  end
32
40
 
33
41
  context "args does not match an ignorable file" do
34
42
  it "returns false" do
35
- Polisher::Gem.ignorable_file?('.rvmra').should be_false
36
- Polisher::Gem.ignorable_file?('foo.gemspoc').should be_false
43
+ described_class.ignorable_file?('.rvmra').should be_false
44
+ described_class.ignorable_file?('foo.gemspoc').should be_false
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "#doc_file?" do
50
+ context "file is on doc file list" do
51
+ it "returns true" do
52
+ described_class.doc_file?('CHANGELOG').should be_true
53
+ end
54
+ end
55
+
56
+ context "file is not on doc file list" do
57
+ it "returns false" do
58
+ described_class.doc_file?('foobar.rb').should be_false
37
59
  end
38
60
  end
39
61
  end
40
62
 
41
63
  describe "#local_versions_for" do
42
- it "returns versions of specified gem in local db"
43
- it "invokes cb with versions retrieved"
64
+ before(:each) do
65
+ # XXX clear the cached version of the gem specification db
66
+ described_class.instance_variable_set(:@local_db, nil)
67
+
68
+ gem1 = ::Gem::Specification.new 'rake', '1.0'
69
+ gem2 = ::Gem::Specification.new 'rake', '2.0'
70
+ gem3 = ::Gem::Specification.new 'rails', '3.0'
71
+ ::Gem::Specification.should_receive(:all).and_return([gem1, gem2, gem3])
72
+
73
+ @version1 = ::Gem::Version.new '1.0'
74
+ @version2 = ::Gem::Version.new '2.0'
75
+ end
76
+
77
+ it "returns versions of specified gem in local db" do
78
+ described_class.local_versions_for('rake').should == [@version1, @version2]
79
+ end
80
+
81
+ it "invokes cb with versions retrieved" do
82
+ cb = proc {}
83
+ cb.should_receive(:call).with(:local_gem, 'rake', [@version1, @version2])
84
+ described_class.local_versions_for('rake', &cb)
85
+ end
44
86
  end
45
87
 
46
88
  describe "#parse" do
47
89
  it "returns new gem" do
48
- gem = Polisher::Gem.parse
49
- gem.should be_an_instance_of(Polisher::Gem)
90
+ gem = described_class.parse
91
+ gem.should be_an_instance_of(described_class)
50
92
  end
51
93
 
52
94
  it "parses gem from gem spec" do
53
95
  spec = Polisher::Test::GEM_SPEC
54
- gem = Polisher::Gem.parse(:gemspec => spec[:path])
96
+ gem = described_class.parse(:gemspec => spec[:path])
55
97
  gem.name.should == spec[:name]
56
98
  gem.version.should == spec[:version]
57
99
  gem.deps.should == spec[:deps]
@@ -62,7 +104,7 @@ module Polisher
62
104
 
63
105
  it "parses gem from metadata hash" do
64
106
  gemj = Polisher::Test::GEM_JSON
65
- gem = Polisher::Gem.parse gemj[:json]
107
+ gem = described_class.parse gemj[:json]
66
108
  gem.name.should == gemj[:name]
67
109
  gem.version.should == gemj[:version]
68
110
  gem.deps.should == gemj[:deps]
@@ -70,45 +112,103 @@ module Polisher
70
112
  end
71
113
  end
72
114
 
115
+ describe "#remote_versions_for" do
116
+ it "retrieves versions from rubygems.org" do
117
+ curl = Curl::Easy.new
118
+ described_class.should_receive(:client)
119
+ .at_least(:once).and_return(curl)
120
+ curl.should_receive(:http_get)
121
+
122
+ # actual output too verbose, just including bits we need
123
+ curl.should_receive(:body_str)
124
+ .and_return([{'number' => 1.1}, {'number' => 2.2}].to_json)
125
+ described_class.remote_versions_for('polisher').should == [1.1, 2.2]
126
+ curl.url.should == "https://rubygems.org/api/v1/versions/polisher.json"
127
+ end
128
+ end
129
+
130
+ describe "#lastest_version_of" do
131
+ it "retrieves latests version of gem available on rubygems.org" do
132
+ described_class.should_receive(:remote_versions_for)
133
+ .with('polisher')
134
+ .and_return([2.2, 1.1])
135
+ described_class.latest_version_of('polisher').should == 2.2
136
+ end
137
+ end
73
138
 
74
139
  describe "#download_gem" do
75
140
  context "gem in GemCache" do
76
- it "returns GemCache gem"
141
+ it "returns GemCache gem" do
142
+ gem = described_class.new
143
+ GemCache.should_receive(:get).with('polisher', '1.1')
144
+ .and_return(gem)
145
+ described_class.download_gem('polisher', '1.1').should == gem
146
+ end
147
+ end
148
+
149
+ it "uses curl to download gem" do
150
+ GemCache.should_receive(:get).and_return(nil)
151
+ curl = Curl::Easy.new
152
+ described_class.should_receive(:client)
153
+ .at_least(:once).and_return(curl)
154
+ curl.should_receive(:http_get)
155
+ curl.should_receive(:body_str).and_return('') # stub out body_str
156
+
157
+ described_class.download_gem 'polisher', '2.2'
158
+ curl.url.should == "https://rubygems.org/gems/polisher-2.2.gem"
159
+ end
160
+
161
+ it "sets gem in gem cache" do
162
+ GemCache.should_receive(:get).and_return(nil)
163
+ curl = Curl::Easy.new
164
+ described_class.should_receive(:client)
165
+ .at_least(:once).and_return(curl)
166
+ curl.stub(:http_get) # stub out http_get
167
+ curl.should_receive(:body_str).and_return('gem')
168
+ GemCache.should_receive(:set)
169
+ .with('polisher', '1.1', 'gem')
170
+ described_class.download_gem 'polisher', '1.1'
77
171
  end
78
172
 
79
- it "uses curl to download gem"
80
- it "sets gem in gem cached"
81
- it "returns downloaded gem binary contents"
173
+ it "returns downloaded gem binary contents" do
174
+ GemCache.should_receive(:get).and_return(nil)
175
+ curl = Curl::Easy.new
176
+ described_class.should_receive(:client)
177
+ .at_least(:once).and_return(curl)
178
+ curl.stub(:http_get) # stub out http_get
179
+ curl.should_receive(:body_str).and_return('gem')
180
+ described_class.download_gem('polisher', '1.1').should == 'gem'
181
+ end
82
182
  end
83
183
 
84
184
  describe "#download_gem_path" do
85
185
  it "downloads gem" do
86
- gem = Polisher::Gem.new
87
- Polisher::Gem.should_receive(:download_gem)
186
+ gem = described_class.new
187
+ described_class.should_receive(:download_gem)
88
188
  gem.downloaded_gem_path
89
189
  end
90
190
 
91
191
  it "returns gem cache path for gem" do
92
192
  # stub out d/l
93
- gem = Polisher::Gem.new :name => 'rails', :version => '1.0'
94
- Polisher::Gem.should_receive(:download_gem)
95
- Polisher::GemCache.should_receive(:path_for).
96
- with('rails', '1.0').
97
- at_least(:once).
98
- and_return('rails_path')
193
+ gem = described_class.new :name => 'rails', :version => '1.0'
194
+ described_class.should_receive(:download_gem)
195
+ Polisher::GemCache.should_receive(:path_for)
196
+ .with('rails', '1.0')
197
+ .at_least(:once)
198
+ .and_return('rails_path')
99
199
  gem.downloaded_gem_path.should == 'rails_path'
100
200
  end
101
201
  end
102
202
 
103
203
  describe "#gem_path" do
104
204
  it "returns specified path" do
105
- gem = Polisher::Gem.new :path => 'gem_path'
205
+ gem = described_class.new :path => 'gem_path'
106
206
  gem.gem_path.should == 'gem_path'
107
207
  end
108
208
 
109
209
  context "specified path is null" do
110
210
  it "returns downloaded gem path" do
111
- gem = Polisher::Gem.new
211
+ gem = described_class.new
112
212
  gem.should_receive(:downloaded_gem_path).and_return('gem_path')
113
213
  gem.gem_path.should == 'gem_path'
114
214
  end
@@ -126,39 +226,122 @@ module Polisher
126
226
  end
127
227
 
128
228
  describe "#file_paths" do
129
- it "returns list of file paths in gem"
229
+ it "returns list of file paths in gem" do
230
+ gem = described_class.new
231
+ gem.should_receive(:each_file).and_yield('file1').and_yield('file2')
232
+ gem.file_paths.should == %w(file1 file2)
233
+ end
130
234
  end
131
235
 
132
236
  describe "#retrieve" do
133
- before(:each) do
134
- @local_gem = Polisher::Test::LOCAL_GEM
135
- end
136
-
137
237
  it "returns gem retrieved from rubygems" do
138
- gem = Polisher::Gem.retrieve(@local_gem[:name])
139
- gem.should be_an_instance_of(Polisher::Gem)
140
- gem.name.should == @local_gem[:name]
141
- gem.version.should == @local_gem[:version]
142
- gem.deps.should == @local_gem[:deps]
143
- gem.dev_deps.should == @local_gem[:dev_deps]
238
+ curl = Curl::Easy.new
239
+ curl.should_receive(:body_str).and_return('spec')
240
+
241
+ url = "https://rubygems.org/api/v1/gems/rails.json"
242
+ Curl::Easy.should_receive(:http_get).with(url).and_return(curl)
243
+
244
+ gem = described_class.new
245
+ described_class.should_receive(:parse).with('spec').and_return(gem)
246
+
247
+ described_class.retrieve('rails').should == gem
144
248
  end
145
249
  end
146
250
 
147
251
  describe "#versions" do
148
- it "looks up and returns versions for gemname in polisher version checker"
252
+ it "looks up and returns versions of gem" do
253
+ gem = described_class.new :name => 'rails'
254
+ Polisher::VersionChecker.should_receive(:versions_for)
255
+ .with('rails')
256
+ .and_return(:koji => ['1.1.1'])
257
+ gem.versions.should == {'rails' => {:koji => ['1.1.1']}}
258
+ end
149
259
 
150
260
  context "recursive is true" do
151
- it "appends versions of gem dependencies to versions list"
261
+ it "retrieves dependency versions" do
262
+ # stub out version checker
263
+ retrieved = {:koji => ['1.0']}
264
+ Polisher::VersionChecker.should_receive(:versions_for)
265
+ .and_return(retrieved)
266
+
267
+ versions = {}
268
+ gem = described_class.new :name => 'rails'
269
+ gem.should_receive(:dependency_versions)
270
+ .with(:recursive => true, :versions => {'rails' => retrieved})
271
+ .and_call_original
272
+ gem.versions(:recursive => true, :versions => versions)
273
+ .should == {'rails' => {:koji => ['1.0']}}
274
+ end
275
+
152
276
  context "dev_deps is true" do
153
- it "appends versions of gem dev dependencies to versions list"
277
+ it "retrieves dev dependency versions" do
278
+ # stub out version checker
279
+ retrieved = {:koji => ['1.0']}
280
+ Polisher::VersionChecker.should_receive(:versions_for)
281
+ .and_return(retrieved)
282
+
283
+ versions = {}
284
+ gem = described_class.new :name => 'rails'
285
+ gem.should_receive(:dependency_versions)
286
+ .with(:recursive => true, :dev_deps => true,
287
+ :versions => {'rails' => retrieved})
288
+ .and_call_original
289
+ gem.should_receive(:dependency_versions)
290
+ .with(:recursive => true, :dev => true, :dev_deps => true,
291
+ :versions => {'rails' => retrieved})
292
+ .and_call_original
293
+ gem.versions(:recursive => true, :dev_deps => true,
294
+ :versions => versions)
295
+ .should == {'rails' => {:koji => ['1.0']}}
296
+ end
297
+ end
298
+ end
299
+ end
300
+
301
+ describe "#dependency_versions" do
302
+ it "retrieves dependency versions" do
303
+ gem = described_class.new
304
+ gem.should_receive(:deps).and_return([::Gem::Dependency.new('rake')])
305
+ described_class.should_receive(:retrieve)
306
+ .with('rake').and_return(gem)
307
+
308
+ versions = {'rake' => {:koji => ['2.1']}}
309
+ gem.should_receive(:versions).and_return(versions)
310
+ gem.dependency_versions.should == versions
311
+ end
312
+
313
+ it "retrieves dev dependency versions" do
314
+ gem = described_class.new
315
+ gem.should_receive(:dev_deps).and_return([::Gem::Dependency.new('rake')])
316
+ described_class.should_receive(:retrieve)
317
+ .with('rake').and_return(gem)
318
+
319
+ versions = {'rake' => {:koji => ['2.1']}}
320
+ gem.should_receive(:versions).and_return(versions)
321
+ gem.dependency_versions(:dev => true).should == versions
322
+ end
323
+
324
+ context "error during gem or version retrieval" do
325
+ it "sets version to 'unknown'" do
326
+ gem = described_class.new
327
+ gem.should_receive(:deps).and_return([::Gem::Dependency.new('rake')])
328
+ described_class.should_receive(:retrieve)
329
+ .with('rake').and_raise(RuntimeError)
330
+
331
+ versions = {:all => [:unknown]}
332
+ gem.should_not_receive(:versions)
333
+ Polisher::VersionChecker.should_receive(:unknown_version)
334
+ .with(:all, 'rake')
335
+ .and_return(versions)
336
+ gem.dependency_versions.should == {'rake' => versions}
154
337
  end
155
338
  end
156
339
  end
157
340
 
158
341
  describe "#diff" do
159
342
  before(:each) do
160
- @gem1 = Polisher::Gem.new
161
- @gem2 = Polisher::Gem.new
343
+ @gem1 = described_class.new
344
+ @gem2 = described_class.new
162
345
 
163
346
  @result = AwesomeSpawn::CommandResult.new '', 'diff_out', '', 0
164
347
  end
@@ -166,9 +349,9 @@ module Polisher
166
349
  it "runs diff against unpacked local and other gems and returns output" do
167
350
  @gem1.should_receive(:unpack).and_return('dir1')
168
351
  @gem2.should_receive(:unpack).and_return('dir2')
169
- AwesomeSpawn.should_receive(:run).
170
- with("#{Polisher::Gem::DIFF_CMD} -r dir1 dir2").
171
- and_return(@result)
352
+ AwesomeSpawn.should_receive(:run)
353
+ .with("#{Polisher::Gem.diff_cmd} -r dir1 dir2")
354
+ .and_return(@result)
172
355
  @gem1.diff(@gem2).should == @result.output
173
356
  end
174
357