2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/commands/environment_command'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsEnvironmentCommand < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::EnvironmentCommand.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute
|
|
|
|
orig_sources = Gem.sources.dup
|
2013-07-09 19:21:36 -04:00
|
|
|
orig_path, ENV['PATH'] = ENV['PATH'], '/usr/local/bin:/usr/bin:/bin'
|
2007-11-10 02:48:56 -05:00
|
|
|
Gem.sources.replace %w[http://gems.example.com]
|
2010-04-22 04:24:42 -04:00
|
|
|
Gem.configuration['gemcutter_key'] = 'blah'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
@cmd.send :handle_options, %w[]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2008-04-11 16:57:02 -04:00
|
|
|
assert_match %r|RUBYGEMS VERSION: (\d\.)+\d|, @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_match %r|RUBY VERSION: \d\.\d\.\d \(.*\) \[.*\]|, @ui.output
|
2007-11-20 00:56:43 -05:00
|
|
|
assert_match %r|INSTALLATION DIRECTORY: #{Regexp.escape @gemhome}|,
|
|
|
|
@ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_match %r|RUBYGEMS PREFIX: |, @ui.output
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_match %r|RUBY EXECUTABLE:.*#{Gem::ConfigMap[:ruby_install_name]}|,
|
2008-02-10 03:00:19 -05:00
|
|
|
@ui.output
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_match %r|EXECUTABLE DIRECTORY:|, @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_match %r|RUBYGEMS PLATFORMS:|, @ui.output
|
|
|
|
assert_match %r|- #{Gem::Platform.local}|, @ui.output
|
|
|
|
assert_match %r|GEM PATHS:|, @ui.output
|
2007-11-20 00:56:43 -05:00
|
|
|
assert_match %r|- #{Regexp.escape @gemhome}|, @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_match %r|GEM CONFIGURATION:|, @ui.output
|
2010-04-22 04:24:42 -04:00
|
|
|
assert_match %r|"gemcutter_key" => "\*\*\*\*"|, @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_match %r|:verbose => |, @ui.output
|
|
|
|
assert_match %r|REMOTE SOURCES:|, @ui.output
|
2013-07-09 19:21:36 -04:00
|
|
|
|
|
|
|
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
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
ensure
|
|
|
|
Gem.sources.replace orig_sources
|
2013-07-09 19:21:36 -04:00
|
|
|
ENV['PATH'] = orig_path
|
2007-11-10 02:48:56 -05:00
|
|
|
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
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
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
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
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]
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
assert_raises Gem::CommandLineError do
|
2007-11-10 02:48:56 -05:00
|
|
|
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
|
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
assert_equal "#{Gem::VERSION}\n", @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
def test_execute_platform
|
|
|
|
@cmd.send :handle_options, %w[platform]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "#{Gem.platforms.join File::PATH_SEPARATOR}\n", @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
end
|