1# coding: UTF-8 2 3require 'rubygems/test_case' 4require 'rubygems/commands/setup_command' 5 6class TestGemCommandsSetupCommand < Gem::TestCase 7 8 def setup 9 super 10 11 @install_dir = File.join @tempdir, 'install' 12 @cmd = Gem::Commands::SetupCommand.new 13 @cmd.options[:prefix] = @install_dir 14 15 FileUtils.mkdir_p 'bin' 16 FileUtils.mkdir_p 'lib/rubygems/ssl_certs' 17 18 open 'bin/gem', 'w' do |io| io.puts '# gem' end 19 open 'lib/rubygems.rb', 'w' do |io| io.puts '# rubygems.rb' end 20 open 'lib/rubygems/test_case.rb', 'w' do |io| io.puts '# test_case.rb' end 21 open 'lib/rubygems/ssl_certs/foo.pem', 'w' do |io| io.puts 'PEM' end 22 end 23 24 def test_pem_files_in 25 assert_equal %w[rubygems/ssl_certs/foo.pem], 26 @cmd.pem_files_in('lib').sort 27 end 28 29 def test_rb_files_in 30 assert_equal %w[rubygems.rb rubygems/test_case.rb], 31 @cmd.rb_files_in('lib').sort 32 end 33 34 def test_install_lib 35 @cmd.extend FileUtils 36 37 Dir.mktmpdir 'lib' do |dir| 38 @cmd.install_lib dir 39 40 assert_path_exists File.join(dir, 'rubygems.rb') 41 assert_path_exists File.join(dir, 'rubygems/ssl_certs/foo.pem') 42 end 43 end 44 45 def test_remove_old_lib_files 46 lib = File.join @install_dir, 'lib' 47 lib_rubygems = File.join lib, 'rubygems' 48 lib_rubygems_defaults = File.join lib_rubygems, 'defaults' 49 50 securerandom_rb = File.join lib, 'securerandom.rb' 51 52 engine_defaults_rb = File.join lib_rubygems_defaults, 'jruby.rb' 53 os_defaults_rb = File.join lib_rubygems_defaults, 'operating_system.rb' 54 55 old_builder_rb = File.join lib_rubygems, 'builder.rb' 56 old_format_rb = File.join lib_rubygems, 'format.rb' 57 58 FileUtils.mkdir_p lib_rubygems_defaults 59 60 open securerandom_rb, 'w' do |io| io.puts '# securerandom.rb' end 61 62 open old_builder_rb, 'w' do |io| io.puts '# builder.rb' end 63 open old_format_rb, 'w' do |io| io.puts '# format.rb' end 64 65 open engine_defaults_rb, 'w' do |io| io.puts '# jruby.rb' end 66 open os_defaults_rb, 'w' do |io| io.puts '# operating_system.rb' end 67 68 @cmd.remove_old_lib_files lib 69 70 refute_path_exists old_builder_rb 71 refute_path_exists old_format_rb 72 73 assert_path_exists securerandom_rb 74 assert_path_exists engine_defaults_rb 75 assert_path_exists os_defaults_rb 76 end 77 78 def test_show_release_notes 79 @default_external = nil 80 capture_io do 81 @default_external, Encoding.default_external = 82 Encoding.default_external, Encoding::US_ASCII 83 end if Object.const_defined? :Encoding 84 85 @cmd.options[:previous_version] = Gem::Version.new '2.0.2' 86 87 open 'History.txt', 'w' do |io| 88 io.puts <<-History_txt 89# coding: UTF-8 90 91=== #{Gem::VERSION} / 2013-03-26 92 93* Bug fixes: 94 * Fixed release note display for LANG=C when installing rubygems 95 * �� is tasty 96 97=== 2.0.2 / 2013-03-06 98 99* Bug fixes: 100 * Other bugs fixed 101 102=== 2.0.1 / 2013-03-05 103 104* Bug fixes: 105 * Yet more bugs fixed 106 History_txt 107 end 108 109 use_ui @ui do 110 @cmd.show_release_notes 111 end 112 113 expected = <<-EXPECTED 114=== 2.0.2 / 2013-03-06 115 116* Bug fixes: 117 * Other bugs fixed 118 119 EXPECTED 120 121 assert_equal expected, @ui.output 122 ensure 123 capture_io do 124 Encoding.default_external = @default_external 125 end if @default_external 126 end 127 128end 129 130