Permalink
Browse files

archiving problematic gem

  • Loading branch information...
1 parent 8cba352 commit e56375131c2114ef8151360aea14d903409e135c @tenderlove committed Feb 6, 2009
Showing with 35 additions and 0 deletions.
  1. +27 −0 lib/busted/gem.rb
  2. +7 −0 test/busted/test_gem.rb
  3. +1 −0 test/helper.rb
View
27 lib/busted/gem.rb
@@ -1,3 +1,5 @@
+require 'tempfile'
+
module Busted
class Gem
class << self
@@ -13,6 +15,31 @@ def spec_for name, version = nil
def initialize gemspec
@gemspec = gemspec
+ @tarcommand = 'tar'
+ @zipcommand = 'zip'
+ end
+
+ def archive_file
+ copy_gem
+ archive_prefix = File.basename(@gemspec.full_gem_path)
+ Dir.chdir(Dir::tmpdir) do
+ begin
+ system %{#{@tarcommand} zcf #{archive_prefix}.tar.gz #{archive_prefix}}
+ return File.join(Dir::tmpdir, "#{archive_prefix}.tar.gz")
+ rescue
+ system %{#{@zipcommand} -r #{archive_prefix}.zip #{archive_prefix}}
+ return File.join(Dir::tmpdir, "#{archive_prefix}.zip")
+ end
+ end
+ end
+
+ 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
end
end
end
View
7 test/busted/test_gem.rb
@@ -16,5 +16,12 @@ 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
1 test/helper.rb
@@ -1,4 +1,5 @@
require 'test/unit'
+require 'tempfile'
require 'busted'
module Busted

0 comments on commit e563751

Please sign in to comment.