summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rubygems/test_gem_commands_environment_command.rb
blob: 81ff55d357a4c7b4be40280f787fda40974420a3 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
require 'rubygems/test_case'
require 'rubygems/commands/environment_command'

class TestGemCommandsEnvironmentCommand < Gem::TestCase

  def setup
    super

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

  def test_execute
    orig_sources = Gem.sources.dup
    orig_path, ENV['PATH'] = ENV['PATH'], %w[/usr/local/bin /usr/bin /bin].join(File::PATH_SEPARATOR)
    Gem.sources.replace %w[http://gems.example.com]
    Gem.configuration['gemcutter_key'] = 'blah'

    @cmd.send :handle_options, %w[]

    use_ui @ui do
      @cmd.execute
    end

    assert_match %r|RUBYGEMS VERSION: (\d\.)+\d|, @ui.output
    assert_match %r|RUBY VERSION: \d\.\d\.\d \(.*\) \[.*\]|, @ui.output
    assert_match %r|INSTALLATION DIRECTORY: #{Regexp.escape @gemhome}|,
                 @ui.output
    assert_match %r|RUBYGEMS PREFIX: |, @ui.output
    assert_match %r|RUBY EXECUTABLE:.*#{RbConfig::CONFIG['ruby_install_name']}|,
                 @ui.output
    assert_match %r|SYSTEM CONFIGURATION DIRECTORY:|, @ui.output
    assert_match %r|EXECUTABLE DIRECTORY:|, @ui.output
    assert_match %r|RUBYGEMS PLATFORMS:|, @ui.output
    assert_match %r|- #{Gem::Platform.local}|, @ui.output
    assert_match %r|GEM PATHS:|, @ui.output
    assert_match %r|- #{Regexp.escape @gemhome}|, @ui.output
    assert_match %r|GEM CONFIGURATION:|, @ui.output
    assert_match %r|"gemcutter_key" => "\*\*\*\*"|, @ui.output
    assert_match %r|:verbose => |, @ui.output
    assert_match %r|REMOTE SOURCES:|, @ui.output

    assert_match %r|- SHELL PATH:|,     @ui.output
    assert_match %r|- /usr/local/bin$|, @ui.output
    assert_match %r|- /usr/bin$|,       @ui.output
    assert_match %r|- /bin$|,           @ui.output

    assert_empty @ui.error

  ensure
    Gem.sources.replace orig_sources
    ENV['PATH'] = orig_path
  end

  def test_execute_gemdir
    @cmd.send :handle_options, %w[gemdir]

    use_ui @ui do
      @cmd.execute
    end

    assert_equal "#{@gemhome}\n", @ui.output
    assert_equal '', @ui.error
  end

  def test_execute_gempath
    @cmd.send :handle_options, %w[gempath]

    use_ui @ui do
      @cmd.execute
    end

    assert_equal "#{@gemhome}\n", @ui.output
    assert_equal '', @ui.error
  end

  def test_execute_gempath_multiple
    Gem.clear_paths
    path = [@gemhome, "#{@gemhome}2"].join File::PATH_SEPARATOR
    ENV['GEM_PATH'] = path

    @cmd.send :handle_options, %w[gempath]

    use_ui @ui do
      @cmd.execute
    end

    assert_equal "#{Gem.path.join File::PATH_SEPARATOR}\n", @ui.output
    assert_equal '', @ui.error
  end

  def test_execute_packageversion
    @cmd.send :handle_options, %w[packageversion]

    use_ui @ui do
      @cmd.execute
    end

    assert_equal "#{Gem::RubyGemsPackageVersion}\n", @ui.output
    assert_equal '', @ui.error
  end

  def test_execute_remotesources
    orig_sources = Gem.sources.dup
    Gem.sources.replace %w[http://gems.example.com]

    @cmd.send :handle_options, %w[remotesources]

    use_ui @ui do
      @cmd.execute
    end

    assert_equal "http://gems.example.com\n", @ui.output
    assert_equal '', @ui.error

  ensure
    Gem.sources.replace orig_sources
  end

  def test_execute_unknown
    @cmd.send :handle_options, %w[unknown]

    assert_raises Gem::CommandLineError do
      use_ui @ui do
        @cmd.execute
      end
    end

    assert_equal '', @ui.output
    assert_equal '', @ui.error
  end

  def test_execute_version
    @cmd.send :handle_options, %w[version]

    use_ui @ui do
      @cmd.execute
    end

    assert_equal "#{Gem::VERSION}\n", @ui.output
    assert_equal '', @ui.error
  end

  def test_execute_platform
    @cmd.send :handle_options, %w[platform]

    use_ui @ui do
      @cmd.execute
    end

    assert_equal "#{Gem.platforms.join File::PATH_SEPARATOR}\n", @ui.output
    assert_equal '', @ui.error
  end
end