diff --git a/lib/rubygems.rb b/lib/rubygems.rb index d31c216142..d0933e1b6c 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -271,9 +271,9 @@ module Gem specs = dep.matching_specs(true) - specs = specs.find_all { |spec| + specs = specs.find_all do |spec| spec.executables.include? exec_name - } if exec_name + end if exec_name unless spec = specs.first msg = "can't find gem #{dep} with executable #{exec_name}" @@ -521,9 +521,9 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} def self.find_files_from_load_path(glob) # :nodoc: glob_with_suffixes = "#{glob}#{Gem.suffix_pattern}" - $LOAD_PATH.map { |load_path| + $LOAD_PATH.map do |load_path| Gem::Util.glob_files_in_dir(glob_with_suffixes, load_path) - }.flatten.select { |file| File.file? file.untaint } + end.flatten.select { |file| File.file? file.untaint } end ## @@ -593,8 +593,10 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end class << self + extend Gem::Deprecate deprecate :gunzip, "Gem::Util.gunzip", 2018, 12 + end ## @@ -605,8 +607,10 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end class << self + extend Gem::Deprecate deprecate :gzip, "Gem::Util.gzip", 2018, 12 + end ## @@ -617,8 +621,10 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end class << self + extend Gem::Deprecate deprecate :inflate, "Gem::Util.inflate", 2018, 12 + end ## @@ -1015,11 +1021,11 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} def self.suffixes @suffixes ||= ['', '.rb', - *%w(DLEXT DLEXT2).map { |key| + *%w(DLEXT DLEXT2).map do |key| val = RbConfig::CONFIG[key] next unless val and not val.empty? ".#{val}" - } + end ].compact.uniq end @@ -1211,6 +1217,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end class << self + ## # TODO remove with RubyGems 4.0 @@ -1218,6 +1225,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} extend Gem::Deprecate deprecate :detect_gemdeps, "Gem.use_gemdeps", 2018, 12 + end # FIX: Almost everywhere else we use the `def self.` way of defining class @@ -1337,6 +1345,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # work attr_reader :pre_uninstall_hooks + end ## diff --git a/lib/rubygems/available_set.rb b/lib/rubygems/available_set.rb index 8334a73ecb..2e9d9496f6 100644 --- a/lib/rubygems/available_set.rb +++ b/lib/rubygems/available_set.rb @@ -162,4 +162,5 @@ class Gem::AvailableSet def inject_into_list(dep_list) @set.each { |t| dep_list.add t.spec } end + end diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index d1878021ba..edb38cb1c2 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -329,4 +329,5 @@ class Gem::BasicSpecification false end end + end diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index 5b8868b0cd..a509b783dd 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -122,6 +122,7 @@ class Gem::Command @defaults = defaults @options = defaults.dup @option_groups = Hash.new { |h,k| h[k] = [] } + @deprecated_options = { command => {} } @parser = nil @when_invoked = nil end @@ -365,13 +366,34 @@ class Gem::Command end end + def deprecate_option(short_name: nil, long_name: nil, version: nil) + @deprecated_options[command].merge!({ short_name => { "rg_version_to_expire" => version } }) if short_name + @deprecated_options[command].merge!({ long_name => { "rg_version_to_expire" => version } }) if long_name + end + + def check_deprecated_options(options) + options.each do |option| + if option_is_deprecated?(option) + version_to_expire = @deprecated_options[command][option]["rg_version_to_expire"] + + deprecate_option_msg = if version_to_expire + "The \"#{option}\" option has been deprecated and will be removed in Rubygems #{version_to_expire}, its use is discouraged." + else + "The \"#{option}\" option has been deprecated and will be removed in future versions of Rubygems, its use is discouraged." + end + + alert_warning(deprecate_option_msg) + end + end + end + ## # Merge a set of command options with the set of default options (without # modifying the default option hash). def merge_options(new_options) @options = @defaults.clone - new_options.each do |k,v| @options[k] = v end + new_options.each { |k,v| @options[k] = v } end ## @@ -392,6 +414,7 @@ class Gem::Command def handle_options(args) args = add_extra_args(args) + check_deprecated_options(args) @options = Marshal.load Marshal.dump @defaults # deep copy parser.parse!(args) @options[:args] = args @@ -420,6 +443,10 @@ class Gem::Command private + def option_is_deprecated?(option) + @deprecated_options[command].has_key?(option) + end + def add_parser_description # :nodoc: return unless description diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb index 761b80ee94..9d318e6e8b 100644 --- a/lib/rubygems/commands/build_command.rb +++ b/lib/rubygems/commands/build_command.rb @@ -96,4 +96,5 @@ Gems can be saved to a specified filename with the output option: terminate_interaction 1 end end + end diff --git a/lib/rubygems/commands/cleanup_command.rb b/lib/rubygems/commands/cleanup_command.rb index aeb4d82fae..fedaec8448 100644 --- a/lib/rubygems/commands/cleanup_command.rb +++ b/lib/rubygems/commands/cleanup_command.rb @@ -99,7 +99,7 @@ If no gems are named all gems in GEM_HOME are cleaned. @full = Gem::DependencyList.from_specs deplist = Gem::DependencyList.new - @gems_to_cleanup.each do |spec| deplist.add spec end + @gems_to_cleanup.each { |spec| deplist.add spec } deps = deplist.strongly_connected_components.flatten @@ -121,19 +121,19 @@ If no gems are named all gems in GEM_HOME are cleaned. end def get_gems_to_cleanup - gems_to_cleanup = @candidate_gems.select { |spec| + gems_to_cleanup = @candidate_gems.select do |spec| @primary_gems[spec.name].version != spec.version - } + end - default_gems, gems_to_cleanup = gems_to_cleanup.partition { |spec| + default_gems, gems_to_cleanup = gems_to_cleanup.partition do |spec| spec.default_gem? - } + end uninstall_from = options[:user_install] ? Gem.user_dir : @original_home - gems_to_cleanup = gems_to_cleanup.select { |spec| + gems_to_cleanup = gems_to_cleanup.select do |spec| spec.base_dir == uninstall_from - } + end @default_gems += default_gems @default_gems.uniq! diff --git a/lib/rubygems/commands/contents_command.rb b/lib/rubygems/commands/contents_command.rb index 6da89a136e..26d6828fe6 100644 --- a/lib/rubygems/commands/contents_command.rb +++ b/lib/rubygems/commands/contents_command.rb @@ -14,7 +14,7 @@ class Gem::Commands::ContentsCommand < Gem::Command add_version_option - add_option( '--all', + add_option('--all', "Contents for all gems") do |all, options| options[:all] = all end @@ -29,12 +29,12 @@ class Gem::Commands::ContentsCommand < Gem::Command options[:lib_only] = lib_only end - add_option( '--[no-]prefix', + add_option('--[no-]prefix', "Don't include installed path prefix") do |prefix, options| options[:prefix] = prefix end - add_option( '--[no-]show-install-dir', + add_option('--[no-]show-install-dir', 'Show only the gem install dir') do |show, options| options[:show_install_dir] = show end diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb index 9e88b04ea5..8e198ac93a 100644 --- a/lib/rubygems/commands/dependency_command.rb +++ b/lib/rubygems/commands/dependency_command.rb @@ -80,9 +80,9 @@ use with other commands. end def gem_dependency(pattern, version, prerelease) # :nodoc: - dependency = Gem::Deprecate.skip_during { + dependency = Gem::Deprecate.skip_during do Gem::Dependency.new pattern, version - } + end dependency.prerelease = prerelease @@ -215,4 +215,5 @@ use with other commands. /\A#{Regexp.union(*args)}/ end end + end diff --git a/lib/rubygems/commands/info_command.rb b/lib/rubygems/commands/info_command.rb index 8d9611a957..6a737b178b 100644 --- a/lib/rubygems/commands/info_command.rb +++ b/lib/rubygems/commands/info_command.rb @@ -4,6 +4,7 @@ require 'rubygems/command' require 'rubygems/commands/query_command' class Gem::Commands::InfoCommand < Gem::Commands::QueryCommand + def initialize super "info", "Show information for the given gem" @@ -30,4 +31,5 @@ class Gem::Commands::InfoCommand < Gem::Commands::QueryCommand def defaults_str "--local" end + end diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb index 776b58651f..82631b1ffd 100644 --- a/lib/rubygems/commands/install_command.rb +++ b/lib/rubygems/commands/install_command.rb @@ -201,10 +201,13 @@ You can use `i` command instead of `install`. request_set = inst.resolve_dependencies name, req if options[:explain] - puts "Gems to install:" + say "Gems to install:" request_set.sorted_requests.each do |s| - puts " #{s.full_name}" + # shows platform specific gems if used + say (plat = s.spec.platform) == Gem::Platform::RUBY ? + " #{s.full_name}" : + " #{s.full_name}-#{plat}" end return diff --git a/lib/rubygems/commands/lock_command.rb b/lib/rubygems/commands/lock_command.rb index 7f02e9feda..ebb402a8bd 100644 --- a/lib/rubygems/commands/lock_command.rb +++ b/lib/rubygems/commands/lock_command.rb @@ -100,9 +100,9 @@ lock it down to the exact version. end def spec_path(gem_full_name) - gemspecs = Gem.path.map { |path| + gemspecs = Gem.path.map do |path| File.join path, "specifications", "#{gem_full_name}.gemspec" - } + end gemspecs.find { |path| File.exist? path } end diff --git a/lib/rubygems/commands/mirror_command.rb b/lib/rubygems/commands/mirror_command.rb index 801c9c8927..4e2a41fa33 100644 --- a/lib/rubygems/commands/mirror_command.rb +++ b/lib/rubygems/commands/mirror_command.rb @@ -3,6 +3,7 @@ require 'rubygems/command' unless defined? Gem::Commands::MirrorCommand class Gem::Commands::MirrorCommand < Gem::Command + def initialize super('mirror', 'Mirror all gem files (requires rubygems-mirror)') begin diff --git a/lib/rubygems/commands/open_command.rb b/lib/rubygems/commands/open_command.rb index 2794fe05e6..8eaeb64ba9 100644 --- a/lib/rubygems/commands/open_command.rb +++ b/lib/rubygems/commands/open_command.rb @@ -17,7 +17,7 @@ class Gem::Commands::OpenCommand < Gem::Command end add_option('-v', '--version VERSION', String, "Opens specific gem version") do |version| - options[:version] = version + options[:version] = version end end @@ -84,4 +84,5 @@ class Gem::Commands::OpenCommand < Gem::Command say "Unable to find gem '#{name}'" end + end diff --git a/lib/rubygems/commands/outdated_command.rb b/lib/rubygems/commands/outdated_command.rb index 70f6c02801..035eaffcbc 100644 --- a/lib/rubygems/commands/outdated_command.rb +++ b/lib/rubygems/commands/outdated_command.rb @@ -30,4 +30,5 @@ update the gems with the update or install commands. say "#{spec.name} (#{spec.version} < #{remote_version})" end end + end diff --git a/lib/rubygems/commands/owner_command.rb b/lib/rubygems/commands/owner_command.rb index 799f31704a..9fcabaa9f8 100644 --- a/lib/rubygems/commands/owner_command.rb +++ b/lib/rubygems/commands/owner_command.rb @@ -4,6 +4,7 @@ require 'rubygems/local_remote_options' require 'rubygems/gemcutter_utilities' class Gem::Commands::OwnerCommand < Gem::Command + include Gem::LocalRemoteOptions include Gem::GemcutterUtilities @@ -60,6 +61,8 @@ permission to. end def show_owners(name) + Gem.load_yaml + response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request| request.add_field "Authorization", api_key end diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index 41decde856..1d0eb61700 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -183,4 +183,5 @@ extensions will be restored. say "Restored #{spec.full_name}" end end + end diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb index 55ee3ae73f..7fd1119ff9 100644 --- a/lib/rubygems/commands/push_command.rb +++ b/lib/rubygems/commands/push_command.rb @@ -5,6 +5,7 @@ require 'rubygems/gemcutter_utilities' require 'rubygems/package' class Gem::Commands::PushCommand < Gem::Command + include Gem::LocalRemoteOptions include Gem::GemcutterUtilities @@ -145,4 +146,5 @@ You can upgrade or downgrade to the latest release version with: gem_metadata["allowed_push_host"] ] end + end diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb index d947d588ef..5a42d45249 100644 --- a/lib/rubygems/commands/query_command.rb +++ b/lib/rubygems/commands/query_command.rb @@ -39,7 +39,7 @@ class Gem::Commands::QueryCommand < Gem::Command options[:details] = value end - add_option( '--[no-]versions', + add_option('--[no-]versions', 'Display only gem names') do |value, options| options[:versions] = value options[:details] = false unless value @@ -56,7 +56,7 @@ class Gem::Commands::QueryCommand < Gem::Command options[:exact] = value end - add_option( '--[no-]prerelease', + add_option('--[no-]prerelease', 'Display prerelease versions') do |value, options| options[:prerelease] = value end @@ -141,9 +141,9 @@ is too hard to use. display_header 'LOCAL' - specs = Gem::Specification.find_all { |s| + specs = Gem::Specification.find_all do |s| s.name =~ name and req =~ s.version - } + end spec_tuples = specs.map do |spec| [spec.name_tuple, spec] diff --git a/lib/rubygems/commands/rdoc_command.rb b/lib/rubygems/commands/rdoc_command.rb index 5f8b72eb7a..ff9e1ffcfa 100644 --- a/lib/rubygems/commands/rdoc_command.rb +++ b/lib/rubygems/commands/rdoc_command.rb @@ -5,6 +5,7 @@ require 'rubygems/rdoc' require 'fileutils' class Gem::Commands::RdocCommand < Gem::Command + include Gem::VersionOption def initialize diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index c9c00b5be4..975eca593d 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -6,6 +6,7 @@ require 'rubygems/command' # RubyGems checkout or tarball. class Gem::Commands::SetupCommand < Gem::Command + HISTORY_HEADER = /^===\s*[\d.a-zA-Z]+\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/.freeze VERSION_MATCHER = /^===\s*([\d.a-zA-Z]+)\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/.freeze diff --git a/lib/rubygems/commands/signin_command.rb b/lib/rubygems/commands/signin_command.rb index 0d527fc339..7c4b5ceb69 100644 --- a/lib/rubygems/commands/signin_command.rb +++ b/lib/rubygems/commands/signin_command.rb @@ -3,6 +3,7 @@ require 'rubygems/command' require 'rubygems/gemcutter_utilities' class Gem::Commands::SigninCommand < Gem::Command + include Gem::GemcutterUtilities def initialize diff --git a/lib/rubygems/commands/specification_command.rb b/lib/rubygems/commands/specification_command.rb index 56b9371686..7326822ad7 100644 --- a/lib/rubygems/commands/specification_command.rb +++ b/lib/rubygems/commands/specification_command.rb @@ -143,4 +143,5 @@ Specific fields in the specification can be extracted in YAML format: say "\n" end end + end diff --git a/lib/rubygems/commands/stale_command.rb b/lib/rubygems/commands/stale_command.rb index 0524ee1e2b..89bafeae98 100644 --- a/lib/rubygems/commands/stale_command.rb +++ b/lib/rubygems/commands/stale_command.rb @@ -2,6 +2,7 @@ require 'rubygems/command' class Gem::Commands::StaleCommand < Gem::Command + def initialize super('stale', 'List gems along with access times') end @@ -36,4 +37,5 @@ longer using. say "#{name} at #{atime.strftime '%c'}" end end + end diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index 9de0ea722b..698ff4b555 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -185,4 +185,5 @@ that is a dependency of an existing gem. You can use the def uninstall(gem_name) Gem::Uninstaller.new(gem_name, options).uninstall end + end diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 9ab3b80e96..c44dcf0bd8 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -194,7 +194,7 @@ command to remove old versions. } gems_to_update = which_to_update hig, options[:args], :system - _, up_ver = gems_to_update.first + _, up_ver = gems_to_update.first target = if update_latest up_ver diff --git a/lib/rubygems/commands/which_command.rb b/lib/rubygems/commands/which_command.rb index 5c51ed72dd..334bde2622 100644 --- a/lib/rubygems/commands/which_command.rb +++ b/lib/rubygems/commands/which_command.rb @@ -2,6 +2,7 @@ require 'rubygems/command' class Gem::Commands::WhichCommand < Gem::Command + def initialize super 'which', 'Find the location of a library file you can require', :search_gems_first => false, :show_all => false diff --git a/lib/rubygems/commands/yank_command.rb b/lib/rubygems/commands/yank_command.rb index d13b674b48..be675fa460 100644 --- a/lib/rubygems/commands/yank_command.rb +++ b/lib/rubygems/commands/yank_command.rb @@ -5,6 +5,7 @@ require 'rubygems/version_option' require 'rubygems/gemcutter_utilities' class Gem::Commands::YankCommand < Gem::Command + include Gem::LocalRemoteOptions include Gem::VersionOption include Gem::GemcutterUtilities diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index e02655fc51..a5c552dc9f 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -484,4 +484,5 @@ if you believe they were disclosed to a third party. attr_reader :hash protected :hash + end diff --git a/lib/rubygems/core_ext/kernel_gem.rb b/lib/rubygems/core_ext/kernel_gem.rb index b0dd69bfcc..39b00387ea 100644 --- a/lib/rubygems/core_ext/kernel_gem.rb +++ b/lib/rubygems/core_ext/kernel_gem.rb @@ -64,9 +64,9 @@ module Kernel spec = dep.to_spec - Gem::LOADED_SPECS_MUTEX.synchronize { + Gem::LOADED_SPECS_MUTEX.synchronize do spec.activate - } if spec + end if spec end private :gem diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 50f46b32a2..7aa0480b80 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -2,8 +2,8 @@ module Gem DEFAULT_HOST = "https://rubygems.org".freeze - @post_install_hooks ||= [] - @done_installing_hooks ||= [] + @post_install_hooks ||= [] + @done_installing_hooks ||= [] @post_uninstall_hooks ||= [] @pre_uninstall_hooks ||= [] @pre_install_hooks ||= [] diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb index 33ba1968d1..3c91392cdd 100644 --- a/lib/rubygems/dependency.rb +++ b/lib/rubygems/dependency.rb @@ -277,16 +277,16 @@ class Gem::Dependency def matching_specs(platform_only = false) env_req = Gem.env_requirement(name) - matches = Gem::Specification.stubs_for(name).find_all { |spec| + matches = Gem::Specification.stubs_for(name).find_all do |spec| requirement.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version) - }.map(&:to_spec) + end.map(&:to_spec) Gem::BundlerVersionFinder.filter!(matches) if name == "bundler".freeze if platform_only - matches.reject! { |spec| + matches.reject! do |spec| spec.nil? || !Gem::Platform.match(spec.platform) - } + end end matches @@ -333,4 +333,5 @@ class Gem::Dependency matches.first end + end diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb index 346208603c..7f4f914591 100644 --- a/lib/rubygems/dependency_installer.rb +++ b/lib/rubygems/dependency_installer.rb @@ -29,7 +29,7 @@ class Gem::DependencyInstaller :wrappers => true, :build_args => nil, :build_docs_in_background => false, - :install_as_default => false + :install_as_default => false }.freeze ## @@ -336,15 +336,15 @@ class Gem::DependencyInstaller # REFACTOR maybe abstract away using Gem::Specification.include? so # that this isn't dependent only on the currently installed gems - dependency_list.specs.reject! { |spec| + dependency_list.specs.reject! do |spec| not keep_names.include?(spec.full_name) and Gem::Specification.include?(spec) - } + end unless dependency_list.ok? or @ignore_dependencies or @force - reason = dependency_list.why_not_ok?.map { |k,v| + reason = dependency_list.why_not_ok?.map do |k,v| "#{k} requires #{v.join(", ")}" - }.join("; ") + end.join("; ") raise Gem::DependencyError, "Unable to resolve dependencies: #{reason}" end diff --git a/lib/rubygems/dependency_list.rb b/lib/rubygems/dependency_list.rb index ee2e4c7343..eec2223077 100644 --- a/lib/rubygems/dependency_list.rb +++ b/lib/rubygems/dependency_list.rb @@ -17,6 +17,7 @@ require 'rubygems/deprecate' # this class necessary anymore? Especially #ok?, #why_not_ok? class Gem::DependencyList + attr_reader :specs include Enumerable @@ -118,10 +119,10 @@ class Gem::DependencyList unsatisfied = Hash.new { |h,k| h[k] = [] } each do |spec| spec.runtime_dependencies.each do |dep| - inst = Gem::Specification.any? { |installed_spec| + inst = Gem::Specification.any? do |installed_spec| dep.name == installed_spec.name and dep.requirement.satisfied_by? installed_spec.version - } + end unless inst or @specs.find { |s| s.satisfies_requirement? dep } unsatisfied[spec.name] << dep @@ -145,10 +146,10 @@ class Gem::DependencyList # If the state is inconsistent, at least don't crash return true unless gem_to_remove - siblings = @specs.find_all { |s| + siblings = @specs.find_all do |s| s.name == gem_to_remove.name && s.full_name != gem_to_remove.full_name - } + end deps = [] @@ -160,11 +161,11 @@ class Gem::DependencyList end end - deps.all? { |dep| - siblings.any? { |s| + deps.all? do |dep| + siblings.any? do |s| s.satisfies_requirement? dep - } - } + end + end end ## @@ -173,10 +174,10 @@ class Gem::DependencyList # dependencies). def remove_specs_unsatisfied_by(dependencies) - specs.reject! { |spec| + specs.reject! do |spec| dep = dependencies[spec.name] dep and not dep.requirement.satisfied_by? spec.version - } + end end ## diff --git a/lib/rubygems/deprecate.rb b/lib/rubygems/deprecate.rb index 815f42ae8c..b5591e6ac1 100644 --- a/lib/rubygems/deprecate.rb +++ b/lib/rubygems/deprecate.rb @@ -48,7 +48,7 @@ module Gem::Deprecate # year/month that it is planned to go away. def deprecate(name, repl, year, month) - class_eval { + class_eval do old = "_deprecated_#{name}" alias_method old, name define_method name do |*args, &block| @@ -62,7 +62,7 @@ module Gem::Deprecate warn "#{msg.join}." unless Gem::Deprecate.skip send old, *args, &block end - } + end end module_function :deprecate, :skip_during diff --git a/lib/rubygems/errors.rb b/lib/rubygems/errors.rb index 6773bbcd26..2cd18e2e20 100644 --- a/lib/rubygems/errors.rb +++ b/lib/rubygems/errors.rb @@ -13,11 +13,13 @@ module Gem # already activated gems or that RubyGems is otherwise unable to activate. class LoadError < ::LoadError + # Name of gem attr_accessor :name # Version requirement of gem attr_accessor :requirement + end ## @@ -25,6 +27,7 @@ module Gem # system. Instead of rescuing from this class, make sure to rescue from the # superclass Gem::LoadError to catch all types of load errors. class MissingSpecError < Gem::LoadError + def initialize(name, requirement) @name = name @requirement = requirement @@ -41,6 +44,7 @@ module Gem total = Gem::Specification.stubs.size "Could not find '#{name}' (#{requirement}) among #{total} total gem(s)\n" end + end ## @@ -48,6 +52,7 @@ module Gem # not the requested version. Instead of rescuing from this class, make sure to # rescue from the superclass Gem::LoadError to catch all types of load errors. class MissingSpecVersionError < MissingSpecError + attr_reader :specs def initialize(name, requirement, specs) @@ -64,6 +69,7 @@ module Gem names = specs.map(&:full_name) "Could not find '#{name}' (#{requirement}) - did find: [#{names.join ','}]\n" end + end # Raised when there are conflicting gem specs loaded @@ -86,14 +92,15 @@ module Gem @conflicts = conflicts @name = target.name - reason = conflicts.map { |act, dependencies| + reason = conflicts.map do |act, dependencies| "#{act.full_name} conflicts with #{dependencies.join(", ")}" - }.join ", " + end.join ", " # TODO: improve message by saying who activated `con` super("Unable to activate #{target.full_name}, because #{reason}") end + end class ErrorReason; end @@ -143,6 +150,7 @@ module Gem @platforms.size == 1 ? '' : 's', @platforms.join(' ,')] end + end ## @@ -181,5 +189,6 @@ module Gem # The "exception" alias allows you to call raise on a SourceFetchProblem. alias exception error + end end diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb index a387cd390f..28ae3aa24e 100644 --- a/lib/rubygems/exceptions.rb +++ b/lib/rubygems/exceptions.rb @@ -19,6 +19,7 @@ class Gem::Exception < RuntimeError extend Gem::Deprecate deprecate :source_exception, :none, 2018, 12 + end class Gem::CommandLineError < Gem::Exception; end @@ -53,14 +54,18 @@ end # Raised when attempting to uninstall a gem that isn't in GEM_HOME. class Gem::GemNotInHomeException < Gem::Exception + attr_accessor :spec + end ### # Raised when removing a gem with the uninstall command fails class Gem::UninstallError < Gem::Exception + attr_accessor :spec + end class Gem::DocumentError < Gem::Exception; end @@ -88,7 +93,9 @@ end ## # Used to raise parsing and loading errors class Gem::FormatException < Gem::Exception + attr_accessor :file_path + end class Gem::GemNotFoundException < Gem::Exception; end @@ -166,10 +173,12 @@ end class Gem::InstallError < Gem::Exception; end class Gem::RuntimeRequirementNotMetError < Gem::InstallError + attr_accessor :suggestion def message [suggestion, super].compact.join("\n\t") end + end ## diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb index f578e7feee..8276dd769a 100644 --- a/lib/rubygems/ext/builder.rb +++ b/lib/rubygems/ext/builder.rb @@ -240,7 +240,9 @@ EOF FileUtils.mkdir_p @spec.extension_dir - File.open destination, 'wb' do |io| io.puts output end + File.open destination, 'wb' do |io| + io.puts output + end destination end diff --git a/lib/rubygems/ext/cmake_builder.rb b/lib/rubygems/ext/cmake_builder.rb index ab226733d9..829b88d1bb 100644 --- a/lib/rubygems/ext/cmake_builder.rb +++ b/lib/rubygems/ext/cmake_builder.rb @@ -2,6 +2,7 @@ require 'rubygems/command' class Gem::Ext::CmakeBuilder < Gem::Ext::Builder + def self.build(extension, dest_path, results, args=[], lib_dir=nil) unless File.exist?('Makefile') cmd = "cmake . -DCMAKE_INSTALL_PREFIX=#{dest_path}" @@ -14,4 +15,5 @@ class Gem::Ext::CmakeBuilder < Gem::Ext::Builder results end + end diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index 5a2b3eb533..169da438ba 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -10,6 +10,7 @@ require 'tempfile' require 'shellwords' class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder + FileEntry = FileUtils::Entry_ # :nodoc: def self.build(extension, dest_path, results, args=[], lib_dir=nil) @@ -88,7 +89,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder private def self.get_relative_path(path) - path[0..Dir.pwd.length-1] = '.' if path.start_with?(Dir.pwd) + path[0..Dir.pwd.length - 1] = '.' if path.start_with?(Dir.pwd) path end diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index c6ccc209c8..877205b619 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -63,7 +63,7 @@ module Gem::GemcutterUtilities env_rubygems_host = nil if env_rubygems_host and env_rubygems_host.empty? - env_rubygems_host|| configured_host + env_rubygems_host || configured_host end end @@ -116,7 +116,7 @@ module Gem::GemcutterUtilities say "Don't have an account yet? " + "Create one at #{sign_in_host}/sign_up" - email = ask " Email: " + email = ask " Email: " password = ask_for_password "Password: " say "\n" diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb index b97347177d..4d199868fb 100644 --- a/lib/rubygems/indexer.rb +++ b/lib/rubygems/indexer.rb @@ -131,7 +131,10 @@ class Gem::Indexer marshal_name = File.join @quick_marshal_dir, spec_file_name marshal_zipped = Gem.deflate Marshal.dump(spec) - File.open marshal_name, 'wb' do |io| io.write marshal_zipped end + + File.open marshal_name, 'wb' do |io| + io.write marshal_zipped + end files << marshal_name @@ -180,9 +183,9 @@ class Gem::Indexer # Builds indices for RubyGems 1.2 and newer. Handles full, latest, prerelease def build_modern_indices(specs) - prerelease, released = specs.partition { |s| + prerelease, released = specs.partition do |s| s.version.prerelease? - } + end latest_specs = Gem::Specification._latest_specs specs @@ -200,7 +203,7 @@ class Gem::Indexer end def map_gems_to_specs(gems) - gems.map { |gemfile| + gems.map do |gemfile| if File.size(gemfile) == 0 alert_warning "Skipping zero-length gem: #{gemfile}" next @@ -223,7 +226,7 @@ class Gem::Indexer "\t#{e.backtrace.join "\n\t"}"].join("\n") alert_error msg end - }.compact + end.compact end ## @@ -439,4 +442,5 @@ class Gem::Indexer Marshal.dump specs_index, io end end + end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 6cd073e11d..b64ba17be6 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -108,6 +108,7 @@ class Gem::Installer end class FakePackage + attr_accessor :spec attr_accessor :dir_mode @@ -125,12 +126,15 @@ class Gem::Installer file = File.join destination_dir, file next if File.exist? file FileUtils.mkdir_p File.dirname(file) - File.open file, 'w' do |fp| fp.puts "# #{file}" end + File.open file, 'w' do |fp| + fp.puts "# #{file}" + end end end def copy_to(path) end + end ## @@ -467,7 +471,7 @@ class Gem::Installer def generate_windows_script(filename, bindir) if Gem.win_platform? - script_name = filename + ".bat" + script_name = formatted_program_filename(filename) + ".bat" script_path = File.join bindir, File.basename(script_name) File.open script_path, 'w' do |file| file.puts windows_stub_script(bindir, filename) diff --git a/lib/rubygems/installer_test_case.rb b/lib/rubygems/installer_test_case.rb index d6d16a9194..6fdc2d6337 100644 --- a/lib/rubygems/installer_test_case.rb +++ b/lib/rubygems/installer_test_case.rb @@ -58,6 +58,7 @@ class Gem::Installer # Available through requiring rubygems/installer_test_case attr_writer :wrappers + end ## @@ -150,10 +151,15 @@ class Gem::InstallerTestCase < Gem::TestCase FileUtils.mkdir_p 'bin' FileUtils.mkdir_p 'lib' FileUtils.mkdir_p File.join('ext', 'a') + File.open File.join('bin', 'executable'), 'w' do |f| f.puts "raise 'ran executable'" end - File.open File.join('lib', 'code.rb'), 'w' do |f| f.puts '1' end + + File.open File.join('lib', 'code.rb'), 'w' do |f| + f.puts '1' + end + File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f| f << <<-EOF File.open 'Rakefile', 'w' do |rf| rf.puts "task :default" end diff --git a/lib/rubygems/local_remote_options.rb b/lib/rubygems/local_remote_options.rb index 9fa256b08a..c940f50ad6 100644 --- a/lib/rubygems/local_remote_options.rb +++ b/lib/rubygems/local_remote_options.rb @@ -26,7 +26,7 @@ module Gem::LocalRemoteOptions valid_uri_schemes = ["http", "https", "file", "s3"] unless valid_uri_schemes.include?(uri.scheme) - msg = "Invalid uri scheme for #{value}\nPreface URLs with one of #{valid_uri_schemes.map{|s| "#{s}://"}}" + msg = "Invalid uri scheme for #{value}\nPreface URLs with one of #{valid_uri_schemes.map{|s| "#{s}://"}}" raise ArgumentError, msg end diff --git a/lib/rubygems/mock_gem_ui.rb b/lib/rubygems/mock_gem_ui.rb index 92ec85625c..e6105d9d49 100644 --- a/lib/rubygems/mock_gem_ui.rb +++ b/lib/rubygems/mock_gem_ui.rb @@ -7,6 +7,7 @@ require 'rubygems/user_interaction' # retrieval during tests. class Gem::MockGemUi < Gem::StreamUI + ## # Raised when you haven't provided enough input to your MockGemUi @@ -19,12 +20,14 @@ class Gem::MockGemUi < Gem::StreamUI end class TermError < RuntimeError + attr_reader :exit_code def initialize(exit_code) super @exit_code = exit_code end + end class SystemExitException < RuntimeError; end diff --git a/lib/rubygems/name_tuple.rb b/lib/rubygems/name_tuple.rb index e948fb3d86..7cb38233eb 100644 --- a/lib/rubygems/name_tuple.rb +++ b/lib/rubygems/name_tuple.rb @@ -7,6 +7,7 @@ require 'rubygems/platform' class Gem::NameTuple + def initialize(name, version, platform="ruby") @name = name @version = version diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 8695b85fec..278ada8514 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -53,6 +53,7 @@ class Gem::Package class Error < Gem::Exception; end class FormatError < Error + attr_reader :path def initialize(message, source = nil) @@ -68,10 +69,12 @@ class Gem::Package end class PathError < Error + def initialize(destination, destination_dir) super "installing into parent path %s of %s is not allowed" % [destination, destination_dir] end + end class NonSeekableIO < Error; end diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb index ed680d6553..2187766c41 100644 --- a/lib/rubygems/path_support.rb +++ b/lib/rubygems/path_support.rb @@ -5,6 +5,7 @@ # to the rest of RubyGems. # class Gem::PathSupport + ## # The default system path for managing Gems. attr_reader :home @@ -87,4 +88,5 @@ class Gem::PathSupport path end end + end diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index f8fe4dad54..603d8ae8b8 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -202,4 +202,5 @@ class Gem::Platform # This will be replaced with Gem::Platform::local. CURRENT = 'current'.freeze + end diff --git a/lib/rubygems/psych_tree.rb b/lib/rubygems/psych_tree.rb index 6f399a289e..b4eebf1dcc 100644 --- a/lib/rubygems/psych_tree.rb +++ b/lib/rubygems/psych_tree.rb @@ -2,6 +2,7 @@ module Gem if defined? ::Psych::Visitors class NoAliasYAMLTree < Psych::Visitors::YAMLTree + def self.create new({}) end unless respond_to? :create @@ -27,6 +28,7 @@ module Gem end private :format_time + end end end diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index 69879df67c..32c65eada8 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -402,4 +402,5 @@ class Gem::RemoteFetcher [id, secret] end + end diff --git a/lib/rubygems/request.rb b/lib/rubygems/request.rb index d442f6534b..1ed2b8ad50 100644 --- a/lib/rubygems/request.rb +++ b/lib/rubygems/request.rb @@ -13,7 +13,7 @@ class Gem::Request def self.create_with_proxy(uri, request_class, last_modified, proxy) # :nodoc: cert_files = get_cert_files proxy ||= get_proxy_from_env(uri.scheme) - pool = ConnectionPools.new proxy_uri(proxy), cert_files + pool = ConnectionPools.new proxy_uri(proxy), cert_files new(uri, request_class, last_modified, pool.pool_for(uri)) end @@ -168,9 +168,10 @@ class Gem::Request no_env_proxy = env_proxy.nil? || env_proxy.empty? - return :no_proxy if scheme == 'https' && no_env_proxy - return get_proxy_from_env 'http' if no_env_proxy and _scheme != 'http' - return :no_proxy if no_env_proxy + if no_env_proxy + return (_scheme == 'https' || _scheme == 'http') ? + :no_proxy : get_proxy_from_env('http') + end uri = URI(Gem::UriFormatter.new(env_proxy).normalize) diff --git a/lib/rubygems/request/connection_pools.rb b/lib/rubygems/request/connection_pools.rb index c02f083b63..7c273d5465 100644 --- a/lib/rubygems/request/connection_pools.rb +++ b/lib/rubygems/request/connection_pools.rb @@ -5,7 +5,9 @@ class Gem::Request::ConnectionPools # :nodoc: @client = Net::HTTP class << self + attr_accessor :client + end def initialize(proxy_uri, cert_files) @@ -40,7 +42,7 @@ class Gem::Request::ConnectionPools # :nodoc: def get_no_proxy_from_env env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY'] - return [] if env_no_proxy.nil? or env_no_proxy.empty? + return [] if env_no_proxy.nil? or env_no_proxy.empty? env_no_proxy.split(/\s*,\s*/) end diff --git a/lib/rubygems/request/http_pool.rb b/lib/rubygems/request/http_pool.rb index a85fc2bdf6..058094a209 100644 --- a/lib/rubygems/request/http_pool.rb +++ b/lib/rubygems/request/http_pool.rb @@ -6,6 +6,7 @@ # use it. class Gem::Request::HTTPPool # :nodoc: + attr_reader :cert_files, :proxy_uri def initialize(http_args, cert_files, proxy_uri) diff --git a/lib/rubygems/request/https_pool.rb b/lib/rubygems/request/https_pool.rb index 50f42d9e0d..1236079b7d 100644 --- a/lib/rubygems/request/https_pool.rb +++ b/lib/rubygems/request/https_pool.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true class Gem::Request::HTTPSPool < Gem::Request::HTTPPool # :nodoc: + private def setup_connection(connection) Gem::Request.configure_connection_for_https(connection, @cert_files) super end + end diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb index 6017d15d13..4ac6ce0293 100644 --- a/lib/rubygems/request_set.rb +++ b/lib/rubygems/request_set.rb @@ -457,9 +457,9 @@ class Gem::RequestSet node.spec.dependencies.each do |dep| next if dep.type == :development and not @development - match = @requests.find { |r| + match = @requests.find do |r| dep.match? r.spec.name, r.spec.version, @prerelease - } + end unless match next if dep.type == :development and @development_shallow diff --git a/lib/rubygems/request_set/gem_dependency_api.rb b/lib/rubygems/request_set/gem_dependency_api.rb index 3892e7aa5f..a4d803f915 100644 --- a/lib/rubygems/request_set/gem_dependency_api.rb +++ b/lib/rubygems/request_set/gem_dependency_api.rb @@ -43,11 +43,12 @@ class Gem::RequestSet::GemDependencyAPI :mri_20 => %w[ruby], :mri_21 => %w[ruby], :rbx => %w[rbx], - :ruby => %w[ruby rbx maglev], - :ruby_18 => %w[ruby rbx maglev], - :ruby_19 => %w[ruby rbx maglev], - :ruby_20 => %w[ruby rbx maglev], - :ruby_21 => %w[ruby rbx maglev], + :truffleruby => %w[truffleruby], + :ruby => %w[ruby rbx maglev truffleruby], + :ruby_18 => %w[ruby rbx maglev truffleruby], + :ruby_19 => %w[ruby rbx maglev truffleruby], + :ruby_20 => %w[ruby rbx maglev truffleruby], + :ruby_21 => %w[ruby rbx maglev truffleruby], }.freeze mswin = Gem::Platform.new 'x86-mswin32' @@ -85,6 +86,7 @@ class Gem::RequestSet::GemDependencyAPI :ruby_19 => Gem::Platform::RUBY, :ruby_20 => Gem::Platform::RUBY, :ruby_21 => Gem::Platform::RUBY, + :truffleruby => Gem::Platform::RUBY, :x64_mingw => x64_mingw, :x64_mingw_20 => x64_mingw, :x64_mingw_21 => x64_mingw @@ -126,6 +128,7 @@ class Gem::RequestSet::GemDependencyAPI :ruby_19 => tilde_gt_1_9_0, :ruby_20 => tilde_gt_2_0_0, :ruby_21 => tilde_gt_2_1_0, + :truffleruby => gt_eq_0, :x64_mingw => gt_eq_0, :x64_mingw_20 => tilde_gt_2_0_0, :x64_mingw_21 => tilde_gt_2_1_0, @@ -440,7 +443,7 @@ Gem dependencies file #{@path} requires #{name} more than once. Gem dependencies file #{@path} includes git reference for both ref and branch but only ref is used. WARNING end - if (ref||branch) && tag + if (ref || branch) && tag warn <<-WARNING Gem dependencies file #{@path} includes git reference for both ref/branch and tag but only ref/branch is used. WARNING @@ -480,7 +483,7 @@ Gem dependencies file #{@path} includes git reference for both ref/branch and ta def gem_group(name, options) # :nodoc: g = options.delete :group - all_groups = g ? Array(g) : [] + all_groups = g ? Array(g) : [] groups = options.delete :groups all_groups |= groups if groups diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb index 1b374660f0..0776cf82e3 100644 --- a/lib/rubygems/request_set/lockfile.rb +++ b/lib/rubygems/request_set/lockfile.rb @@ -5,6 +5,7 @@ # constructed. class Gem::RequestSet::Lockfile + ## # Raised when a lockfile cannot be parsed @@ -35,6 +36,7 @@ class Gem::RequestSet::Lockfile @path = path super "#{message} (at line #{line} column #{column})" end + end ## @@ -79,7 +81,7 @@ class Gem::RequestSet::Lockfile @gem_deps_file.untaint unless gem_deps_file.tainted? - @platforms = [] + @platforms = [] end def add_DEPENDENCIES(out) # :nodoc: @@ -153,7 +155,7 @@ class Gem::RequestSet::Lockfile base = File.expand_path(base) if dest.index(base) == 0 - offset = dest[base.size+1..-1] + offset = dest[base.size + 1..-1] return '.' unless offset @@ -233,6 +235,7 @@ class Gem::RequestSet::Lockfile def requests @set.sorted_requests end + end require 'rubygems/request_set/lockfile/tokenizer' diff --git a/lib/rubygems/request_set/lockfile/parser.rb b/lib/rubygems/request_set/lockfile/parser.rb index 0fe0405e32..1e9d2b12de 100644 --- a/lib/rubygems/request_set/lockfile/parser.rb +++ b/lib/rubygems/request_set/lockfile/parser.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true class Gem::RequestSet::Lockfile::Parser + ### # Parses lockfiles @@ -327,9 +328,9 @@ class Gem::RequestSet::Lockfile::Parser def pinned_requirement(name) # :nodoc: requirement = Gem::Dependency.new name - specification = @set.sets.flat_map { |set| + specification = @set.sets.flat_map do |set| set.find_all(requirement) - }.compact.first + end.compact.first specification && specification.version end @@ -340,4 +341,5 @@ class Gem::RequestSet::Lockfile::Parser def unget(token) # :nodoc: @tokens.unshift token end + end diff --git a/lib/rubygems/request_set/lockfile/tokenizer.rb b/lib/rubygems/request_set/lockfile/tokenizer.rb index bb69c85fb4..97396ec199 100644 --- a/lib/rubygems/request_set/lockfile/tokenizer.rb +++ b/lib/rubygems/request_set/lockfile/tokenizer.rb @@ -2,6 +2,7 @@ require 'rubygems/request_set/lockfile/parser' class Gem::RequestSet::Lockfile::Tokenizer + Token = Struct.new :type, :value, :column, :line EOF = Token.new :EOF @@ -109,4 +110,5 @@ class Gem::RequestSet::Lockfile::Tokenizer @tokens end + end diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb index 48f4b00d63..918404f2cd 100644 --- a/lib/rubygems/requirement.rb +++ b/lib/rubygems/requirement.rb @@ -2,10 +2,6 @@ require "rubygems/version" require "rubygems/deprecate" -# If we're being loaded after yaml was already required, then -# load our yaml + workarounds now. -Gem.load_yaml if defined? ::YAML - ## # A Requirement is a set of one or more version restrictions. It supports a # few (=, !=, >, <, >=, <=, ~>) different restriction operators. @@ -14,6 +10,7 @@ Gem.load_yaml if defined? ::YAML # together in RubyGems. class Gem::Requirement + OPS = { #:nodoc: "=" => lambda { |v, r| v == r }, "!=" => lambda { |v, r| v != r }, @@ -26,7 +23,7 @@ class Gem::Requirement SOURCE_SET_REQUIREMENT = Struct.new(:for_lockfile).new "!" # :nodoc: - quoted = OPS.keys.map { |k| Regexp.quote k }.join "|" + quoted = OPS.keys.map { |k| Regexp.quote k }.join "|" PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Gem::Version::VERSION_PATTERN})\\s*".freeze # :nodoc: ## @@ -156,11 +153,11 @@ class Gem::Requirement def for_lockfile # :nodoc: return if [DefaultRequirement] == @requirements - list = requirements.sort_by { |_, version| + list = requirements.sort_by do |_, version| version - }.map { |op, version| + end.map do |op, version| "#{op} #{version}" - }.uniq + end.uniq " (#{list.join ', '})" end @@ -305,11 +302,14 @@ class Gem::Requirement l.first <=> r.first # then, sort by the operator (for stability) end end + end class Gem::Version + # This is needed for compatibility with older yaml # gemspecs. Requirement = Gem::Requirement # :nodoc: + end diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb index 8a72006ea8..d308f68f21 100644 --- a/lib/rubygems/resolver.rb +++ b/lib/rubygems/resolver.rb @@ -11,6 +11,7 @@ require 'rubygems/util/list' # all the requirements. class Gem::Resolver + require 'rubygems/resolver/molinillo' ## @@ -234,11 +235,11 @@ class Gem::Resolver groups = Hash.new { |hash, key| hash[key] = [] } # create groups & sources in the same loop - sources = possibles.map { |spec| + sources = possibles.map do |spec| source = spec.source groups[source] << spec source - }.uniq.reverse + end.uniq.reverse activation_requests = [] diff --git a/lib/rubygems/resolver/activation_request.rb b/lib/rubygems/resolver/activation_request.rb index b28e1bef32..78e8a46674 100644 --- a/lib/rubygems/resolver/activation_request.rb +++ b/lib/rubygems/resolver/activation_request.rb @@ -54,12 +54,12 @@ class Gem::Resolver::ActivationRequest if @spec.respond_to? :sources exception = nil - path = @spec.sources.find{ |source| + path = @spec.sources.find do |source| begin source.download full_spec, path rescue exception end - } + end return path if path raise exception if exception diff --git a/lib/rubygems/resolver/best_set.rb b/lib/rubygems/resolver/best_set.rb index cc91b65c0b..8a8c15d9a4 100644 --- a/lib/rubygems/resolver/best_set.rb +++ b/lib/rubygems/resolver/best_set.rb @@ -63,9 +63,9 @@ class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet uri = URI uri unless URI === uri uri.query = nil - raise error unless api_set = @sets.find { |set| + raise error unless api_set = @sets.find do |set| Gem::Resolver::APISet === set and set.dep_uri == uri - } + end index_set = Gem::Resolver::IndexSet.new api_set.source diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb index f3827ad4e9..ba14ee945d 100644 --- a/lib/rubygems/resolver/installer_set.rb +++ b/lib/rubygems/resolver/installer_set.rb @@ -55,9 +55,9 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set found = find_all request - found.delete_if { |s| + found.delete_if do |s| s.version.prerelease? and not s.local? - } unless dependency.prerelease? + end unless dependency.prerelease? found = found.select do |s| Gem::Source::SpecificFile === s.source or @@ -115,7 +115,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set def find_all(req) res = [] - dep = req.dependency + dep = req.dependency return res if @ignore_dependencies and @always_install.none? { |spec| dep.match? spec } diff --git a/lib/rubygems/resolver/lock_set.rb b/lib/rubygems/resolver/lock_set.rb index 4002a963a4..4134b4dcaf 100644 --- a/lib/rubygems/resolver/lock_set.rb +++ b/lib/rubygems/resolver/lock_set.rb @@ -16,7 +16,7 @@ class Gem::Resolver::LockSet < Gem::Resolver::Set Gem::Source::Lock.new source end - @specs = [] + @specs = [] end ## diff --git a/lib/rubygems/resolver/lock_specification.rb b/lib/rubygems/resolver/lock_specification.rb index e29b567de4..5954507dba 100644 --- a/lib/rubygems/resolver/lock_specification.rb +++ b/lib/rubygems/resolver/lock_specification.rb @@ -71,9 +71,9 @@ class Gem::Resolver::LockSpecification < Gem::Resolver::Specification # A specification constructed from the lockfile is returned def spec - @spec ||= Gem::Specification.find { |spec| + @spec ||= Gem::Specification.find do |spec| spec.name == @name and spec.version == @version - } + end @spec ||= Gem::Specification.new do |s| s.name = @name diff --git a/lib/rubygems/resolver/requirement_list.rb b/lib/rubygems/resolver/requirement_list.rb index 98d086e63c..cf0014b0bb 100644 --- a/lib/rubygems/resolver/requirement_list.rb +++ b/lib/rubygems/resolver/requirement_list.rb @@ -79,4 +79,5 @@ class Gem::Resolver::RequirementList x = @exact[0,5] x + @list[0,5 - x.size] end + end diff --git a/lib/rubygems/resolver/specification.rb b/lib/rubygems/resolver/specification.rb index 7c1e9be702..e859d6659a 100644 --- a/lib/rubygems/resolver/specification.rb +++ b/lib/rubygems/resolver/specification.rb @@ -111,4 +111,5 @@ class Gem::Resolver::Specification def local? # :nodoc: false end + end diff --git a/lib/rubygems/resolver/stats.rb b/lib/rubygems/resolver/stats.rb index 64b458f504..5f41940b1e 100644 --- a/lib/rubygems/resolver/stats.rb +++ b/lib/rubygems/resolver/stats.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true class Gem::Resolver::Stats + def initialize @max_depth = 0 @max_requirements = 0 @@ -42,4 +43,5 @@ class Gem::Resolver::Stats $stdout.printf PATTERN, "Backtracking #", @backtracking $stdout.printf PATTERN, "Iteration #", @iterations end + end diff --git a/lib/rubygems/security/signer.rb b/lib/rubygems/security/signer.rb index 34e86e921a..4e835e5b80 100644 --- a/lib/rubygems/security/signer.rb +++ b/lib/rubygems/security/signer.rb @@ -72,7 +72,7 @@ class Gem::Security::Signer @options = DEFAULT_OPTIONS.merge(options) unless @key - default_key = File.join Gem.default_key_path + default_key = File.join Gem.default_key_path @key = default_key if File.exist? default_key end diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb index 1453bf2323..97923ef698 100644 --- a/lib/rubygems/server.rb +++ b/lib/rubygems/server.rb @@ -607,13 +607,13 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } Gem::Specification.each do |spec| total_file_count += spec.files.size - deps = spec.dependencies.map { |dep| + deps = spec.dependencies.map do |dep| { "name" => dep.name, "type" => dep.type, "version" => dep.requirement.to_s, } - } + end deps = deps.sort_by { |dep| [dep["name"].downcase, dep["version"]] } deps.last["is_last"] = true unless deps.empty? @@ -754,9 +754,9 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } # documentation - just put it underneath the main doc folder. def show_rdoc_for_pattern(pattern, res) - found_gems = Dir.glob("{#{@gem_dirs.join ','}}/doc/#{pattern}").select {|path| + found_gems = Dir.glob("{#{@gem_dirs.join ','}}/doc/#{pattern}").select do |path| File.exist? File.join(path, 'rdoc/index.html') - } + end case found_gems.length when 0 return false @@ -875,4 +875,5 @@ div.method-source-code pre { color: #ffdead; overflow: hidden; } system("#{@launch} http://#{host}:#{@port}") end + end diff --git a/lib/rubygems/source_list.rb b/lib/rubygems/source_list.rb index 83b689f78e..0622bfa17b 100644 --- a/lib/rubygems/source_list.rb +++ b/lib/rubygems/source_list.rb @@ -147,4 +147,5 @@ class Gem::SourceList @sources.delete_if { |x| x.uri.to_s == source.to_s } end end + end diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb index ca901cb8bf..4e62d7dd81 100644 --- a/lib/rubygems/spec_fetcher.rb +++ b/lib/rubygems/spec_fetcher.rb @@ -189,7 +189,7 @@ class Gem::SpecFetcher max = gem_name.size / 2 names = available_specs(type).first.values.flatten(1) - matches = names.map { |n| + matches = names.map do |n| next unless n.match_platform? distance = levenshtein_distance gem_name, n.name.downcase.tr('_-', '') @@ -199,7 +199,7 @@ class Gem::SpecFetcher return [n.name] if distance == 0 [n.name, distance] - }.compact + end.compact matches = if matches.empty? && type != :prerelease suggest_gems_from_name gem_name, :prerelease diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 0215f4aa66..6e1246c920 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -85,14 +85,14 @@ class Gem::Specification < Gem::BasicSpecification 'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"', '"test_file=x" is a shortcut for "test_files=[x]"' ], - 2 => [ + 2 => [ 'Added "required_rubygems_version"', 'Now forward-compatible with future versions', ], - 3 => [ + 3 => [ 'Added Fixnum validation to the specification_version' ], - 4 => [ + 4 => [ 'Added sandboxed freeform metadata to the specification version.' ] }.freeze @@ -183,9 +183,9 @@ class Gem::Specification < Gem::BasicSpecification @@attributes = @@default_value.keys.sort_by { |s| s.to_s } @@array_attributes = @@default_value.reject { |k,v| v != [] }.keys - @@nil_attributes, @@non_nil_attributes = @@default_value.keys.partition { |k| + @@nil_attributes, @@non_nil_attributes = @@default_value.keys.partition do |k| @@default_value[k].nil? - } + end @@stubs_by_name = {} @@ -792,11 +792,11 @@ class Gem::Specification < Gem::BasicSpecification private_class_method :installed_stubs def self.map_stubs(dirs, pattern) # :nodoc: - dirs.flat_map { |dir| + dirs.flat_map do |dir| base_dir = File.dirname dir gems_dir = File.join base_dir, "gems" gemspec_stubs_in(dir, pattern) { |path| yield path, base_dir, gems_dir } - } + end end private_class_method :map_stubs @@ -854,11 +854,11 @@ class Gem::Specification < Gem::BasicSpecification end def self._resort!(specs) # :nodoc: - specs.sort! { |a, b| + specs.sort! do |a, b| names = a.name <=> b.name next names if names.nonzero? b.version <=> a.version - } + end end ## @@ -974,9 +974,9 @@ class Gem::Specification < Gem::BasicSpecification # Return the directories that Specification uses to find specs. def self.dirs - @@dirs ||= Gem.path.collect { |dir| + @@dirs ||= Gem.path.collect do |dir| File.join dir.dup.untaint, "specifications" - } + end end ## @@ -1038,10 +1038,10 @@ class Gem::Specification < Gem::BasicSpecification def self.find_by_path(path) path = path.dup.freeze - spec = @@spec_with_requirable_file[path] ||= (stubs.find { |s| + spec = @@spec_with_requirable_file[path] ||= (stubs.find do |s| next unless Gem::BundlerVersionFinder.compatible?(s) s.contains_requirable_file? path - } || NOT_FOUND) + end || NOT_FOUND) spec.to_spec end @@ -1050,18 +1050,18 @@ class Gem::Specification < Gem::BasicSpecification # amongst the specs that are not activated. def self.find_inactive_by_path(path) - stub = stubs.find { |s| + stub = stubs.find do |s| next if s.activated? next unless Gem::BundlerVersionFinder.compatible?(s) s.contains_requirable_file? path - } + end stub && stub.to_spec end def self.find_active_stub_by_path(path) - stub = @@active_stub_with_requirable_file[path] ||= (stubs.find { |s| + stub = @@active_stub_with_requirable_file[path] ||= (stubs.find do |s| s.activated? and s.contains_requirable_file? path - } || NOT_FOUND) + end || NOT_FOUND) stub.this end @@ -1142,10 +1142,10 @@ class Gem::Specification < Gem::BasicSpecification result[spec.name][spec.platform] = spec end - result.map(&:last).map(&:values).flatten.reject { |spec| + result.map(&:last).map(&:values).flatten.reject do |spec| minimum = native[spec.name] minimum && spec.version < minimum - }.sort_by{ |tup| tup.name } + end.sort_by{ |tup| tup.name } end ## @@ -1311,6 +1311,8 @@ class Gem::Specification < Gem::BasicSpecification # Load custom marshal format, re-initializing defaults as needed def self._load(str) + Gem.load_yaml + array = Marshal.load str spec = Gem::Specification.new @@ -1678,12 +1680,12 @@ class Gem::Specification < Gem::BasicSpecification def conflicts conflicts = {} - self.runtime_dependencies.each { |dep| + self.runtime_dependencies.each do |dep| spec = Gem.loaded_specs[dep.name] if spec and not spec.satisfies_requirement? dep (conflicts[spec] ||= []) << dep end - } + end env_req = Gem.env_requirement(name) (conflicts[self] ||= []) << env_req unless env_req.satisfied_by? version conflicts @@ -1693,9 +1695,9 @@ class Gem::Specification < Gem::BasicSpecification # return true if there will be conflict when spec if loaded together with the list of specs. def conficts_when_loaded_with?(list_of_specs) # :nodoc: - result = list_of_specs.any? { |spec| + result = list_of_specs.any? do |spec| spec.dependencies.any? { |dep| dep.runtime? && (dep.name == name) && !satisfies_requirement?(dep) } - } + end result end @@ -1704,14 +1706,14 @@ class Gem::Specification < Gem::BasicSpecification def has_conflicts? return true unless Gem.env_requirement(name).satisfied_by?(version) - self.dependencies.any? { |dep| + self.dependencies.any? do |dep| if dep.runtime? spec = Gem.loaded_specs[dep.name] spec and not spec.satisfies_requirement? dep else false end - } + end end # The date this gem was created. @@ -2591,6 +2593,8 @@ class Gem::Specification < Gem::BasicSpecification end def to_yaml(opts = {}) # :nodoc: + Gem.load_yaml + # Because the user can switch the YAML engine behind our # back, we have to check again here to make sure that our # psych code was properly loaded, and load it if not. diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index 4b79c1ac61..a4c6888cd1 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -2,6 +2,7 @@ require 'delegate' require 'uri' class Gem::SpecificationPolicy < SimpleDelegator + VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/.freeze # :nodoc: SPECIAL_CHARACTERS = /\A[#{Regexp.escape('.-_')}]+/.freeze # :nodoc: @@ -300,7 +301,7 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: end def validate_licenses - licenses.each { |license| + licenses.each do |license| if license.length > 64 error "each license must be 64 characters or less" end @@ -314,7 +315,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li message += "Did you mean #{suggestions.map { |s| "'#{s}'"}.join(', ')}?\n" unless suggestions.nil? warning(message) end - } + end warning <<-warning if licenses.empty? licenses is empty, but is recommended. Use a license identifier from @@ -404,4 +405,5 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li def help_text # :nodoc: "See http://guides.rubygems.org/specification-reference/ for help" end + end diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb index 022da9185d..e2f6e245e7 100644 --- a/lib/rubygems/stub_specification.rb +++ b/lib/rubygems/stub_specification.rb @@ -5,6 +5,7 @@ # information. class Gem::StubSpecification < Gem::BasicSpecification + # :nodoc: PREFIX = "# stub: ".freeze @@ -12,6 +13,7 @@ class Gem::StubSpecification < Gem::BasicSpecification OPEN_MODE = 'r:UTF-8:-'.freeze class StubLine # :nodoc: all + attr_reader :name, :version, :platform, :require_paths, :extensions, :full_name @@ -50,10 +52,11 @@ class Gem::StubSpecification < Gem::BasicSpecification end path_list = parts.last - @require_paths = REQUIRE_PATH_LIST[path_list] || path_list.split("\0".freeze).map! { |x| + @require_paths = REQUIRE_PATH_LIST[path_list] || path_list.split("\0".freeze).map! do |x| REQUIRE_PATHS[x] || x - } + end end + end def self.default_gemspec_stub(filename, base_dir, gems_dir) diff --git a/lib/rubygems/syck_hack.rb b/lib/rubygems/syck_hack.rb index 051483eac8..0d87c71df4 100644 --- a/lib/rubygems/syck_hack.rb +++ b/lib/rubygems/syck_hack.rb @@ -40,11 +40,13 @@ module YAML # :nodoc: # should. module Syck class DefaultKey + remove_method :to_s rescue nil def to_s '=' end + end end diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 783e8956a1..5f2bbd7b86 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -1,12 +1,6 @@ # frozen_string_literal: true # TODO: $SAFE = 1 -begin - gem 'minitest', '~> 5.0' -rescue NoMethodError, Gem::LoadError - # for ruby tests -end - if defined? Gem::QuickLoader Gem::QuickLoader.load_full_rubygems_library else @@ -23,7 +17,7 @@ if File.exist?(bundler_gemspec) end begin - gem 'minitest' + gem 'minitest', '~> 5.0' rescue Gem::LoadError end @@ -115,6 +109,8 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni attr_accessor :uri # :nodoc: + TEST_PATH = ENV.fetch('RUBYGEMS_TEST_PATH', File.expand_path('../../../test/rubygems', __FILE__)) + def assert_activate(expected, *specs) specs.each do |spec| case spec @@ -191,19 +187,19 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni def assert_contains_make_command(target, output, msg = nil) if output.match(/\n/) - msg = message(msg) { + msg = message(msg) do 'Expected output containing make command "%s": %s' % [ ('%s %s' % [make_command, target]).rstrip, output.inspect ] - } + end else - msg = message(msg) { + msg = message(msg) do 'Expected make command "%s": %s' % [ ('%s %s' % [make_command, target]).rstrip, output.inspect ] - } + end end assert scan_make_command_lines(output).any? { |line| @@ -260,7 +256,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni @fetcher = nil if Gem::USE_BUNDLER_FOR_GEMDEPS - Bundler.ui = Bundler::UI::Silent.new + Bundler.ui = Bundler::UI::Silent.new end @back_ui = Gem::DefaultUserInteraction.ui @ui = Gem::MockGemUi.new @@ -316,7 +312,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni Gem.ensure_gem_subdirectories @gemhome @orig_LOAD_PATH = $LOAD_PATH.dup - $LOAD_PATH.map! { |s| + $LOAD_PATH.map! do |s| expand_path = File.expand_path(s) if expand_path != s expand_path.untaint @@ -327,7 +323,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni s = expand_path end s - } + end Dir.chdir @tempdir @@ -599,11 +595,11 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni def uninstall_gem(spec) require 'rubygems/uninstaller' - Class.new(Gem::Uninstaller) { + Class.new(Gem::Uninstaller) do def ask_if_ok(spec) true end - }.new(spec.name, :executables => true, :user_install => true).uninstall + end.new(spec.name, :executables => true, :user_install => true).uninstall end ## @@ -612,7 +608,11 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni def create_tmpdir tmpdir = nil - Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp + + Dir.chdir Dir.tmpdir do + tmpdir = Dir.pwd + end # HACK OSX /private/tmp + tmpdir = File.join tmpdir, "test_rubygems_#{$$}" FileUtils.mkdir_p tmpdir return tmpdir @@ -723,7 +723,10 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni spec.files.each do |file| next if File.exist? file FileUtils.mkdir_p File.dirname(file) - File.open file, 'w' do |fp| fp.puts "# #{file}" end + + File.open file, 'w' do |fp| + fp.puts "# #{file}" + end end use_ui Gem::MockGemUi.new do @@ -751,6 +754,11 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni Gem::Specification.reset end + def util_clear_default_gems + FileUtils.rm_rf @default_spec_dir + FileUtils.mkdir @default_spec_dir + end + ## # Install the provided specs @@ -1017,7 +1025,7 @@ Also, a list: s.add_dependency 'x', '>= 1' end - @pl1 = quick_gem 'pl', '1' do |s| # l for legacy + @pl1 = quick_gem 'pl', '1' do |s| # l for legacy s.files = %w[lib/code.rb] s.require_paths = %w[lib] s.platform = Gem::Platform.new 'i386-linux' @@ -1339,6 +1347,7 @@ Also, a list: end class << self + # :nodoc: ## # Return the join path, with escaping backticks, dollars, and @@ -1352,12 +1361,12 @@ Also, a list: "\"#{path.gsub(/[`$"]/, '\\&')}\"" end end + end @@ruby = rubybin - gempath = File.expand_path('../../../test/rubygems', __FILE__) - @@good_rake = "#{rubybin} #{escape_path(gempath, 'good_rake.rb')}" - @@bad_rake = "#{rubybin} #{escape_path(gempath, 'bad_rake.rb')}" + @@good_rake = "#{rubybin} #{escape_path(TEST_PATH, 'good_rake.rb')}" + @@bad_rake = "#{rubybin} #{escape_path(TEST_PATH, 'bad_rake.rb')}" ## # Construct a new Gem::Dependency. @@ -1526,6 +1535,7 @@ Also, a list: def prefetch(reqs) # :nodoc: end + end ## @@ -1545,14 +1555,12 @@ Also, a list: def self.cert_path(cert_name) if 32 == (Time.at(2**32) rescue 32) - cert_file = - File.expand_path "../../../test/rubygems/#{cert_name}_cert_32.pem", - __FILE__ + cert_file = "#{TEST_PATH}/#{cert_name}_cert_32.pem" return cert_file if File.exist? cert_file end - File.expand_path "../../../test/rubygems/#{cert_name}_cert.pem", __FILE__ + "#{TEST_PATH}/#{cert_name}_cert.pem" end ## @@ -1570,13 +1578,13 @@ Also, a list: # Returns the path to the key named +key_name+ from test/rubygems def self.key_path(key_name) - File.expand_path "../../../test/rubygems/#{key_name}_key.pem", __FILE__ + "#{TEST_PATH}/#{key_name}_key.pem" end # :stopdoc: # only available in RubyGems tests - PRIVATE_KEY_PASSPHRASE = 'Foo bar'.freeze + PRIVATE_KEY_PASSPHRASE = 'Foo bar'.freeze begin PRIVATE_KEY = load_key 'private' diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb index d531239812..069ecccabe 100644 --- a/lib/rubygems/test_utilities.rb +++ b/lib/rubygems/test_utilities.rb @@ -366,4 +366,5 @@ class TempIO < Tempfile flush Gem.read_binary path end + end diff --git a/lib/rubygems/text.rb b/lib/rubygems/text.rb index 5d346b496b..f6817c06a2 100644 --- a/lib/rubygems/text.rb +++ b/lib/rubygems/text.rb @@ -65,12 +65,12 @@ module Gem::Text x = nil str1.each_char.each_with_index do |char1,i| - e = i+1 + e = i + 1 str2.each_char.each_with_index do |char2,j| cost = (char1 == char2) ? 0 : 1 x = min3( - d[j+1] + 1, # insertion + d[j + 1] + 1, # insertion e + 1, # deletion d[j] + cost # substitution ) diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index c213cf656e..fe423a7ebd 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -57,7 +57,7 @@ class Gem::Uninstaller # Indicate if development dependencies should be checked when # uninstalling. (default: false) # - @check_dev = options[:check_dev] + @check_dev = options[:check_dev] if options[:force] @force_all = true @@ -134,7 +134,7 @@ class Gem::Uninstaller elsif index >= 0 && index < list.size uninstall_gem list[index] else - say "Error: must enter a number [1-#{list.size+1}]" + say "Error: must enter a number [1-#{list.size + 1}]" end else uninstall_gem list.first @@ -180,9 +180,9 @@ class Gem::Uninstaller # Leave any executables created by other installed versions # of this gem installed. - list = Gem::Specification.find_all { |s| + list = Gem::Specification.find_all do |s| s.name == spec.name && s.version != spec.version - } + end list.each do |s| s.executables.each do |exe_name| @@ -354,4 +354,5 @@ class Gem::Uninstaller raise e end + end diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 03eac76ea8..ecd1454e2d 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -227,7 +227,7 @@ class Gem::StreamUI @outs.puts question list.each_with_index do |item, index| - @outs.puts " #{index+1}. #{item}" + @outs.puts " #{index + 1}. #{item}" end @outs.print "> " @@ -418,6 +418,7 @@ class Gem::StreamUI def done end + end ## @@ -506,6 +507,7 @@ class Gem::StreamUI def done @out.puts @terminal_message end + end ## @@ -549,6 +551,7 @@ class Gem::StreamUI def done end + end ## @@ -603,7 +606,9 @@ class Gem::StreamUI @out.puts message end end + end + end ## @@ -619,6 +624,7 @@ class Gem::ConsoleUI < Gem::StreamUI def initialize super STDIN, STDOUT, STDERR, true end + end ## @@ -651,4 +657,5 @@ class Gem::SilentUI < Gem::StreamUI def progress_reporter(*args) # :nodoc: SilentProgressReporter.new(@outs, *args) end + end diff --git a/lib/rubygems/util.rb b/lib/rubygems/util.rb index b9e5dfc8c7..401e5609f7 100644 --- a/lib/rubygems/util.rb +++ b/lib/rubygems/util.rb @@ -28,7 +28,9 @@ module Gem::Util zipped = StringIO.new(String.new, 'w') zipped.set_encoding Encoding::BINARY - Zlib::GzipWriter.wrap zipped do |io| io.write data end + Zlib::GzipWriter.wrap zipped do |io| + io.write data + end zipped.string end diff --git a/lib/rubygems/util/licenses.rb b/lib/rubygems/util/licenses.rb index 2a536575c0..ac0d3bb44e 100644 --- a/lib/rubygems/util/licenses.rb +++ b/lib/rubygems/util/licenses.rb @@ -2,6 +2,7 @@ require 'rubygems/text' class Gem::Licenses + extend Gem::Text NONSTANDARD = 'Nonstandard'.freeze @@ -434,4 +435,5 @@ class Gem::Licenses return unless lowest < license.size by_distance[lowest] end + end diff --git a/lib/rubygems/util/list.rb b/lib/rubygems/util/list.rb index 33c40af4bb..7e4d6b5de6 100644 --- a/lib/rubygems/util/list.rb +++ b/lib/rubygems/util/list.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true module Gem class List + include Enumerable attr_accessor :value, :tail @@ -33,5 +34,6 @@ module Gem return List.new(value) unless list List.new value, list end + end end diff --git a/lib/rubygems/validator.rb b/lib/rubygems/validator.rb index f00021daa9..7ed0a1f80f 100644 --- a/lib/rubygems/validator.rb +++ b/lib/rubygems/validator.rb @@ -25,7 +25,7 @@ class Gem::Validator installed_files = [] Find.find gem_directory do |file_name| - fn = file_name[gem_directory.size..file_name.size-1].sub(/^\//, "") + fn = file_name[gem_directory.size..file_name.size - 1].sub(/^\//, "") installed_files << fn unless fn =~ /CVS/ || fn.empty? || File.directory?(file_name) end @@ -91,17 +91,17 @@ class Gem::Validator File.open gem_path, Gem.binary_mode do |file| package = Gem::Package.new gem_path - good, gone = package.contents.partition { |file_name| + good, gone = package.contents.partition do |file_name| File.exist? File.join(gem_directory, file_name) - } + end gone.sort.each do |path| errors[gem_name][path] = "Missing file" end - good, unreadable = good.partition { |file_name| + good, unreadable = good.partition do |file_name| File.readable? File.join(gem_directory, file_name) - } + end unreadable.sort.each do |path| errors[gem_name][path] = "Unreadable file" @@ -141,4 +141,5 @@ class Gem::Validator errors end + end diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index f2f10569e8..c23b157708 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -150,6 +150,7 @@ # a zero to give a sensible result. class Gem::Version + autoload :Requirement, 'rubygems/requirement' include Comparable @@ -395,4 +396,5 @@ class Gem::Version numeric_segments = string_segments.slice!(0, string_start || string_segments.size) return numeric_segments, string_segments end + end diff --git a/test/rubygems/plugin/load/rubygems_plugin.rb b/test/rubygems/plugin/load/rubygems_plugin.rb index 7cc6bef90b..85a6851ace 100644 --- a/test/rubygems/plugin/load/rubygems_plugin.rb +++ b/test/rubygems/plugin/load/rubygems_plugin.rb @@ -1,4 +1,6 @@ # frozen_string_literal: true class TestGem + TEST_PLUGIN_LOAD = :loaded + end diff --git a/test/rubygems/test_deprecate.rb b/test/rubygems/test_deprecate.rb index fab4f33b86..b92bd1c3da 100644 --- a/test/rubygems/test_deprecate.rb +++ b/test/rubygems/test_deprecate.rb @@ -45,6 +45,7 @@ class TestDeprecate < Gem::TestCase end class Thing + extend Gem::Deprecate attr_accessor :message def foo @@ -54,6 +55,7 @@ class TestDeprecate < Gem::TestCase @message = "bar" end deprecate :foo, :bar, 2099, 3 + end def test_deprecated_method_calls_the_old_method @@ -74,4 +76,5 @@ class TestDeprecate < Gem::TestCase assert_match(/Thing#foo is deprecated; use bar instead\./, err) assert_match(/on or after 2099-03-01/, err) end + end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index c913f30e27..b2f718bf1a 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -14,7 +14,6 @@ $LOAD_PATH.map! do |path| end class TestGem < Gem::TestCase - RUBY_INSTALL_NAME = RbConfig::CONFIG['RUBY_INSTALL_NAME'] PLUGINS_LOADED = [] # rubocop:disable Style/MutableConstant @@ -151,35 +150,40 @@ class TestGem < Gem::TestCase end def test_self_install_permissions_with_format_executable - @format_executable = true - assert_self_install_permissions + assert_self_install_permissions(format_executable: true) end - def assert_self_install_permissions + def test_self_install_permissions_with_format_executable_and_non_standard_ruby_install_name + Gem::Installer.exec_format = nil + ruby_install_name 'ruby27' do + assert_self_install_permissions(format_executable: true) + end + ensure + Gem::Installer.exec_format = nil + end + + def assert_self_install_permissions(format_executable: false) mask = win_platform? ? 0700 : 0777 options = { :dir_mode => 0500, - :prog_mode => 0510, + :prog_mode => win_platform? ? 0410 : 0510, :data_mode => 0640, :wrappers => true, - :format_executable => !!(@format_executable if defined?(@format_executable)) + :format_executable => format_executable } Dir.chdir @tempdir do Dir.mkdir 'bin' - File.open 'bin/foo.cmd', 'w' do |fp| - fp.chmod(0755) - fp.puts 'p' - end - Dir.mkdir 'data' - File.open 'data/foo.txt', 'w' do |fp| - fp.puts 'blah' - end + + File.write 'bin/foo', "#!/usr/bin/env ruby\n" + File.chmod 0755, 'bin/foo' + + File.write 'data/foo.txt', "blah\n" spec_fetcher do |f| f.gem 'foo', 1 do |s| - s.executables = ['foo.cmd'] - s.files = %w[bin/foo.cmd data/foo.txt] + s.executables = ['foo'] + s.files = %w[bin/foo data/foo.txt] end end Gem.install 'foo', Gem::Requirement.default, options @@ -188,19 +192,18 @@ class TestGem < Gem::TestCase prog_mode = (options[:prog_mode] & mask).to_s(8) dir_mode = (options[:dir_mode] & mask).to_s(8) data_mode = (options[:data_mode] & mask).to_s(8) - prog_name = 'foo.cmd' - prog_name = RUBY_INSTALL_NAME.sub('ruby', 'foo.cmd') if options[:format_executable] + prog_name = 'foo' + prog_name = RbConfig::CONFIG['ruby_install_name'].sub('ruby', 'foo') if options[:format_executable] expected = { "bin/#{prog_name}" => prog_mode, 'gems/foo-1' => dir_mode, 'gems/foo-1/bin' => dir_mode, 'gems/foo-1/data' => dir_mode, - 'gems/foo-1/bin/foo.cmd' => prog_mode, + 'gems/foo-1/bin/foo' => prog_mode, 'gems/foo-1/data/foo.txt' => data_mode, } - # below is for intermittent errors on Appveyor & Travis 2019-01, - # see https://github.com/rubygems/rubygems/pull/2568 - sleep 0.2 + # add Windows script + expected["bin/#{prog_name}.bat"] = mask.to_s(8) if win_platform? result = {} Dir.chdir @gemhome do expected.each_key do |n| @@ -209,7 +212,7 @@ class TestGem < Gem::TestCase end assert_equal(expected, result) ensure - File.chmod(0755, *Dir.glob(@gemhome+'/gems/**/').map {|path| path.untaint}) + File.chmod(0755, *Dir.glob(@gemhome + '/gems/**/').map {|path| path.untaint}) end def test_require_missing @@ -413,7 +416,10 @@ class TestGem < Gem::TestCase fp.puts 'blah' end - foo = util_spec 'foo' do |s| s.files = %w[data/foo.txt] end + foo = util_spec 'foo' do |s| + s.files = %w[data/foo.txt] + end + install_gem foo end @@ -631,7 +637,7 @@ class TestGem < Gem::TestCase discover_path = File.join 'lib', 'sff', 'discover.rb' - foo1, foo2 = %w(1 2).map { |version| + foo1, foo2 = %w(1 2).map do |version| spec = quick_gem 'sff', version do |s| s.files << discover_path end @@ -641,7 +647,7 @@ class TestGem < Gem::TestCase end spec - } + end Gem.refresh @@ -663,7 +669,7 @@ class TestGem < Gem::TestCase discover_path = File.join 'lib', 'sff', 'discover.rb' - foo1, _ = %w(1 2).map { |version| + foo1, _ = %w(1 2).map do |version| spec = quick_gem 'sff', version do |s| s.files << discover_path end @@ -673,7 +679,7 @@ class TestGem < Gem::TestCase end spec - } + end Gem.refresh write_file(File.join Dir.pwd, 'Gemfile') do |fp| @@ -699,7 +705,7 @@ class TestGem < Gem::TestCase discover_path = File.join 'lib', 'sff', 'discover.rb' - _, foo2 = %w(1 2).map { |version| + _, foo2 = %w(1 2).map do |version| spec = quick_gem 'sff', version do |s| s.files << discover_path end @@ -709,7 +715,7 @@ class TestGem < Gem::TestCase end spec - } + end Gem.refresh @@ -1087,7 +1093,7 @@ class TestGem < Gem::TestCase def test_self_post_build assert_equal 1, Gem.post_build_hooks.length - Gem.post_build do |installer| end + Gem.post_build { |installer| } assert_equal 2, Gem.post_build_hooks.length end @@ -1095,7 +1101,7 @@ class TestGem < Gem::TestCase def test_self_post_install assert_equal 1, Gem.post_install_hooks.length - Gem.post_install do |installer| end + Gem.post_install { |installer| } assert_equal 2, Gem.post_install_hooks.length end @@ -1103,7 +1109,7 @@ class TestGem < Gem::TestCase def test_self_done_installing assert_empty Gem.done_installing_hooks - Gem.done_installing do |gems| end + Gem.done_installing { |gems| } assert_equal 1, Gem.done_installing_hooks.length end @@ -1119,7 +1125,7 @@ class TestGem < Gem::TestCase def test_self_post_uninstall assert_equal 1, Gem.post_uninstall_hooks.length - Gem.post_uninstall do |installer| end + Gem.post_uninstall { |installer| } assert_equal 2, Gem.post_uninstall_hooks.length end @@ -1127,7 +1133,7 @@ class TestGem < Gem::TestCase def test_self_pre_install assert_equal 1, Gem.pre_install_hooks.length - Gem.pre_install do |installer| end + Gem.pre_install { |installer| } assert_equal 2, Gem.pre_install_hooks.length end @@ -1143,7 +1149,7 @@ class TestGem < Gem::TestCase def test_self_pre_uninstall assert_equal 1, Gem.pre_uninstall_hooks.length - Gem.pre_uninstall do |installer| end + Gem.pre_uninstall { |installer| } assert_equal 2, Gem.pre_uninstall_hooks.length end @@ -1328,7 +1334,7 @@ class TestGem < Gem::TestCase a = util_spec "a", "1" b = util_spec "b", "1", "c" => nil c = util_spec "c", "2" - d = util_spec "d", "1", {'e' => '= 1'}, "lib/d.rb" + d = util_spec "d", "1", {'e' => '= 1'}, "lib/d.rb" e = util_spec "e", "1" install_specs a, c, b, e, d @@ -1943,4 +1949,5 @@ You may need to `gem install -g` to install missing gems def util_cache_dir File.join Gem.dir, "cache" end + end diff --git a/test/rubygems/test_gem_available_set.rb b/test/rubygems/test_gem_available_set.rb index d4042c94f5..64ee9a36a9 100644 --- a/test/rubygems/test_gem_available_set.rb +++ b/test/rubygems/test_gem_available_set.rb @@ -68,7 +68,7 @@ class TestGemAvailableSet < Gem::TestCase def test_best a1, _ = util_gem 'a', '1' - a2, _ = util_gem 'a', '2' + a2, _ = util_gem 'a', '2' set = Gem::AvailableSet.new set.add a1, @source @@ -97,7 +97,7 @@ class TestGemAvailableSet < Gem::TestCase def test_sorted_normal_versions a1, _ = util_gem 'a', '1' - a2, _ = util_gem 'a', '2' + a2, _ = util_gem 'a', '2' set = Gem::AvailableSet.new set.add a1, @source @@ -127,4 +127,5 @@ class TestGemAvailableSet < Gem::TestCase assert_equal [a3a, a2, a2a, a1, a1a], g end + end diff --git a/test/rubygems/test_gem_bundler_version_finder.rb b/test/rubygems/test_gem_bundler_version_finder.rb index 3b63b89423..8e883bc719 100644 --- a/test/rubygems/test_gem_bundler_version_finder.rb +++ b/test/rubygems/test_gem_bundler_version_finder.rb @@ -2,7 +2,10 @@ require 'rubygems/test_case' class TestGemBundlerVersionFinder < Gem::TestCase + def setup + super + @argv = ARGV.dup @env = ENV.to_hash.clone ENV.delete("BUNDLER_VERSION") @@ -13,6 +16,8 @@ class TestGemBundlerVersionFinder < Gem::TestCase ARGV.replace @argv ENV.replace @env $0 = @dollar_0 + + super end def bvf @@ -123,4 +128,5 @@ class TestGemBundlerVersionFinder < Gem::TestCase bvf.filter!(specs) specs end + end diff --git a/test/rubygems/test_gem_command.rb b/test/rubygems/test_gem_command.rb index 8caa9c6e2e..f3897c7102 100644 --- a/test/rubygems/test_gem_command.rb +++ b/test/rubygems/test_gem_command.rb @@ -3,7 +3,9 @@ require 'rubygems/test_case' require 'rubygems/command' class Gem::Command + public :parser + end class TestGemCommand < Gem::TestCase @@ -15,7 +17,7 @@ class TestGemCommand < Gem::TestCase @common_options = Gem::Command.common_options.dup Gem::Command.common_options.clear - Gem::Command.common_options << [ + Gem::Command.common_options << [ ['-x', '--exe', 'Execute'], lambda do |*a| @xopt = true end @@ -32,7 +34,7 @@ class TestGemCommand < Gem::TestCase def test_self_add_specific_extra_args added_args = %w[--all] - @cmd.add_option '--all' do |v,o| end + @cmd.add_option('--all') { |v,o| } Gem::Command.add_specific_extra_args @cmd_name, added_args @@ -96,7 +98,7 @@ class TestGemCommand < Gem::TestCase def test_invoke_with_bad_options use_ui @ui do - @cmd.when_invoked do true end + @cmd.when_invoked { true } ex = assert_raises OptionParser::InvalidOption do @cmd.invoke('-zzz') @@ -107,7 +109,7 @@ class TestGemCommand < Gem::TestCase end def test_invoke_with_common_options - @cmd.when_invoked do true end + @cmd.when_invoked { true } use_ui @ui do @cmd.invoke "-x" @@ -195,6 +197,93 @@ class TestGemCommand < Gem::TestCase assert_equal ['-h', 'command'], args end + def test_deprecate_option_long_name + deprecate_msg = <<-EXPECTED +WARNING: The \"--test\" option has been deprecated and will be removed in Rubygems 3.1, its use is discouraged. + EXPECTED + + testCommand = Class.new(Gem::Command) do + def initialize + super('test', 'Gem::Command instance for testing') + + add_option('-t', '--test', 'Test command') do |value, options| + options[:test] = true + end + + deprecate_option(long_name: '--test', version: '3.1') + end + + def execute + true + end + end + + cmd = testCommand.new + + use_ui @ui do + cmd.invoke("--test") + assert_equal deprecate_msg, @ui.error + end + end + + def test_deprecate_option_no_version + deprecate_msg = <<-EXPECTED +WARNING: The \"--test\" option has been deprecated and will be removed in future versions of Rubygems, its use is discouraged. + EXPECTED + + testCommand = Class.new(Gem::Command) do + def initialize + super('test', 'Gem::Command instance for testing') + + add_option('-t', '--test', 'Test command') do |value, options| + options[:test] = true + end + + deprecate_option(long_name: '--test') + end + + def execute + true + end + end + + cmd = testCommand.new + + use_ui @ui do + cmd.invoke("--test") + assert_equal deprecate_msg, @ui.error + end + end + + def test_deprecate_option_short_name + deprecate_msg = <<-EXPECTED +WARNING: The \"-t\" option has been deprecated and will be removed in Rubygems 3.5, its use is discouraged. + EXPECTED + + testCommand = Class.new(Gem::Command) do + def initialize + super('test', 'Gem::Command instance for testing') + + add_option('-t', '--test', 'Test command') do |value, options| + options[:test] = true + end + + deprecate_option(short_name: '-t', version: '3.5') + end + + def execute + true + end + end + + cmd = testCommand.new + + use_ui @ui do + cmd.invoke("-t") + assert_equal deprecate_msg, @ui.error + end + end + def test_show_lookup_failure_suggestions_local correct = "non_existent_with_hint" misspelled = "nonexistent_with_hint" diff --git a/test/rubygems/test_gem_commands_cleanup_command.rb b/test/rubygems/test_gem_commands_cleanup_command.rb index fdcd71ed8a..3494085a64 100644 --- a/test/rubygems/test_gem_commands_cleanup_command.rb +++ b/test/rubygems/test_gem_commands_cleanup_command.rb @@ -56,8 +56,13 @@ class TestGemCommandsCleanupCommand < Gem::TestCase end def test_execute_all_dependencies - @b_1 = util_spec 'b', 1 do |s| s.add_dependency 'a', '1' end - @b_2 = util_spec 'b', 2 do |s| s.add_dependency 'a', '2' end + @b_1 = util_spec 'b', 1 do |s| + s.add_dependency 'a', '1' + end + + @b_2 = util_spec 'b', 2 do |s| + s.add_dependency 'a', '2' + end install_gem @b_1 install_gem @b_2 @@ -71,8 +76,13 @@ class TestGemCommandsCleanupCommand < Gem::TestCase end def test_execute_dev_dependencies - @b_1 = util_spec 'b', 1 do |s| s.add_development_dependency 'a', '1' end - @c_1 = util_spec 'c', 1 do |s| s.add_development_dependency 'a', '2' end + @b_1 = util_spec 'b', 1 do |s| + s.add_development_dependency 'a', '1' + end + + @c_1 = util_spec 'c', 1 do |s| + s.add_development_dependency 'a', '2' + end install_gem @b_1 install_gem @c_1 @@ -85,8 +95,13 @@ class TestGemCommandsCleanupCommand < Gem::TestCase end def test_execute_without_dev_dependencies - @b_1 = util_spec 'b', 1 do |s| s.add_development_dependency 'a', '1' end - @c_1 = util_spec 'c', 1 do |s| s.add_development_dependency 'a', '2' end + @b_1 = util_spec 'b', 1 do |s| + s.add_development_dependency 'a', '1' + end + + @c_1 = util_spec 'c', 1 do |s| + s.add_development_dependency 'a', '2' + end install_gem @b_1 install_gem @c_1 @@ -263,4 +278,5 @@ class TestGemCommandsCleanupCommand < Gem::TestCase assert_path_exists d_1.gem_dir assert_path_exists d_2.gem_dir end + end diff --git a/test/rubygems/test_gem_commands_environment_command.rb b/test/rubygems/test_gem_commands_environment_command.rb index 1451f03982..074df19e52 100644 --- a/test/rubygems/test_gem_commands_environment_command.rb +++ b/test/rubygems/test_gem_commands_environment_command.rb @@ -152,4 +152,5 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase assert_equal "#{Gem.platforms.join File::PATH_SEPARATOR}\n", @ui.output assert_equal '', @ui.error end + end diff --git a/test/rubygems/test_gem_commands_help_command.rb b/test/rubygems/test_gem_commands_help_command.rb index 55bc797b28..8fcff6b1e7 100644 --- a/test/rubygems/test_gem_commands_help_command.rb +++ b/test/rubygems/test_gem_commands_help_command.rb @@ -7,6 +7,7 @@ require "rubygems/command_manager" require File.expand_path('../rubygems_plugin', __FILE__) class TestGemCommandsHelpCommand < Gem::TestCase + # previously this was calc'd in setup, but 1.8.7 had # intermittent failures, but no issues with above require PLUGIN = File.expand_path('../rubygems_plugin.rb', __FILE__) @@ -75,4 +76,5 @@ class TestGemCommandsHelpCommand < Gem::TestCase yield @ui.output, @ui.error end + end diff --git a/test/rubygems/test_gem_commands_info_command.rb b/test/rubygems/test_gem_commands_info_command.rb index 83b18c5036..373fccceee 100644 --- a/test/rubygems/test_gem_commands_info_command.rb +++ b/test/rubygems/test_gem_commands_info_command.rb @@ -41,4 +41,5 @@ class TestGemCommandsInfoCommand < Gem::TestCase assert_match %r%#{@gem.summary}\n%, @ui.output assert_match "", @ui.error end + end diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index 0976a31b50..21aa29822f 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -1142,4 +1142,59 @@ ERROR: Possible alternatives: non_existent_with_hint assert_equal [:test, :development], @cmd.options[:without_groups] end + def test_explain_platform_local + local = Gem::Platform.local + spec_fetcher do |fetcher| + fetcher.spec 'a', 2 + + fetcher.spec 'a', 2 do |s| + s.platform = local + end + end + + @cmd.options[:explain] = true + @cmd.options[:args] = %w[a] + + use_ui @ui do + assert_raises Gem::MockGemUi::SystemExitException, @ui.error do + @cmd.execute + end + end + + out = @ui.output.split "\n" + + assert_equal "Gems to install:", out.shift + assert_equal " a-2-#{local}", out.shift + assert_empty out + end + + def test_explain_platform_ruby + local = Gem::Platform.local + spec_fetcher do |fetcher| + fetcher.spec 'a', 2 + + fetcher.spec 'a', 2 do |s| + s.platform = local + end + end + + # equivalent to --platform=ruby + Gem.platforms = [Gem::Platform::RUBY] + + @cmd.options[:explain] = true + @cmd.options[:args] = %w[a] + + use_ui @ui do + assert_raises Gem::MockGemUi::SystemExitException, @ui.error do + @cmd.execute + end + end + + out = @ui.output.split "\n" + + assert_equal "Gems to install:", out.shift + assert_equal " a-2", out.shift + assert_empty out + end + end diff --git a/test/rubygems/test_gem_commands_mirror.rb b/test/rubygems/test_gem_commands_mirror.rb index 1a29755911..07ec9f3d0c 100644 --- a/test/rubygems/test_gem_commands_mirror.rb +++ b/test/rubygems/test_gem_commands_mirror.rb @@ -3,6 +3,7 @@ require 'rubygems/test_case' require 'rubygems/commands/mirror_command' class TestGemCommandsMirrorCommand < Gem::TestCase + def setup super diff --git a/test/rubygems/test_gem_commands_outdated_command.rb b/test/rubygems/test_gem_commands_outdated_command.rb index 3b0220e84b..3c37e22a09 100644 --- a/test/rubygems/test_gem_commands_outdated_command.rb +++ b/test/rubygems/test_gem_commands_outdated_command.rb @@ -29,4 +29,5 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase assert_equal "foo (0.2 < 2.0)\n", @ui.output assert_equal "", @ui.error end + end diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index e4aa8d8656..c8e3bec88e 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -54,7 +54,10 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute_all - a = util_spec 'a' do |s| s.executables = %w[foo] end + a = util_spec 'a' do |s| + s.executables = %w[foo] + end + write_file File.join(@tempdir, 'bin', 'foo') do |fp| fp.puts "#!/usr/bin/ruby" end @@ -116,7 +119,9 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute_extensions_explicit - a = util_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end + a = util_spec 'a' do |s| + s.extensions << 'ext/a/extconf.rb' + end ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb' write_file ext_path do |io| @@ -152,7 +157,9 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute_no_extension - a = util_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end + a = util_spec 'a' do |s| + s.extensions << 'ext/a/extconf.rb' + end ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb' write_file ext_path do |io| @@ -178,7 +185,9 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute_with_extension_with_build_args - a = util_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end + a = util_spec 'a' do |s| + s.extensions << 'ext/a/extconf.rb' + end ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb' write_file ext_path do |io| diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb index 592295d684..185d3cc1fc 100644 --- a/test/rubygems/test_gem_commands_push_command.rb +++ b/test/rubygems/test_gem_commands_push_command.rb @@ -28,11 +28,13 @@ class TestGemCommandsPushCommand < Gem::TestCase @cmd = Gem::Commands::PushCommand.new class << Gem + alias_method :orig_latest_rubygems_version, :latest_rubygems_version def latest_rubygems_version Gem.rubygems_version end + end end @@ -40,8 +42,10 @@ class TestGemCommandsPushCommand < Gem::TestCase super class << Gem + remove_method :latest_rubygems_version alias_method :latest_rubygems_version, :orig_latest_rubygems_version + end end @@ -132,7 +136,7 @@ class TestGemCommandsPushCommand < Gem::TestCase ENV["RUBYGEMS_HOST"] = @host Gem.configuration.disable_default_gem_server = true @response = "Successfully registered gem: freewill (1.0.0)" - @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] + @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] send_battery end @@ -160,14 +164,14 @@ class TestGemCommandsPushCommand < Gem::TestCase FileUtils.rm Gem.configuration.credentials_path @response = "Successfully registered gem: freebird (1.0.1)" - @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] + @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] send_battery end def test_sending_gem @response = "Successfully registered gem: freewill (1.0.0)" - @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] + @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] send_battery end @@ -195,7 +199,7 @@ class TestGemCommandsPushCommand < Gem::TestCase FileUtils.rm Gem.configuration.credentials_path @response = "Successfully registered gem: freebird (1.0.1)" - @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] + @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] send_battery end @@ -210,7 +214,7 @@ class TestGemCommandsPushCommand < Gem::TestCase ENV["GEM_HOST_API_KEY"] = "PRIVKEY" @response = "Successfully registered gem: freebird (1.0.1)" - @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] + @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] send_battery end @@ -237,7 +241,7 @@ class TestGemCommandsPushCommand < Gem::TestCase FileUtils.rm Gem.configuration.credentials_path @response = "Successfully registered gem: freebird (1.0.1)" - @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] + @fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK'] send_battery end @@ -311,7 +315,7 @@ class TestGemCommandsPushCommand < Gem::TestCase FileUtils.rm Gem.configuration.credentials_path @response = "Successfully registered gem: freebird (1.0.1)" - @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, 'OK'] + @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, 'OK'] # do not set @host use_ui(@ui) { @cmd.send_gem(@path) } diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb index 7957689db4..71cf386026 100644 --- a/test/rubygems/test_gem_commands_query_command.rb +++ b/test/rubygems/test_gem_commands_query_command.rb @@ -19,6 +19,7 @@ module TestGemCommandsQueryCommandSetup end class TestGemCommandsQueryCommandWithInstalledGems < Gem::TestCase + include TestGemCommandsQueryCommandSetup def test_execute @@ -585,9 +586,11 @@ pl (1 i386-linux) fetcher.spec 'a', '3.a' end end + end class TestGemCommandsQueryCommandWithoutInstalledGems < Gem::TestCase + include TestGemCommandsQueryCommandSetup def test_execute_platform @@ -829,4 +832,5 @@ othergem (1.2.3) fetcher.download 'a', '3.a' end end + end diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb index 4f34112099..569091a8a7 100644 --- a/test/rubygems/test_gem_commands_setup_command.rb +++ b/test/rubygems/test_gem_commands_setup_command.rb @@ -23,17 +23,36 @@ class TestGemCommandsSetupCommand < Gem::TestCase FileUtils.mkdir_p 'bin' FileUtils.mkdir_p 'lib/rubygems/ssl_certs/rubygems.org' - File.open 'bin/gem', 'w' do |io| io.puts '# gem' end - File.open 'lib/rubygems.rb', 'w' do |io| io.puts '# rubygems.rb' end - File.open 'lib/rubygems/test_case.rb', 'w' do |io| io.puts '# test_case.rb' end - File.open 'lib/rubygems/ssl_certs/rubygems.org/foo.pem', 'w' do |io| io.puts 'PEM' end + File.open 'bin/gem', 'w' do + |io| io.puts '# gem' + end + + File.open 'lib/rubygems.rb', 'w' do |io| + io.puts '# rubygems.rb' + end + + File.open 'lib/rubygems/test_case.rb', 'w' do |io| + io.puts '# test_case.rb' + end + + File.open 'lib/rubygems/ssl_certs/rubygems.org/foo.pem', 'w' do |io| + io.puts 'PEM' + end FileUtils.mkdir_p 'bundler/exe' FileUtils.mkdir_p 'bundler/lib/bundler' - File.open 'bundler/exe/bundle', 'w' do |io| io.puts '# bundle' end - File.open 'bundler/lib/bundler.rb', 'w' do |io| io.puts '# bundler.rb' end - File.open 'bundler/lib/bundler/b.rb', 'w' do |io| io.puts '# b.rb' end + File.open 'bundler/exe/bundle', 'w' do |io| + io.puts '# bundle' + end + + File.open 'bundler/lib/bundler.rb', 'w' do |io| + io.puts '# bundler.rb' + end + + File.open 'bundler/lib/bundler/b.rb', 'w' do |io| + io.puts '# b.rb' + end FileUtils.mkdir_p 'default/gems' @@ -220,14 +239,29 @@ class TestGemCommandsSetupCommand < Gem::TestCase FileUtils.mkdir_p lib_rubygems_defaults FileUtils.mkdir_p lib_bundler - File.open securerandom_rb, 'w' do |io| io.puts '# securerandom.rb' end + File.open securerandom_rb, 'w' do |io| + io.puts '# securerandom.rb' + end - File.open old_builder_rb, 'w' do |io| io.puts '# builder.rb' end - File.open old_format_rb, 'w' do |io| io.puts '# format.rb' end - File.open old_bundler_c_rb, 'w' do |io| io.puts '# c.rb' end + File.open old_builder_rb, 'w' do |io| + io.puts '# builder.rb' + end - File.open engine_defaults_rb, 'w' do |io| io.puts '# jruby.rb' end - File.open os_defaults_rb, 'w' do |io| io.puts '# operating_system.rb' end + File.open old_format_rb, 'w' do |io| + io.puts '# format.rb' + end + + File.open old_bundler_c_rb, 'w' do |io| + io.puts '# c.rb' + end + + File.open engine_defaults_rb, 'w' do |io| + io.puts '# jruby.rb' + end + + File.open os_defaults_rb, 'w' do |io| + io.puts '# operating_system.rb' + end @cmd.remove_old_lib_files lib diff --git a/test/rubygems/test_gem_commands_signin_command.rb b/test/rubygems/test_gem_commands_signin_command.rb index afcb8d6d99..6276ea0264 100644 --- a/test/rubygems/test_gem_commands_signin_command.rb +++ b/test/rubygems/test_gem_commands_signin_command.rb @@ -26,7 +26,7 @@ class TestGemCommandsSigninCommand < Gem::TestCase end def test_execute_when_already_signed_in_with_same_host - host = 'http://some-gemcutter-compatible-host.org' + host = 'http://some-gemcutter-compatible-host.org' util_capture(nil, host) { @cmd.execute } old_credentials = YAML.load_file Gem.configuration.credentials_path @@ -38,10 +38,10 @@ class TestGemCommandsSigninCommand < Gem::TestCase end def test_execute_when_already_signed_in_with_different_host - api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf04045xxxx' + api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf04045xxxx' util_capture(nil, nil, api_key) { @cmd.execute } - host = 'http://some-gemcutter-compatible-host.org' + host = 'http://some-gemcutter-compatible-host.org' util_capture(nil, host, api_key) { @cmd.execute } credentials = YAML.load_file Gem.configuration.credentials_path @@ -95,4 +95,5 @@ class TestGemCommandsSigninCommand < Gem::TestCase sign_in_ui end + end diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb index ad92c26073..1e58643566 100644 --- a/test/rubygems/test_gem_commands_sources_command.rb +++ b/test/rubygems/test_gem_commands_sources_command.rb @@ -40,9 +40,9 @@ class TestGemCommandsSourcesCommand < Gem::TestCase fetcher.spec 'a', 1 end - specs = Gem::Specification.map { |spec| + specs = Gem::Specification.map do |spec| [spec.name, spec.version, spec.original_platform] - } + end specs_dump_gz = StringIO.new Zlib::GzipWriter.wrap specs_dump_gz do |io| @@ -167,9 +167,9 @@ source http://gems.example.com/ already present in the cache fetcher.spec 'a', 1 end - specs = Gem::Specification.map { |spec| + specs = Gem::Specification.map do |spec| [spec.name, spec.version, spec.original_platform] - } + end specs_dump_gz = StringIO.new Zlib::GzipWriter.wrap specs_dump_gz do |io| diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 407d2451a6..efe5a768ef 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -54,7 +54,10 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase util_build_gem c installer = util_installer c, @gemhome - use_ui @ui do installer.install end + + use_ui @ui do + installer.install + end ui = Gem::MockGemUi.new @@ -92,7 +95,9 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase # Evil hack to prevent false removal success FileUtils.rm_f @executable - File.open @executable, "wb+" do |f| f.puts "binary" end + File.open @executable, "wb+" do |f| + f.puts "binary" + end @cmd.options[:executables] = true @cmd.options[:args] = [@spec.name] @@ -366,4 +371,5 @@ WARNING: Use your OS package manager to uninstall vendor gems assert_empty @ui.output assert_match %r!Error: unable to successfully uninstall '#{@spec.name}'!, @ui.error end + end diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index 549e34c218..0247a03477 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -66,7 +66,9 @@ class TestGemCommandsUpdateCommand < Gem::TestCase def test_execute_system spec_fetcher do |fetcher| - fetcher.download 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end + fetcher.download 'rubygems-update', 9 do |s| + s.files = %w[setup.rb] + end end @cmd.options[:args] = [] @@ -107,8 +109,13 @@ class TestGemCommandsUpdateCommand < Gem::TestCase def test_execute_system_multiple spec_fetcher do |fetcher| - fetcher.download 'rubygems-update', 8 do |s| s.files = %w[setup.rb] end - fetcher.download 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end + fetcher.download 'rubygems-update', 8 do |s| + s.files = %w[setup.rb] + end + + fetcher.download 'rubygems-update', 9 do |s| + s.files = %w[setup.rb] + end end @cmd.options[:args] = [] @@ -128,8 +135,13 @@ class TestGemCommandsUpdateCommand < Gem::TestCase def test_execute_system_specific spec_fetcher do |fetcher| - fetcher.download 'rubygems-update', 8 do |s| s.files = %w[setup.rb] end - fetcher.download 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end + fetcher.download 'rubygems-update', 8 do |s| + s.files = %w[setup.rb] + end + + fetcher.download 'rubygems-update', 9 do |s| + s.files = %w[setup.rb] + end end @cmd.options[:args] = [] @@ -149,8 +161,13 @@ class TestGemCommandsUpdateCommand < Gem::TestCase def test_execute_system_specifically_to_latest_version spec_fetcher do |fetcher| - fetcher.download 'rubygems-update', 8 do |s| s.files = %w[setup.rb] end - fetcher.download 'rubygems-update', 9 do |s| s.files = %w[setup.rb] end + fetcher.download 'rubygems-update', 8 do |s| + s.files = %w[setup.rb] + end + + fetcher.download 'rubygems-update', 9 do |s| + s.files = %w[setup.rb] + end end @cmd.options[:args] = [] @@ -387,7 +404,10 @@ class TestGemCommandsUpdateCommand < Gem::TestCase specs = spec_fetcher do |fetcher| fetcher.spec 'a', 1 fetcher.spec 'a', 2 - fetcher.spec 'a', 2 do |s| s.platform = platform end + + fetcher.spec 'a', 2 do |s| + s.platform = platform + end end expected = [ @@ -522,4 +542,5 @@ class TestGemCommandsUpdateCommand < Gem::TestCase assert_equal " a-2", out.shift assert_empty out end + end diff --git a/test/rubygems/test_gem_commands_yank_command.rb b/test/rubygems/test_gem_commands_yank_command.rb index d30c386aa6..666779a4ac 100644 --- a/test/rubygems/test_gem_commands_yank_command.rb +++ b/test/rubygems/test_gem_commands_yank_command.rb @@ -3,6 +3,7 @@ require 'rubygems/test_case' require 'rubygems/commands/yank_command' class TestGemCommandsYankCommand < Gem::TestCase + def setup super @@ -12,7 +13,7 @@ class TestGemCommandsYankCommand < Gem::TestCase @fetcher = Gem::RemoteFetcher.fetcher Gem.configuration.rubygems_api_key = 'key' - Gem.configuration.api_keys[:KEY] = 'other' + Gem.configuration.api_keys[:KEY] = 'other' end def test_handle_options diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index 192699aaba..858d268d79 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -489,4 +489,5 @@ if you believe they were disclosed to a third party. util_config_file assert_equal(true, @cfg.disable_default_gem_server) end + end diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index 74b7a6a83e..bf65cf9ed3 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -26,18 +26,22 @@ class TestGemDependencyInstaller < Gem::TestCase end def util_setup_gems - @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end + @a1, @a1_gem = util_gem 'a', '1' do |s| + s.executables << 'a_bin' + end + @a1_pre, @a1_pre_gem = util_gem 'a', '1.a' + @b1, @b1_gem = util_gem 'b', '1' do |s| s.add_dependency 'a' s.add_development_dependency 'aa' end - @c1, @c1_gem = util_gem 'c', '1' do |s| + @c1, @c1_gem = util_gem 'c', '1' do |s| s.add_development_dependency 'b' end - @d1, @d1_gem = util_gem 'd', '1' do |s| + @d1, @d1_gem = util_gem 'd', '1' do |s| s.add_development_dependency 'c' end @@ -872,8 +876,13 @@ class TestGemDependencyInstaller < Gem::TestCase a1_data = nil a2_o_data = nil - File.open @a1_gem, 'rb' do |fp| a1_data = fp.read end - File.open a2_o_gem, 'rb' do |fp| a2_o_data = fp.read end + File.open @a1_gem, 'rb' do |fp| + a1_data = fp.read + end + + File.open a2_o_gem, 'rb' do |fp| + a2_o_data = fp.read + end @fetcher.data["http://gems.example.com/gems/#{@a1.file_name}"] = a1_data @@ -1235,4 +1244,5 @@ class TestGemDependencyInstaller < Gem::TestCase util_clear_gems end + end diff --git a/test/rubygems/test_gem_dependency_list.rb b/test/rubygems/test_gem_dependency_list.rb index 9bd6ceb6f3..019cb33973 100644 --- a/test/rubygems/test_gem_dependency_list.rb +++ b/test/rubygems/test_gem_dependency_list.rb @@ -16,13 +16,23 @@ class TestGemDependencyList < Gem::TestCase @a2 = util_spec 'a', '2' @a3 = util_spec 'a', '3' - @b1 = util_spec 'b', '1' do |s| s.add_dependency 'a', '>= 1' end - @b2 = util_spec 'b', '2' do |s| s.add_dependency 'a', '>= 1' end + @b1 = util_spec 'b', '1' do |s| + s.add_dependency 'a', '>= 1' + end + + @b2 = util_spec 'b', '2' do |s| + s.add_dependency 'a', '>= 1' + end + + @c1 = util_spec 'c', '1' do |s| + s.add_dependency 'b', '>= 1' + end - @c1 = util_spec 'c', '1' do |s| s.add_dependency 'b', '>= 1' end @c2 = util_spec 'c', '2' - @d1 = util_spec 'd', '1' do |s| s.add_dependency 'c', '>= 1' end + @d1 = util_spec 'd', '1' do |s| + s.add_dependency 'c', '>= 1' + end end def test_active_count @@ -165,8 +175,13 @@ class TestGemDependencyList < Gem::TestCase a1 = util_spec 'a', '1' a2 = util_spec 'a', '2' - b = util_spec 'b', '1' do |s| s.add_dependency 'a', '= 1' end - c = util_spec 'c', '1' do |s| s.add_dependency 'a', '= 2' end + b = util_spec 'b', '1' do |s| + s.add_dependency 'a', '= 1' + end + + c = util_spec 'c', '1' do |s| + s.add_dependency 'a', '= 2' + end d = util_spec 'd', '1' do |s| s.add_dependency 'b' diff --git a/test/rubygems/test_gem_ext_builder.rb b/test/rubygems/test_gem_ext_builder.rb index ce04762e84..46a4385750 100644 --- a/test/rubygems/test_gem_ext_builder.rb +++ b/test/rubygems/test_gem_ext_builder.rb @@ -134,6 +134,7 @@ install: def test_build_extensions_install_ext_only class << Gem + alias orig_install_extension_in_lib install_extension_in_lib remove_method :install_extension_in_lib @@ -141,6 +142,7 @@ install: def Gem.install_extension_in_lib false end + end @spec.extensions << 'ext/extconf.rb' @@ -177,9 +179,11 @@ install: refute_path_exists File.join @spec.gem_dir, 'lib', 'a', 'b.rb' ensure class << Gem + remove_method :install_extension_in_lib alias install_extension_in_lib orig_install_extension_in_lib + end end diff --git a/test/rubygems/test_gem_ext_rake_builder.rb b/test/rubygems/test_gem_ext_rake_builder.rb index 6b647293a8..c86ff07649 100644 --- a/test/rubygems/test_gem_ext_rake_builder.rb +++ b/test/rubygems/test_gem_ext_rake_builder.rb @@ -3,6 +3,7 @@ require 'rubygems/test_case' require 'rubygems/ext' class TestGemExtRakeBuilder < Gem::TestCase + def setup super @@ -90,4 +91,5 @@ class TestGemExtRakeBuilder < Gem::TestCase EO_MKRF end end + end diff --git a/test/rubygems/test_gem_gemcutter_utilities.rb b/test/rubygems/test_gem_gemcutter_utilities.rb index 4315090a3d..03bb78271b 100644 --- a/test/rubygems/test_gem_gemcutter_utilities.rb +++ b/test/rubygems/test_gem_gemcutter_utilities.rb @@ -90,7 +90,7 @@ class TestGemGemcutterUtilities < Gem::TestCase end def test_sign_in - api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' + api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' util_sign_in [api_key, 200, 'OK'] assert_match %r{Enter your RubyGems.org credentials.}, @sign_in_ui.output @@ -102,7 +102,7 @@ class TestGemGemcutterUtilities < Gem::TestCase end def test_sign_in_with_host - api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' + api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' util_sign_in [api_key, 200, 'OK'], 'http://example.com', ['http://example.com'] @@ -116,7 +116,7 @@ class TestGemGemcutterUtilities < Gem::TestCase end def test_sign_in_with_host_nil - api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' + api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' util_sign_in [api_key, 200, 'OK'], nil, [nil] @@ -130,7 +130,7 @@ class TestGemGemcutterUtilities < Gem::TestCase end def test_sign_in_with_host_ENV - api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' + api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' util_sign_in [api_key, 200, 'OK'], 'http://example.com' assert_match "Enter your http://example.com credentials.", @@ -143,7 +143,7 @@ class TestGemGemcutterUtilities < Gem::TestCase end def test_sign_in_skips_with_existing_credentials - api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' + api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' Gem.configuration.rubygems_api_key = api_key util_sign_in [api_key, 200, 'OK'] @@ -152,8 +152,8 @@ class TestGemGemcutterUtilities < Gem::TestCase end def test_sign_in_skips_with_key_override - api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' - Gem.configuration.api_keys[:KEY] = 'other' + api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' + Gem.configuration.api_keys[:KEY] = 'other' @cmd.options[:key] = :KEY util_sign_in [api_key, 200, 'OK'] @@ -173,7 +173,7 @@ class TestGemGemcutterUtilities < Gem::TestCase assert_match %r{Enter your RubyGems.org credentials.}, @sign_in_ui.output assert_match %r{Signed in.}, @sign_in_ui.output - credentials = YAML.load_file Gem.configuration.credentials_path + credentials = YAML.load_file Gem.configuration.credentials_path assert_equal api_key, credentials[:rubygems_api_key] assert_equal other_api_key, credentials[:other_api_key] end diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb index 9f27744d48..cc83cdd81e 100644 --- a/test/rubygems/test_gem_indexer.rb +++ b/test/rubygems/test_gem_indexer.rb @@ -37,6 +37,13 @@ class TestGemIndexer < Gem::TestCase @indexer = Gem::Indexer.new(@tempdir) end + def teardown + super + + util_clear_gems + util_clear_default_gems + end + def test_initialize assert_equal @tempdir, @indexer.dest_directory assert_match %r{#{Dir.mktmpdir('gem_generate_index').match(/.*-/)}}, @indexer.directory diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index 65eaf7275f..dd6bd08dde 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -180,4 +180,5 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase assert_equal true, @cmd.options[:post_install_message] end + end diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 23c153d69b..ebf23ecfcc 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -2,6 +2,7 @@ require 'rubygems/installer_test_case' class TestGemInstaller < Gem::InstallerTestCase + @@symlink_supported = nil def symlink_supported? @@ -163,6 +164,8 @@ gem 'other', version wrapper = File.read installed_exec assert_match %r|generated by RubyGems|, wrapper + ensure + Gem::Installer.exec_format = nil end def test_check_executable_overwrite_other_gem @@ -699,7 +702,10 @@ gem 'other', version end def test_initialize - spec = util_spec 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end + spec = util_spec 'a' do |s| + s.platform = Gem::Platform.new 'mswin32' + end + gem = File.join @tempdir, spec.file_name Dir.mkdir util_inst_bindir @@ -945,7 +951,10 @@ gem 'other', version # Morph spec to have lib/other.rb instead of code.rb and recreate @spec.files = File.join('lib', 'other.rb') Dir.chdir @tempdir do - File.open File.join('lib', 'other.rb'), 'w' do |f| f.puts '1' end + File.open File.join('lib', 'other.rb'), 'w' do |f| + f.puts '1' + end + use_ui ui do FileUtils.rm @gem Gem::Package.build @spec @@ -1282,9 +1291,9 @@ gem 'other', version end # empty depend file for no auto dependencies - @spec.files += %W"depend #{@spec.name}.c".each {|file| + @spec.files += %W"depend #{@spec.name}.c".each do |file| write_file File.join(@tempdir, file) - } + end so = File.join(@spec.gem_dir, "#{@spec.name}.#{RbConfig::CONFIG["DLEXT"]}") refute_path_exists so @@ -1768,4 +1777,5 @@ gem 'other', version def mask 0100755 & (~File.umask) end + end diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index dfb6ea40d1..17e288998f 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -129,8 +129,13 @@ class TestGemPackage < Gem::Package::TarTestCase FileUtils.mkdir_p 'lib/empty' - File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end - File.open 'lib/extra.rb', 'w' do |io| io.write '# lib/extra.rb' end + File.open 'lib/code.rb', 'w' do |io| + io.write '# lib/code.rb' + end + + File.open 'lib/extra.rb', 'w' do |io| + io.write '# lib/extra.rb' + end package = Gem::Package.new 'bogus.gem' package.spec = spec @@ -157,7 +162,10 @@ class TestGemPackage < Gem::Package::TarTestCase spec.files = %w[lib/code.rb lib/code_sym.rb lib/code_sym2.rb] FileUtils.mkdir_p 'lib' - File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end + + File.open 'lib/code.rb', 'w' do |io| + io.write '# lib/code.rb' + end # NOTE: 'code.rb' is correct, because it's relative to lib/code_sym.rb begin @@ -433,7 +441,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_extract_files_empty - data_tgz = util_tar_gz do end + data_tgz = util_tar_gz { } gem = util_tar do |tar| tar.add_file 'data.tar.gz', 0644 do |io| @@ -462,7 +470,9 @@ class TestGemPackage < Gem::Package::TarTestCase package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.add_file '/absolute.rb', 0644 do |io| io.write 'hi' end + tar.add_file '/absolute.rb', 0644 do |io| + io.write 'hi' + end end e = assert_raises Gem::Package::PathError do @@ -477,7 +487,10 @@ class TestGemPackage < Gem::Package::TarTestCase package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.add_file 'relative.rb', 0644 do |io| io.write 'hi' end + tar.add_file 'relative.rb', 0644 do |io| + io.write 'hi' + end + tar.mkdir 'lib', 0755 tar.add_symlink 'lib/foo.rb', '../relative.rb', 0644 end @@ -506,7 +519,9 @@ class TestGemPackage < Gem::Package::TarTestCase tgz_io = util_tar_gz do |tar| tar.mkdir 'lib', 0755 tar.add_symlink 'lib/link', '../..', 0644 - tar.add_file 'lib/link/outside.txt', 0644 do |io| io.write 'hi' end + tar.add_file 'lib/link/outside.txt', 0644 do |io| + io.write 'hi' + end end # Extract into a subdirectory of @destination; if this test fails it writes @@ -534,7 +549,9 @@ class TestGemPackage < Gem::Package::TarTestCase tgz_io = util_tar_gz do |tar| tar.mkdir 'lib', 0755 - tar.add_file 'lib/foo.rb', 0644 do |io| io.write 'hi' end + tar.add_file 'lib/foo.rb', 0644 do |io| + io.write 'hi' + end tar.mkdir 'lib/foo', 0755 end @@ -551,7 +568,9 @@ class TestGemPackage < Gem::Package::TarTestCase package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.add_file './dot_slash.rb', 0644 do |io| io.write 'hi' end + tar.add_file './dot_slash.rb', 0644 do |io| + io.write 'hi' + end end package.extract_tar_gz tgz_io, @destination @@ -564,7 +583,9 @@ class TestGemPackage < Gem::Package::TarTestCase package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.add_file '.dot_file.rb', 0644 do |io| io.write 'hi' end + tar.add_file '.dot_file.rb', 0644 do |io| + io.write 'hi' + end end package.extract_tar_gz tgz_io, @destination @@ -578,7 +599,9 @@ class TestGemPackage < Gem::Package::TarTestCase package = Gem::Package.new @gem tgz_io = util_tar_gz do |tar| - tar.add_file 'foo/file.rb', 0644 do |io| io.write 'hi' end + tar.add_file 'foo/file.rb', 0644 do |io| + io.write 'hi' + end end package.extract_tar_gz tgz_io, @destination.upcase @@ -1043,7 +1066,9 @@ class TestGemPackage < Gem::Package::TarTestCase tgz_io = StringIO.new # can't wrap TarWriter because it seeks - Zlib::GzipWriter.wrap tgz_io do |io| io.write tar_io.string end + Zlib::GzipWriter.wrap tgz_io do |io| + io.write tar_io.string + end StringIO.new tgz_io.string end diff --git a/test/rubygems/test_gem_package_tar_reader_entry.rb b/test/rubygems/test_gem_package_tar_reader_entry.rb index ef088e32be..4627c230d9 100644 --- a/test/rubygems/test_gem_package_tar_reader_entry.rb +++ b/test/rubygems/test_gem_package_tar_reader_entry.rb @@ -43,19 +43,19 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase assert @entry.bytes_read - e = assert_raises IOError do @entry.eof? end + e = assert_raises(IOError) { @entry.eof? } assert_equal 'closed Gem::Package::TarReader::Entry', e.message - e = assert_raises IOError do @entry.getc end + e = assert_raises(IOError) { @entry.getc } assert_equal 'closed Gem::Package::TarReader::Entry', e.message - e = assert_raises IOError do @entry.pos end + e = assert_raises(IOError) { @entry.pos } assert_equal 'closed Gem::Package::TarReader::Entry', e.message - e = assert_raises IOError do @entry.read end + e = assert_raises(IOError) { @entry.read } assert_equal 'closed Gem::Package::TarReader::Entry', e.message - e = assert_raises IOError do @entry.rewind end + e = assert_raises(IOError) { @entry.rewind } assert_equal 'closed Gem::Package::TarReader::Entry', e.message end diff --git a/test/rubygems/test_gem_package_tar_writer.rb b/test/rubygems/test_gem_package_tar_writer.rb index 517320c011..6a940ed902 100644 --- a/test/rubygems/test_gem_package_tar_writer.rb +++ b/test/rubygems/test_gem_package_tar_writer.rb @@ -25,7 +25,9 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase def test_add_file Time.stub :now, Time.at(1458518157) do - @tar_writer.add_file 'x', 0644 do |f| f.write 'a' * 10 end + @tar_writer.add_file 'x', 0644 do |f| + f.write 'a' * 10 + end assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now), @io.string[0, 512]) @@ -160,7 +162,9 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase def test_add_file_simple Time.stub :now, Time.at(1458518157) do - @tar_writer.add_file_simple 'x', 0644, 10 do |io| io.write "a" * 10 end + @tar_writer.add_file_simple 'x', 0644, 10 do |io| + io.write "a" * 10 + end assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now), @io.string[0, 512]) @@ -173,7 +177,9 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase def test_add_file_simple_source_date_epoch ENV["SOURCE_DATE_EPOCH"] = "123456789" Time.stub :now, Time.at(1458518157) do - @tar_writer.add_file_simple 'x', 0644, 10 do |io| io.write "a" * 10 end + @tar_writer.add_file_simple 'x', 0644, 10 do |io| + io.write "a" * 10 + end assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc), @io.string[0, 512]) @@ -195,7 +201,7 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase @tar_writer.add_file_simple("lib/foo/bar", 0, 10) { |f| f.write @data } @tar_writer.flush - assert_equal @data + ("\0" * (512-@data.size)), + assert_equal @data + ("\0" * (512 - @data.size)), @io.string[512, 512] end @@ -295,7 +301,7 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase # note, GNU tar 1.28 is unable to handle this case too, # tested with "tar --format=ustar -cPf /tmp/foo.tartar -- /aaaaaa....a" - name = '/' + 'a' * 100 + name = '/' + 'a' * 100 exception = assert_raises Gem::Package::TooLongFileName do @tar_writer.split_name name end diff --git a/test/rubygems/test_gem_path_support.rb b/test/rubygems/test_gem_path_support.rb index 551ec28781..1f9cfe2c57 100644 --- a/test/rubygems/test_gem_path_support.rb +++ b/test/rubygems/test_gem_path_support.rb @@ -4,6 +4,7 @@ require 'rubygems' require 'fileutils' class TestGemPathSupport < Gem::TestCase + def setup super @@ -135,4 +136,5 @@ class TestGemPathSupport < Gem::TestCase assert_equal dir, ps.home assert_equal [dir, not_existing], ps.path end + end diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb index fc8b7030fb..61d1966119 100644 --- a/test/rubygems/test_gem_platform.rb +++ b/test/rubygems/test_gem_platform.rb @@ -211,13 +211,13 @@ class TestGemPlatform < Gem::TestCase assert((arm === Gem::Platform.local), 'arm === armv5') assert((armv5 === Gem::Platform.local), 'armv5 === armv5') refute((armv7 === Gem::Platform.local), 'armv7 === armv5') - refute((Gem::Platform.local === arm), 'armv5 === arm') + refute((Gem::Platform.local === arm), 'armv5 === arm') util_set_arch 'armv7-linux' assert((arm === Gem::Platform.local), 'arm === armv7') refute((armv5 === Gem::Platform.local), 'armv5 === armv7') assert((armv7 === Gem::Platform.local), 'armv7 === armv7') - refute((Gem::Platform.local === arm), 'armv7 === arm') + refute((Gem::Platform.local === arm), 'armv7 === arm') end def test_equals3_version @@ -304,4 +304,5 @@ class TestGemPlatform < Gem::TestCase def refute_local_match(name) refute_match Gem::Platform.local, name end + end diff --git a/test/rubygems/test_gem_rdoc.rb b/test/rubygems/test_gem_rdoc.rb index 073578527d..6184d4b457 100644 --- a/test/rubygems/test_gem_rdoc.rb +++ b/test/rubygems/test_gem_rdoc.rb @@ -4,8 +4,8 @@ require 'rubygems/test_case' require 'rubygems/rdoc' class TestGemRDoc < Gem::TestCase + Gem::RDoc.load_rdoc - rdoc_4 = Gem::Requirement.new('> 3').satisfied_by?(Gem::RDoc.rdoc_version) def setup super @@ -31,29 +31,8 @@ class TestGemRDoc < Gem::TestCase Gem.configuration[:rdoc] = nil end - ## - # RDoc 4 ships with its own Gem::RDoc which overrides this one which is - # shipped for backwards compatibility. - - def rdoc_4? - Gem::Requirement.new('>= 4.0.0.preview2').satisfied_by? \ - @hook.class.rdoc_version - end - - def rdoc_3? - Gem::Requirement.new('~> 3.0').satisfied_by? @hook.class.rdoc_version - end - - def rdoc_3_8_or_better? - Gem::Requirement.new('>= 3.8').satisfied_by? @hook.class.rdoc_version - end - def test_initialize - if rdoc_4? - refute @hook.generate_rdoc - else - assert @hook.generate_rdoc - end + refute @hook.generate_rdoc assert @hook.generate_ri rdoc = Gem::RDoc.new @a, false, false @@ -75,67 +54,6 @@ class TestGemRDoc < Gem::TestCase assert_empty args end - def test_document - skip 'RDoc 3 required' unless rdoc_3? - - options = RDoc::Options.new - options.files = [] - - rdoc = @hook.new_rdoc - @hook.instance_variable_set :@rdoc, rdoc - @hook.instance_variable_set :@file_info, [] - - @hook.document 'darkfish', options, @a.doc_dir('rdoc') - - assert @hook.rdoc_installed? - end unless rdoc_4 - - def test_generate - skip 'RDoc 3 required' unless rdoc_3? - - FileUtils.mkdir_p @a.doc_dir - FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') - - @hook.generate - - assert @hook.rdoc_installed? - assert @hook.ri_installed? - - rdoc = @hook.instance_variable_get :@rdoc - - refute rdoc.options.hyperlink_all - end unless rdoc_4 - - def test_generate_configuration_rdoc_array - skip 'RDoc 3 required' unless rdoc_3? - - Gem.configuration[:rdoc] = %w[-A] - - FileUtils.mkdir_p @a.doc_dir - FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') - - @hook.generate - - rdoc = @hook.instance_variable_get :@rdoc - - assert rdoc.options.hyperlink_all - end unless rdoc_4 - - def test_generate_configuration_rdoc_string - skip 'RDoc 3 required' unless rdoc_3? - - Gem.configuration[:rdoc] = '-A' - - FileUtils.mkdir_p @a.doc_dir - FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') - - @hook.generate - - rdoc = @hook.instance_variable_get :@rdoc - - assert rdoc.options.hyperlink_all - end unless rdoc_4 - def test_generate_disabled @hook.generate_rdoc = false @hook.generate_ri = false @@ -146,57 +64,6 @@ class TestGemRDoc < Gem::TestCase refute @hook.ri_installed? end - def test_generate_force - skip 'RDoc 3 required' unless rdoc_3? - - FileUtils.mkdir_p @a.doc_dir 'ri' - FileUtils.mkdir_p @a.doc_dir 'rdoc' - FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') - - @hook.force = true - - @hook.generate - - assert_path_exists File.join(@a.doc_dir('rdoc'), 'index.html') - assert_path_exists File.join(@a.doc_dir('ri'), 'cache.ri') - end unless rdoc_4 - - def test_generate_no_overwrite - skip 'RDoc 3 required' unless rdoc_3? - - FileUtils.mkdir_p @a.doc_dir 'ri' - FileUtils.mkdir_p @a.doc_dir 'rdoc' - FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') - - @hook.generate - - refute_path_exists File.join(@a.doc_dir('rdoc'), 'index.html') - refute_path_exists File.join(@a.doc_dir('ri'), 'cache.ri') - end unless rdoc_4 - - def test_generate_legacy - skip 'RDoc < 3.8 required' if rdoc_3_8_or_better? - - FileUtils.mkdir_p @a.doc_dir - FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') - - @hook.generate_legacy - - assert @hook.rdoc_installed? - assert @hook.ri_installed? - end unless rdoc_4 - - def test_legacy_rdoc - skip 'RDoc < 3.8 required' if rdoc_3_8_or_better? - - FileUtils.mkdir_p @a.doc_dir - FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') - - @hook.legacy_rdoc '--op', @a.doc_dir('rdoc') - - assert @hook.rdoc_installed? - end unless rdoc_4 - def test_new_rdoc assert_kind_of RDoc::RDoc, @hook.new_rdoc end diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index a725fe205c..a5ff929bd0 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -84,7 +84,7 @@ gems: # Generated via: # x = OpenSSL::PKey::DH.new(2048) # wait a while... # x.to_s => pem - TEST_KEY_DH2048 = OpenSSL::PKey::DH.new <<-_end_of_pem_ + TEST_KEY_DH2048 = OpenSSL::PKey::DH.new <<-_end_of_pem_ -----BEGIN DH PARAMETERS----- MIIBCAKCAQEA3Ze2EHSfYkZLUn557torAmjBgPsqzbodaRaGZtgK1gEU+9nNJaFV G1JKhmGUiEDyIW7idsBpe4sX/Wqjnp48Lr8IeI/SlEzLdoGpf05iRYXC8Cm9o8aM @@ -117,7 +117,10 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== FileUtils.mkdir @gems_dir # TODO: why does the remote fetcher need it written to disk? - @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end + @a1, @a1_gem = util_gem 'a', '1' do |s| + s.executables << 'a_bin' + end + @a1.loaded_from = File.join(@gemhome, 'specifications', @a1.full_name) Gem::RemoteFetcher.fetcher = nil @@ -786,7 +789,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== ssl_server = self.class.start_ssl_server({ :SSLVerifyClient => - OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT}) + OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT}) temp_ca_cert = File.join(DIR, 'ca_cert.pem') temp_client_cert = File.join(DIR, 'client.pem') @@ -803,7 +806,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== ssl_server = self.class.start_ssl_server({ :SSLVerifyClient => - OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT}) + OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT}) temp_ca_cert = File.join(DIR, 'ca_cert.pem') temp_client_cert = File.join(DIR, 'invalid_client.pem') @@ -895,11 +898,14 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== end class NilLog < WEBrick::Log + def log(level, data) #Do nothing end + end class << self + attr_reader :normal_server, :proxy_server attr_accessor :enable_zip, :enable_yaml @@ -959,12 +965,12 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== :SSLVerifyClient => nil, :SSLCertName => nil }.merge(config)) - server.mount_proc("/yaml") { |req, res| + server.mount_proc("/yaml") do |req, res| res.body = "--- true\n" - } - server.mount_proc("/insecure_redirect") { |req, res| + end + server.mount_proc("/insecure_redirect") do |req, res| res.set_redirect(WEBrick::HTTPStatus::MovedPermanently, req.query['to']) - } + end server.ssl_context.tmp_dh_callback = proc { TEST_KEY_DH2048 } t = Thread.new do begin @@ -999,7 +1005,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== :AccessLog => null_logger ) s.mount_proc("/kill") { |req, res| s.shutdown } - s.mount_proc("/yaml") { |req, res| + s.mount_proc("/yaml") do |req, res| if req["X-Captain"] res.body = req["X-Captain"] elsif @enable_yaml @@ -1011,8 +1017,8 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== res.body = "