summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rubygems/test_gem_commands_fetch_command.rb
blob: c452e79f14740acac1e74957508465c9fe2c9da0 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
require 'rubygems/test_case'
require 'rubygems/package'
require 'rubygems/security'
require 'rubygems/commands/fetch_command'

class TestGemCommandsFetchCommand < Gem::TestCase

  def setup
    super

    @cmd = Gem::Commands::FetchCommand.new
  end

  def test_execute
    specs = spec_fetcher do |fetcher|
      fetcher.gem 'a', 2
    end

    refute_path_exists File.join(@tempdir, 'cache'), 'sanity check'

    @cmd.options[:args] = %w[a]

    use_ui @ui do
      Dir.chdir @tempdir do
        @cmd.execute
      end
    end

    a2 = specs['a-2']

    assert_path_exists(File.join(@tempdir, a2.file_name),
                       "#{a2.full_name} not fetched")
    refute_path_exists File.join(@tempdir, 'cache'),
                       'gem repository directories must not be created'
  end

  def test_execute_latest
    specs = spec_fetcher do |fetcher|
      fetcher.gem 'a', 1
      fetcher.gem 'a', 2
    end

    refute_path_exists File.join(@tempdir, 'cache'), 'sanity check'

    @cmd.options[:args] = %w[a]
    @cmd.options[:version] = req('>= 0.1')

    use_ui @ui do
      Dir.chdir @tempdir do
        @cmd.execute
      end
    end

    a2 = specs['a-2']
    assert_path_exists(File.join(@tempdir, a2.file_name),
                       "#{a2.full_name} not fetched")
    refute_path_exists File.join(@tempdir, 'cache'),
                       'gem repository directories must not be created'
  end

  def test_execute_prerelease
    specs = spec_fetcher do |fetcher|
      fetcher.gem 'a', 2
      fetcher.gem 'a', '2.a'
    end

    @cmd.options[:args] = %w[a]
    @cmd.options[:prerelease] = true

    use_ui @ui do
      Dir.chdir @tempdir do
        @cmd.execute
      end
    end

    a2 = specs['a-2']

    assert_path_exists(File.join(@tempdir, a2.file_name),
                       "#{a2.full_name} not fetched")
  end

  def test_execute_specific_prerelease
    specs = spec_fetcher do |fetcher|
      fetcher.gem 'a', 2
      fetcher.gem 'a', '2.a'
    end

    @cmd.options[:args] = %w[a]
    @cmd.options[:prerelease] = true
    @cmd.options[:version] = "2.a"

    use_ui @ui do
      Dir.chdir @tempdir do
        @cmd.execute
      end
    end

    a2_pre = specs['a-2.a']

    assert_path_exists(File.join(@tempdir, a2_pre.file_name),
                       "#{a2_pre.full_name} not fetched")
  end

  def test_execute_version
    specs = spec_fetcher do |fetcher|
      fetcher.gem 'a', 1
      fetcher.gem 'a', 2
    end

    @cmd.options[:args] = %w[a]
    @cmd.options[:version] = Gem::Requirement.new '1'

    use_ui @ui do
      Dir.chdir @tempdir do
        @cmd.execute
      end
    end

    a1 = specs['a-1']

    assert_path_exists(File.join(@tempdir, a1.file_name),
                       "#{a1.full_name} not fetched")
  end

end