3 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
5 # See LICENSE.txt for permissions.
9 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
10 require 'rubygems/config_file'
12 class TestGemConfigFile < RubyGemTestCase
17 @temp_conf = File.join @tempdir, '.gemrc'
19 @cfg_args = %W[--config-file #{@temp_conf}]
24 assert_equal @temp_conf, @cfg.config_file_name
26 assert_equal false, @cfg.backtrace
27 assert_equal true, @cfg.update_sources
28 assert_equal false, @cfg.benchmark
29 assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold
30 assert_equal true, @cfg.verbose
31 assert_equal %w[http://gems.example.com], Gem.sources
33 File.open @temp_conf, 'w' do |fp|
34 fp.puts ":backtrace: true"
35 fp.puts ":update_sources: false"
36 fp.puts ":benchmark: true"
37 fp.puts ":bulk_threshold: 10"
38 fp.puts ":verbose: false"
40 fp.puts " - http://more-gems.example.com"
41 fp.puts "install: --wrappers"
46 assert_equal true, @cfg.backtrace
47 assert_equal true, @cfg.benchmark
48 assert_equal 10, @cfg.bulk_threshold
49 assert_equal false, @cfg.verbose
50 assert_equal false, @cfg.update_sources
51 assert_equal %w[http://more-gems.example.com], Gem.sources
52 assert_equal '--wrappers', @cfg[:install]
55 def test_initialize_handle_arguments_config_file
56 util_config_file %W[--config-file #{@temp_conf}]
58 assert_equal @temp_conf, @cfg.config_file_name
61 def test_initialize_handle_arguments_config_file_equals
62 util_config_file %W[--config-file=#{@temp_conf}]
64 assert_equal @temp_conf, @cfg.config_file_name
67 def test_handle_arguments
68 args = %w[--backtrace --bunch --of --args here]
70 @cfg.handle_arguments args
72 assert_equal %w[--bunch --of --args here], @cfg.args
75 def test_handle_arguments_backtrace
76 assert_equal false, @cfg.backtrace
78 args = %w[--backtrace]
80 @cfg.handle_arguments args
82 assert_equal true, @cfg.backtrace
85 def test_handle_arguments_benchmark
86 assert_equal false, @cfg.benchmark
88 args = %w[--benchmark]
90 @cfg.handle_arguments args
92 assert_equal true, @cfg.benchmark
95 def test_handle_arguments_debug
96 old_dollar_DEBUG = $DEBUG
97 assert_equal false, $DEBUG
101 @cfg.handle_arguments args
103 assert_equal true, $DEBUG
105 $DEBUG = old_dollar_DEBUG
108 def test_handle_arguments_override
109 File.open @temp_conf, 'w' do |fp|
110 fp.puts ":benchmark: false"
113 util_config_file %W[--benchmark --config-file=#{@temp_conf}]
115 assert_equal true, @cfg.benchmark
118 def test_handle_arguments_traceback
119 assert_equal false, @cfg.backtrace
121 args = %w[--traceback]
123 @cfg.handle_arguments args
125 assert_equal true, @cfg.backtrace
128 def test_really_verbose
129 assert_equal false, @cfg.really_verbose
133 assert_equal false, @cfg.really_verbose
137 assert_equal true, @cfg.really_verbose
141 @cfg.backtrace = true
142 @cfg.benchmark = true
143 @cfg.update_sources = false
144 @cfg.bulk_threshold = 10
146 Gem.sources.replace %w[http://more-gems.example.com]
147 @cfg[:install] = '--wrappers'
153 # These should not be written out to the config file.
154 assert_equal false, @cfg.backtrace, 'backtrace'
155 assert_equal false, @cfg.benchmark, 'benchmark'
156 assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold,
158 assert_equal true, @cfg.update_sources, 'update_sources'
159 assert_equal true, @cfg.verbose, 'verbose'
161 assert_equal '--wrappers', @cfg[:install], 'install'
163 # this should be written out to the config file.
164 assert_equal %w[http://more-gems.example.com], Gem.sources
167 def test_write_from_hash
168 File.open @temp_conf, 'w' do |fp|
169 fp.puts ":backtrace: true"
170 fp.puts ":benchmark: true"
171 fp.puts ":bulk_threshold: 10"
172 fp.puts ":update_sources: false"
173 fp.puts ":verbose: false"
175 fp.puts " - http://more-gems.example.com"
176 fp.puts "install: --wrappers"
181 @cfg.backtrace = :junk
182 @cfg.benchmark = :junk
183 @cfg.update_sources = :junk
184 @cfg.bulk_threshold = 20
186 Gem.sources.replace %w[http://even-more-gems.example.com]
187 @cfg[:install] = '--wrappers --no-rdoc'
193 # These should not be written out to the config file
194 assert_equal true, @cfg.backtrace, 'backtrace'
195 assert_equal true, @cfg.benchmark, 'benchmark'
196 assert_equal 10, @cfg.bulk_threshold, 'bulk_threshold'
197 assert_equal false, @cfg.update_sources, 'update_sources'
198 assert_equal false, @cfg.verbose, 'verbose'
200 assert_equal '--wrappers --no-rdoc', @cfg[:install], 'install'
202 assert_equal %w[http://even-more-gems.example.com], Gem.sources
205 def util_config_file(args = @cfg_args)
206 @cfg = Gem::ConfigFile.new args