2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/commands/environment_command'
5 class TestGemCommandsEnvironmentCommand < RubyGemTestCase
10 @cmd = Gem::Commands::EnvironmentCommand.new
14 orig_sources = Gem.sources.dup
15 Gem.sources.replace %w[http://gems.example.com]
17 @cmd.send :handle_options, %w[]
23 assert_match %r|RUBYGEMS VERSION: (\d\.)+\d|, @ui.output
24 assert_match %r|RUBY VERSION: \d\.\d\.\d \(.*\) \[.*\]|, @ui.output
25 assert_match %r|INSTALLATION DIRECTORY: #{Regexp.escape @gemhome}|,
27 assert_match %r|RUBYGEMS PREFIX: |, @ui.output
28 assert_match %r|RUBY EXECUTABLE:.*#{Gem::ConfigMap[:RUBY_INSTALL_NAME]}|,
30 assert_match %r|RUBYGEMS PLATFORMS:|, @ui.output
31 assert_match %r|- #{Gem::Platform.local}|, @ui.output
32 assert_match %r|GEM PATHS:|, @ui.output
33 assert_match %r|- #{Regexp.escape @gemhome}|, @ui.output
34 assert_match %r|GEM CONFIGURATION:|, @ui.output
35 assert_match %r|:verbose => |, @ui.output
36 assert_match %r|REMOTE SOURCES:|, @ui.output
37 assert_equal '', @ui.error
40 Gem.sources.replace orig_sources
43 def test_execute_gemdir
44 @cmd.send :handle_options, %w[gemdir]
50 assert_equal "#{@gemhome}\n", @ui.output
51 assert_equal '', @ui.error
54 def test_execute_gempath
55 @cmd.send :handle_options, %w[gempath]
61 assert_equal "#{@gemhome}\n", @ui.output
62 assert_equal '', @ui.error
65 def test_execute_gempath_multiple
67 path = [@gemhome, "#{@gemhome}2"].join File::PATH_SEPARATOR
68 ENV['GEM_PATH'] = path
70 @cmd.send :handle_options, %w[gempath]
76 assert_equal "#{Gem.path.join File::PATH_SEPARATOR}\n", @ui.output
77 assert_equal '', @ui.error
80 def test_execute_packageversion
81 @cmd.send :handle_options, %w[packageversion]
87 assert_equal "#{Gem::RubyGemsPackageVersion}\n", @ui.output
88 assert_equal '', @ui.error
91 def test_execute_remotesources
92 orig_sources = Gem.sources.dup
93 Gem.sources.replace %w[http://gems.example.com]
95 @cmd.send :handle_options, %w[remotesources]
101 assert_equal "http://gems.example.com\n", @ui.output
102 assert_equal '', @ui.error
105 Gem.sources.replace orig_sources
108 def test_execute_unknown
109 @cmd.send :handle_options, %w[unknown]
111 assert_raise Gem::CommandLineError do
117 assert_equal '', @ui.output
118 assert_equal '', @ui.error
121 def test_execute_version
122 @cmd.send :handle_options, %w[version]
128 assert_equal "#{Gem::RubyGemsVersion}\n", @ui.output
129 assert_equal '', @ui.error