~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rubygems/test_gem_commands_unpack_command.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require_relative 'gemutilities'
 
1
require 'rubygems/test_case'
2
2
require 'rubygems/commands/unpack_command'
3
3
 
4
 
class TestGemCommandsUnpackCommand < RubyGemTestCase
 
4
class TestGemCommandsUnpackCommand < Gem::TestCase
5
5
 
6
6
  def setup
7
7
    super
11
11
    end
12
12
  end
13
13
 
 
14
  def test_find_in_cache
 
15
    util_make_gems
 
16
 
 
17
    assert_equal(
 
18
      @cmd.find_in_cache(File.basename @a1.cache_file),
 
19
      @a1.cache_file,
 
20
      'found a-1.gem in the cache'
 
21
    )
 
22
  end
 
23
 
 
24
  def test_get_path
 
25
    util_setup_fake_fetcher
 
26
    util_clear_gems
 
27
    util_setup_spec_fetcher @a1
 
28
 
 
29
    a1_data = nil
 
30
 
 
31
    open @a1.cache_file, 'rb' do |fp|
 
32
      a1_data = fp.read
 
33
    end
 
34
 
 
35
    Gem::RemoteFetcher.fetcher.data['http://gems.example.com/gems/a-1.gem'] =
 
36
      a1_data
 
37
 
 
38
    dep = Gem::Dependency.new(@a1.name, @a1.version)
 
39
    assert_equal(
 
40
      @cmd.get_path(dep),
 
41
      @a1.cache_file,
 
42
      'fetches a-1 and returns the cache path'
 
43
    )
 
44
 
 
45
    FileUtils.rm @a1.cache_file
 
46
 
 
47
    assert_equal(
 
48
      @cmd.get_path(dep),
 
49
      @a1.cache_file,
 
50
      'when removed from cache, refetches a-1'
 
51
    )
 
52
  end
 
53
 
14
54
  def test_execute
15
55
    util_make_gems
16
56
 
27
67
  end
28
68
 
29
69
  def test_execute_gem_path
30
 
    util_make_gems
 
70
    util_setup_fake_fetcher
 
71
    util_setup_spec_fetcher
31
72
 
32
73
    Gem.clear_paths
33
74
 
34
75
    gemhome2 = File.join @tempdir, 'gemhome2'
35
76
 
36
 
    Gem.send :set_paths, [gemhome2, @gemhome].join(File::PATH_SEPARATOR)
37
 
    Gem.send :set_home, gemhome2
 
77
    Gem.paths = { "GEM_PATH" => [gemhome2, @gemhome], "GEM_HOME" => gemhome2 }
38
78
 
39
79
    @cmd.options[:args] = %w[a]
40
80
 
48
88
  end
49
89
 
50
90
  def test_execute_gem_path_missing
51
 
    util_make_gems
 
91
    util_setup_fake_fetcher
52
92
    util_setup_spec_fetcher
53
93
 
54
94
    Gem.clear_paths
55
95
 
56
96
    gemhome2 = File.join @tempdir, 'gemhome2'
57
97
 
58
 
    Gem.send :set_paths, [gemhome2, @gemhome].join(File::PATH_SEPARATOR)
59
 
    Gem.send :set_home, gemhome2
 
98
    Gem.paths = { "GEM_PATH" => [gemhome2, @gemhome], "GEM_HOME" => gemhome2 }
60
99
 
61
100
    @cmd.options[:args] = %w[z]
62
101
 
75
114
    util_clear_gems
76
115
 
77
116
    a2_data = nil
78
 
    open File.join(@gemhome, 'cache', @a2.file_name), 'rb' do |fp|
 
117
    open @a2.cache_file, 'rb' do |fp|
79
118
      a2_data = fp.read
80
119
    end
81
120
 
94
133
    assert File.exist?(File.join(@tempdir, 'a-2')), 'a should be unpacked'
95
134
  end
96
135
 
 
136
  def test_execute_spec
 
137
    util_make_gems
 
138
 
 
139
    @cmd.options[:args] = %w[a b]
 
140
    @cmd.options[:spec] = true
 
141
 
 
142
    use_ui @ui do
 
143
      Dir.chdir @tempdir do
 
144
        @cmd.execute
 
145
      end
 
146
    end
 
147
 
 
148
    assert File.exist?(File.join(@tempdir, 'a-3.a.gemspec'))
 
149
    assert File.exist?(File.join(@tempdir, 'b-2.gemspec'))
 
150
  end
 
151
 
97
152
  def test_execute_sudo
 
153
    skip 'Cannot perform this test on windows (chmod)' if win_platform?
 
154
 
98
155
    util_make_gems
99
156
 
100
 
    File.chmod 0555, @gemhome
 
157
    FileUtils.chmod 0555, @gemhome
101
158
 
102
159
    @cmd.options[:args] = %w[b]
103
160
 
109
166
 
110
167
    assert File.exist?(File.join(@tempdir, 'b-2')), 'b should be unpacked'
111
168
  ensure
112
 
    File.chmod 0755, @gemhome
 
169
    FileUtils.chmod 0755, @gemhome
113
170
  end
114
171
 
115
172
  def test_execute_with_target_option
129
186
  end
130
187
 
131
188
  def test_execute_exact_match
132
 
    foo_spec = quick_gem 'foo'
133
 
    foo_bar_spec = quick_gem 'foo_bar'
 
189
    foo_spec = quick_spec 'foo'
 
190
    foo_bar_spec = quick_spec 'foo_bar'
134
191
 
135
192
    use_ui @ui do
136
193
      Dir.chdir @tempdir do
155
212
    assert File.exist?(File.join(@tempdir, foo_spec.full_name))
156
213
  end
157
214
 
 
215
  def test_handle_options_metadata
 
216
    refute @cmd.options[:spec]
 
217
 
 
218
    @cmd.send :handle_options, %w[--spec a]
 
219
 
 
220
    assert @cmd.options[:spec]
 
221
  end
 
222
 
158
223
end
159
224