Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactoring gem archiver

  • Loading branch information...
commit b16361ad7aaf50e35c2d5d7e701e34ef1963e9c1 1 parent 3fb1734
@tenderlove authored
View
3  lib/busted/collectors.rb
@@ -1,3 +1,4 @@
require 'busted/collectors/collector'
require 'busted/collectors/ruby_info'
-require 'busted/collectors/gem_info'
+require 'busted/collectors/rubygems_info'
+require 'busted/collectors/gem_archiver'
View
13 lib/busted/collectors/gem_archiver.rb
@@ -0,0 +1,13 @@
+module Busted
+ module Collectors
+ class GemArchiver < Collector
+ def process gemspec
+ dirname = File.expand_path('.')
+ FileUtils.rm_rf(dirname)
+ FileUtils.mkdir_p(dirname)
+ FileUtils.cp_r(gemspec.full_gem_path, dirname)
+ File.join(dirname, File.basename(gemspec.full_gem_path))
+ end
+ end
+ end
+end
View
2  lib/busted/collectors/gem_info.rb → lib/busted/collectors/rubygems_info.rb
@@ -1,6 +1,6 @@
module Busted
module Collectors
- class GemInfo < Collector
+ class RubygemsInfo < Collector
def process gemspec = nil
template_file = File.join(BASEDIR, 'templates', 'gem_info.erb')
template = ERB.new(File.read(template_file))
View
8 lib/busted/gem.rb
@@ -20,7 +20,7 @@ def initialize gemspec
@gemspec = gemspec
@tarcommand = 'tar'
@zipcommand = 'zip'
- @scratch_dir = File.join(Dir.tmpdir, $$.to_s)
+ @scratch_dir = File.join(Dir.tmpdir, Time.now.to_i.to_s)
FileUtils.mkdir_p(@scratch_dir)
Dir.chdir @scratch_dir
end
@@ -49,11 +49,7 @@ def gem_info_file
private
def copy_gem
- dirname = File.join(Dir::tmpdir, File.basename(@gemspec.full_gem_path))
- FileUtils.rm_rf(dirname)
- FileUtils.mkdir_p(dirname)
- FileUtils.cp_r(@gemspec.full_gem_path, dirname)
- dirname
+ Collectors::GemArchiver.new(@scratch_dir).process(@gemspec)
end
end
end
View
8 test/busted/test_gem.rb
@@ -16,13 +16,5 @@ def test_spec_for
assert broken_gem
assert broken_gem.version
end
-
- def test_archive_file
- broken = Busted::Gem.new(@spec)
- filename = broken.archive_file
- assert_match Dir::tmpdir, filename
- assert File.exists?(filename)
- end
-
end
end
View
40 test/collectors/test_gem_archiver.rb
@@ -0,0 +1,40 @@
+require 'helper'
+require 'find'
+
+module Busted
+ module Collectors
+ class TestGemArchiver < TestCase
+ def setup
+ @scratch_dir = File.join(Dir.tmpdir, Time.now.to_i.to_s)
+ FileUtils.mkdir_p @scratch_dir
+ @ga = GemArchiver.new @scratch_dir
+
+ dep = ::Gem::Dependency.new('', ::Gem::Requirement.default)
+ specs = ::Gem.source_index.search dep
+ @spec = specs.first
+ end
+
+ def test_save_to_scratch_dir
+ dir = @ga.process @spec
+ assert_match @scratch_dir, dir
+ end
+
+ def test_process
+ dir = @ga.process @spec
+ bn = File.basename(@spec.full_gem_path)
+ expected = []
+ actual = []
+
+ Find.find(dir) do |path|
+ actual << path.sub(/^.*#{bn}/, '')
+ end
+ Find.find(@spec.full_gem_path) do |path|
+ expected << path.sub(/^.*#{bn}/, '')
+ end
+
+ assert_equal expected.length, actual.length
+ assert_equal expected.sort, actual.sort
+ end
+ end
+ end
+end
View
2  test/collectors/test_ruby_info.rb
@@ -4,7 +4,7 @@ module Busted
module Collectors
class TestRubyInfo < TestCase
def setup
- @scratch_dir = File.join(Dir.tmpdir, $$.to_s)
+ @scratch_dir = File.join(Dir.tmpdir, Time.now.to_i.to_s)
FileUtils.mkdir_p @scratch_dir
@ri = RubyInfo.new @scratch_dir
end
View
4 test/collectors/test_gem_info.rb → test/collectors/test_rubygems_info.rb
@@ -2,11 +2,11 @@
module Busted
module Collectors
- class TestGemInfo < TestCase
+ class TestRubygemsInfo < TestCase
def setup
@scratch_dir = File.join(Dir.tmpdir, $$.to_s)
FileUtils.mkdir_p @scratch_dir
- @gi = GemInfo.new @scratch_dir
+ @gi = RubygemsInfo.new @scratch_dir
end
def test_writes_to_scratch_dir
Please sign in to comment.
Something went wrong with that request. Please try again.