File: gem2tgz_test.rb

package info (click to toggle)
gem2deb 2.2.8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,232 kB
  • sloc: ruby: 5,562; sh: 142; perl: 46; makefile: 39; ansic: 33
file content (98 lines) | stat: -rw-r--r-- 3,078 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require_relative '../test_helper'
require 'yaml'
require 'rubygems'

require 'gem2deb/gem2tgz'

class Gem2TgzTest < Gem2DebTestCase

  SIMPLE_GEM_TARBALL    = File.join(tmpdir,    "#{SIMPLE_GEM_DIRNAME}.tar.gz")
  SIMPLE_TGZ_TARBALL    = File.join(tmpdir,    "#{SIMPLE_TGZ_DIRNAME}.tar.gz")

  should 'convert using a new instance when converting through the class' do
    gem2tgz = mock
    gem2tgz.expects(:convert!)
    Gem2Deb::Gem2Tgz.expects(:new).with(SIMPLE_GEM, SIMPLE_GEM_TARBALL).returns(gem2tgz)
    Gem2Deb::Gem2Tgz.convert!(SIMPLE_GEM, SIMPLE_GEM_TARBALL)
  end

  class << self
    attr_accessor :instance
  end
  def instance
    self.class.instance
  end


  one_time_setup do
    self.instance = Gem2Deb::Gem2Tgz.new(SIMPLE_GEM, SIMPLE_GEM_TARBALL)
    self.instance.convert!
  end

  context 'converting a simple gem' do
    should 'create tarball' do
      assert_file_exists SIMPLE_GEM_TARBALL
    end
    should 'include the contents of the gem in the tarball' do
      assert_contained_in_tarball SIMPLE_GEM_TARBALL, 'simplegem-0.0.1/lib/simplegem.rb'
    end
    should 'not include data.tar.gz' do
      assert_not_contained_in_tarball SIMPLE_GEM_TARBALL, 'simplegem-0.0.1/data.tar.gz'
    end
    should 'not include metadata.gz' do
      assert_not_contained_in_tarball SIMPLE_GEM_TARBALL, 'simplegem-0.0.1/metadata.gz'
    end
    should 'not leave temporary directory after creating tarball' do
      assert_no_file_exists instance.target_dir
    end
    should 'not leave metadata.yml in the tarball' do
      assert_not_contained_in_tarball SIMPLE_GEM_TARBALL, 'simplegem-0.0.1/metadata.yml'
    end
    should 'create gemspec' do
      unpack(SIMPLE_GEM_TARBALL) do
        assert_file_exists 'simplegem-0.0.1/simplegem.gemspec'
      end
    end
    should 'not include checksums.yaml.gz' do
      assert_not_contained_in_tarball SIMPLE_GEM_TARBALL, 'simplegem-0.0.1/checksums.yaml.gz'
    end
    context 'looking inside generated gemspec' do
      setup do
        @gemspec = unpack(SIMPLE_GEM_TARBALL) do
          Gem::Specification.load('simplegem-0.0.1/simplegem.gemspec')
        end
      end
      should 'be a valid gemspec' do
        assert_kind_of Gem::Specification, @gemspec
      end
      should "be simplegem's spec" do
        assert_equal 'simplegem', @gemspec.name
      end
    end
  end

  context('tgz package') do
    setup do
      @tgz = Gem2Deb::Gem2Tgz.new(SIMPLE_TGZ, SIMPLE_TGZ_TARBALL)
      @tgz.convert!
    end
    should 'create tarball' do
      assert_file_exists SIMPLE_TGZ_TARBALL
    end
    should 'include the contents of the tgz in the tarball' do
      assert_contained_in_tarball SIMPLE_TGZ_TARBALL, 'simpletgz-0.0.1/lib/simpletgz.rb'
    end
  end

  should 'not mess with the full path' do
    testdir = File.join(tmpdir, 'Downloads') # uppercase
    FileUtils.mkdir_p(testdir)
    FileUtils.cp(SIMPLE_GEM, testdir)
    gem = File.join(testdir, File.basename(SIMPLE_GEM))
    tarball = gem.gsub('.gem', '.tar.gz')

    Gem2Deb::Gem2Tgz.new(gem).convert!
    assert File.exist?(tarball)
  end

end