1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Merge Bundler 2.1.0.pre3 released version

This commit is contained in:
Hiroshi SHIBATA 2019-11-13 07:57:02 +09:00 committed by SHIBATA Hiroshi
parent 00d56bdf66
commit bb9ecd026a
Notes: git 2019-11-13 10:20:19 +09:00
36 changed files with 191 additions and 151 deletions

View file

@ -1,6 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative "vendored_thor" unless defined?(Thor)
require_relative "../bundler" require_relative "../bundler"
require "shellwords" require "shellwords"

View file

@ -175,7 +175,7 @@ class Bundler::Thor
handle_no_command_error(meth) unless command handle_no_command_error(meth) unless command
shell.say "Usage:" shell.say "Usage:"
shell.say " #{banner(command)}" shell.say " #{banner(command).split("\n").join("\n ")}"
shell.say shell.say
class_options_help(shell, nil => command.options.values) class_options_help(shell, nil => command.options.values)
if command.long_description if command.long_description
@ -398,7 +398,10 @@ class Bundler::Thor
# the namespace should be displayed as arguments. # the namespace should be displayed as arguments.
# #
def banner(command, namespace = nil, subcommand = false) def banner(command, namespace = nil, subcommand = false)
"#{basename} #{command.formatted_usage(self, $thor_runner, subcommand)}" $thor_runner ||= false
command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage|
"#{basename} #{formatted_usage}"
end.join("\n")
end end
def baseclass #:nodoc: def baseclass #:nodoc:

View file

@ -12,6 +12,7 @@ class Bundler::Thor
attr_accessor :behavior attr_accessor :behavior
def self.included(base) #:nodoc: def self.included(base) #:nodoc:
super(base)
base.extend ClassMethods base.extend ClassMethods
end end

View file

@ -56,7 +56,7 @@ class Bundler::Thor
attr_reader :source attr_reader :source
def initialize(base, source, destination = nil, config = {}, &block) def initialize(base, source, destination = nil, config = {}, &block)
@source = File.expand_path(base.find_in_source_paths(source.to_s)) @source = File.expand_path(Dir[Util.escape_globs(base.find_in_source_paths(source.to_s))].first)
@block = block @block = block
super(base, destination, {:recursive => true}.merge(config)) super(base, destination, {:recursive => true}.merge(config))
end end
@ -96,22 +96,12 @@ class Bundler::Thor
end end
end end
if RUBY_VERSION < "2.0" def file_level_lookup(previous_lookup)
def file_level_lookup(previous_lookup) File.join(previous_lookup, "*")
File.join(previous_lookup, "{*,.[a-z]*}") end
end
def files(lookup) def files(lookup)
Dir[lookup] Dir.glob(lookup, File::FNM_DOTMATCH)
end
else
def file_level_lookup(previous_lookup)
File.join(previous_lookup, "*")
end
def files(lookup)
Dir.glob(lookup, File::FNM_DOTMATCH)
end
end end
end end
end end

View file

@ -23,14 +23,14 @@ class Bundler::Thor
destination = args.first || source destination = args.first || source
source = File.expand_path(find_in_source_paths(source.to_s)) source = File.expand_path(find_in_source_paths(source.to_s))
create_file destination, nil, config do resulting_destination = create_file destination, nil, config do
content = File.binread(source) content = File.binread(source)
content = yield(content) if block content = yield(content) if block
content content
end end
if config[:mode] == :preserve if config[:mode] == :preserve
mode = File.stat(source).mode mode = File.stat(source).mode
chmod(destination, mode, config) chmod(resulting_destination, mode, config)
end end
end end
@ -80,14 +80,14 @@ class Bundler::Thor
config = args.last.is_a?(Hash) ? args.pop : {} config = args.last.is_a?(Hash) ? args.pop : {}
destination = args.first destination = args.first
if source =~ %r{^https?\://} render = if source =~ %r{^https?\://}
require "open-uri" require "open-uri"
URI.send(:open, source) { |input| input.binmode.read }
else else
source = File.expand_path(find_in_source_paths(source.to_s)) source = File.expand_path(find_in_source_paths(source.to_s))
open(source) { |input| input.binmode.read }
end end
render = open(source) { |input| input.binmode.read }
destination ||= if block_given? destination ||= if block_given?
block.arity == 1 ? yield(render) : yield block.arity == 1 ? yield(render) : yield
else else

View file

@ -21,9 +21,14 @@ class Bundler::Thor
# gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n") # gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n")
# end # end
# #
WARNINGS = { unchanged_no_flag: 'File unchanged! The supplied flag value not found!' }
def insert_into_file(destination, *args, &block) def insert_into_file(destination, *args, &block)
data = block_given? ? block : args.shift data = block_given? ? block : args.shift
config = args.shift
config = args.shift || {}
config[:after] = /\z/ unless config.key?(:before) || config.key?(:after)
action InjectIntoFile.new(self, destination, data, config) action InjectIntoFile.new(self, destination, data, config)
end end
alias_method :inject_into_file, :insert_into_file alias_method :inject_into_file, :insert_into_file
@ -45,8 +50,6 @@ class Bundler::Thor
end end
def invoke! def invoke!
say_status :invoke
content = if @behavior == :after content = if @behavior == :after
'\0' + replacement '\0' + replacement
else else
@ -54,7 +57,11 @@ class Bundler::Thor
end end
if exists? if exists?
replace!(/#{flag}/, content, config[:force]) if replace!(/#{flag}/, content, config[:force])
say_status(:invoke)
else
say_status(:unchanged, warning: WARNINGS[:unchanged_no_flag], color: :red)
end
else else
unless pretend? unless pretend?
raise Bundler::Thor::Error, "The file #{ destination } does not appear to exist" raise Bundler::Thor::Error, "The file #{ destination } does not appear to exist"
@ -78,7 +85,7 @@ class Bundler::Thor
protected protected
def say_status(behavior) def say_status(behavior, warning: nil, color: nil)
status = if behavior == :invoke status = if behavior == :invoke
if flag == /\A/ if flag == /\A/
:prepend :prepend
@ -87,11 +94,13 @@ class Bundler::Thor
else else
:insert :insert
end end
elsif warning
warning
else else
:subtract :subtract
end end
super(status, config[:verbose]) super(status, (color || config[:verbose]))
end end
# Adds the content to the file. # Adds the content to the file.
@ -100,8 +109,10 @@ class Bundler::Thor
return if pretend? return if pretend?
content = File.read(destination) content = File.read(destination)
if force || !content.include?(replacement) if force || !content.include?(replacement)
content.gsub!(regexp, string) success = content.gsub!(regexp, string)
File.open(destination, "wb") { |file| file.write(content) } File.open(destination, "wb") { |file| file.write(content) }
success
end end
end end
end end

View file

@ -1,6 +1,5 @@
require_relative "command" require_relative "command"
require_relative "core_ext/hash_with_indifferent_access" require_relative "core_ext/hash_with_indifferent_access"
require_relative "core_ext/ordered_hash"
require_relative "error" require_relative "error"
require_relative "invocation" require_relative "invocation"
require_relative "parser" require_relative "parser"
@ -89,6 +88,7 @@ class Bundler::Thor
class << self class << self
def included(base) #:nodoc: def included(base) #:nodoc:
super(base)
base.extend ClassMethods base.extend ClassMethods
base.send :include, Invocation base.send :include, Invocation
base.send :include, Shell base.send :include, Shell
@ -353,22 +353,22 @@ class Bundler::Thor
# Returns the commands for this Bundler::Thor class. # Returns the commands for this Bundler::Thor class.
# #
# ==== Returns # ==== Returns
# OrderedHash:: An ordered hash with commands names as keys and Bundler::Thor::Command # Hash:: An ordered hash with commands names as keys and Bundler::Thor::Command
# objects as values. # objects as values.
# #
def commands def commands
@commands ||= Bundler::Thor::CoreExt::OrderedHash.new @commands ||= Hash.new
end end
alias_method :tasks, :commands alias_method :tasks, :commands
# Returns the commands for this Bundler::Thor class and all subclasses. # Returns the commands for this Bundler::Thor class and all subclasses.
# #
# ==== Returns # ==== Returns
# OrderedHash:: An ordered hash with commands names as keys and Bundler::Thor::Command # Hash:: An ordered hash with commands names as keys and Bundler::Thor::Command
# objects as values. # objects as values.
# #
def all_commands def all_commands
@all_commands ||= from_superclass(:all_commands, Bundler::Thor::CoreExt::OrderedHash.new) @all_commands ||= from_superclass(:all_commands, Hash.new)
@all_commands.merge!(commands) @all_commands.merge!(commands)
end end
alias_method :all_tasks, :all_commands alias_method :all_tasks, :all_commands
@ -502,7 +502,7 @@ class Bundler::Thor
msg = "ERROR: \"#{basename} #{name}\" was called with ".dup msg = "ERROR: \"#{basename} #{name}\" was called with ".dup
msg << "no arguments" if args.empty? msg << "no arguments" if args.empty?
msg << "arguments " << args.inspect unless args.empty? msg << "arguments " << args.inspect unless args.empty?
msg << "\nUsage: #{banner(command).inspect}" msg << "\nUsage: \"#{banner(command).split("\n").join("\"\n \"")}\""
raise InvocationError, msg raise InvocationError, msg
end end
@ -596,6 +596,7 @@ class Bundler::Thor
# Everytime someone inherits from a Bundler::Thor class, register the klass # Everytime someone inherits from a Bundler::Thor class, register the klass
# and file into baseclass. # and file into baseclass.
def inherited(klass) def inherited(klass)
super(klass)
Bundler::Thor::Base.register_klass_file(klass) Bundler::Thor::Base.register_klass_file(klass)
klass.instance_variable_set(:@no_commands, false) klass.instance_variable_set(:@no_commands, false)
end end
@ -603,6 +604,7 @@ class Bundler::Thor
# Fire this callback whenever a method is added. Added methods are # Fire this callback whenever a method is added. Added methods are
# tracked as commands by invoking the create_command method. # tracked as commands by invoking the create_command method.
def method_added(meth) def method_added(meth)
super(meth)
meth = meth.to_s meth = meth.to_s
if meth == "initialize" if meth == "initialize"

View file

@ -49,24 +49,32 @@ class Bundler::Thor
formatted ||= "".dup formatted ||= "".dup
# Add usage with required arguments Array(usage).map do |specific_usage|
formatted << if klass && !klass.arguments.empty? formatted_specific_usage = formatted
usage.to_s.gsub(/^#{name}/) do |match|
match << " " << klass.arguments.map(&:usage).compact.join(" ")
end
else
usage.to_s
end
# Add required options formatted_specific_usage += required_arguments_for(klass, specific_usage)
formatted << " #{required_options}"
# Strip and go! # Add required options
formatted.strip formatted_specific_usage += " #{required_options}"
# Strip and go!
formatted_specific_usage.strip
end.join("\n")
end end
protected protected
# Add usage with required arguments
def required_arguments_for(klass, usage)
if klass && !klass.arguments.empty?
usage.to_s.gsub(/^#{name}/) do |match|
match << " " << klass.arguments.map(&:usage).compact.join(" ")
end
else
usage.to_s
end
end
def not_debugging?(instance) def not_debugging?(instance)
!(instance.class.respond_to?(:debugging) && instance.class.debugging) !(instance.class.respond_to?(:debugging) && instance.class.debugging)
end end
@ -97,8 +105,7 @@ class Bundler::Thor
def handle_argument_error?(instance, error, caller) def handle_argument_error?(instance, error, caller)
not_debugging?(instance) && (error.message =~ /wrong number of arguments/ || error.message =~ /given \d*, expected \d*/) && begin not_debugging?(instance) && (error.message =~ /wrong number of arguments/ || error.message =~ /given \d*, expected \d*/) && begin
saned = sans_backtrace(error.backtrace, caller) saned = sans_backtrace(error.backtrace, caller)
# Ruby 1.9 always include the called method in the backtrace saned.empty? || saned.size == 1
saned.empty? || (saned.size == 1 && RUBY_VERSION >= "1.9")
end end
end end

View file

@ -1,22 +1,18 @@
class Bundler::Thor class Bundler::Thor
Correctable = Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable)
begin # In order to support versions of Ruby that don't have keyword
require 'did_you_mean' # arguments, we need our own spell checker class that doesn't take key
# words. Even though this code wouldn't be hit because of the check
# above, it's still necessary because the interpreter would otherwise be
# unable to parse the file.
class NoKwargSpellChecker < DidYouMean::SpellChecker # :nodoc:
def initialize(dictionary)
@dictionary = dictionary
end
end
# In order to support versions of Ruby that don't have keyword DidYouMean::Correctable
# arguments, we need our own spell checker class that doesn't take key end
# words. Even though this code wouldn't be hit because of the check
# above, it's still necessary because the interpreter would otherwise be
# unable to parse the file.
class NoKwargSpellChecker < DidYouMean::SpellChecker # :nodoc:
def initialize(dictionary)
@dictionary = dictionary
end
end
DidYouMean::Correctable
rescue LoadError, NameError
end
# Bundler::Thor::Error is raised when it's caused by wrong usage of thor classes. Those # Bundler::Thor::Error is raised when it's caused by wrong usage of thor classes. Those
# errors have their backtrace suppressed and are nicely shown to the user. # errors have their backtrace suppressed and are nicely shown to the user.

View file

@ -1,6 +1,7 @@
class Bundler::Thor class Bundler::Thor
module Invocation module Invocation
def self.included(base) #:nodoc: def self.included(base) #:nodoc:
super(base)
base.extend ClassMethods base.extend ClassMethods
end end

View file

@ -24,7 +24,7 @@ class Bundler::Thor
$stdin.gets $stdin.gets
else else
# Lazy-load io/console since it is gem-ified as of 2.3 # Lazy-load io/console since it is gem-ified as of 2.3
require "io/console" if RUBY_VERSION > "1.9.2" require "io/console"
$stdin.noecho(&:gets) $stdin.noecho(&:gets)
end end
end end

View file

@ -1,19 +1,19 @@
begin
require "readline"
rescue LoadError
end
class Bundler::Thor class Bundler::Thor
module LineEditor module LineEditor
class Readline < Basic class Readline < Basic
def self.available? def self.available?
begin
require "readline"
rescue LoadError
end
Object.const_defined?(:Readline) Object.const_defined?(:Readline)
end end
def readline def readline
if echo? if echo?
::Readline.completion_append_character = nil ::Readline.completion_append_character = nil
# Ruby 1.8.7 does not allow Readline.completion_proc= to receive nil. # rb-readline does not allow Readline.completion_proc= to receive nil.
if complete = completion_proc if complete = completion_proc
::Readline.completion_proc = complete ::Readline.completion_proc = complete
end end

View file

@ -9,7 +9,7 @@ class Bundler::Thor
arguments = [] arguments = []
args.each do |item| args.each do |item|
break if item =~ /^-/ break if item.is_a?(String) && item =~ /^-/
arguments << item arguments << item
end end

View file

@ -1,17 +1,18 @@
class Bundler::Thor class Bundler::Thor
class Option < Argument #:nodoc: class Option < Argument #:nodoc:
attr_reader :aliases, :group, :lazy_default, :hide attr_reader :aliases, :group, :lazy_default, :hide, :repeatable
VALID_TYPES = [:boolean, :numeric, :hash, :array, :string] VALID_TYPES = [:boolean, :numeric, :hash, :array, :string]
def initialize(name, options = {}) def initialize(name, options = {})
@check_default_type = options[:check_default_type] @check_default_type = options[:check_default_type]
options[:required] = false unless options.key?(:required) options[:required] = false unless options.key?(:required)
@repeatable = options.fetch(:repeatable, false)
super super
@lazy_default = options[:lazy_default] @lazy_default = options[:lazy_default]
@group = options[:group].to_s.capitalize if options[:group] @group = options[:group].to_s.capitalize if options[:group]
@aliases = Array(options[:aliases]) @aliases = Array(options[:aliases])
@hide = options[:hide] @hide = options[:hide]
end end
# This parse quick options given as method_options. It makes several # This parse quick options given as method_options. It makes several
@ -128,7 +129,8 @@ class Bundler::Thor
@default.class.name.downcase.to_sym @default.class.name.downcase.to_sym
end end
raise ArgumentError, "Expected #{@type} default value for '#{switch_name}'; got #{@default.inspect} (#{default_type})" unless default_type == @type expected_type = (@repeatable && @type != :hash) ? :array : @type
raise ArgumentError, "Expected #{expected_type} default value for '#{switch_name}'; got #{@default.inspect} (#{default_type})" unless default_type == expected_type
end end
def dasherized? def dasherized?

View file

@ -97,7 +97,8 @@ class Bundler::Thor
switch = normalize_switch(switch) switch = normalize_switch(switch)
option = switch_option(switch) option = switch_option(switch)
@assigns[option.human_name] = parse_peek(switch, option) result = parse_peek(switch, option)
assign_result!(option, result)
elsif @stop_on_unknown elsif @stop_on_unknown
@parsing_options = false @parsing_options = false
@extra << shifted @extra << shifted
@ -132,6 +133,15 @@ class Bundler::Thor
protected protected
def assign_result!(option, result)
if option.repeatable && option.type == :hash
(@assigns[option.human_name] ||= {}).merge!(result)
elsif option.repeatable
(@assigns[option.human_name] ||= []) << result
else
@assigns[option.human_name] = result
end
end
# Check if the current value in peek is a registered switch. # Check if the current value in peek is a registered switch.
# #
# Two booleans are returned. The first is true if the current value # Two booleans are returned. The first is true if the current value
@ -161,7 +171,7 @@ class Bundler::Thor
end end
def switch?(arg) def switch?(arg)
switch_option(normalize_switch(arg)) !switch_option(normalize_switch(arg)).nil?
end end
def switch_option(arg) def switch_option(arg)
@ -194,7 +204,7 @@ class Bundler::Thor
shift shift
false false
else else
!no_or_skip?(switch) @switches.key?(switch) || !no_or_skip?(switch)
end end
else else
@switches.key?(switch) || !no_or_skip?(switch) @switches.key?(switch) || !no_or_skip?(switch)

View file

@ -25,6 +25,7 @@ class Bundler::Thor
end end
def self.included(base) def self.included(base)
super(base)
# Hack. Make rakefile point to invoker, so rdoc task is generated properly. # Hack. Make rakefile point to invoker, so rdoc task is generated properly.
rakefile = File.basename(caller[0].match(/(.*):\d+/)[1]) rakefile = File.basename(caller[0].match(/(.*):\d+/)[1])
Rake.application.instance_variable_set(:@rakefile, rakefile) Rake.application.instance_variable_set(:@rakefile, rakefile)

View file

@ -7,6 +7,8 @@ require "digest/md5"
require "pathname" require "pathname"
class Bundler::Thor::Runner < Bundler::Thor #:nodoc: # rubocop:disable ClassLength class Bundler::Thor::Runner < Bundler::Thor #:nodoc: # rubocop:disable ClassLength
autoload :OpenURI, "open-uri"
map "-T" => :list, "-i" => :install, "-u" => :update, "-v" => :version map "-T" => :list, "-i" => :install, "-u" => :update, "-v" => :version
def self.banner(command, all = false, subcommand = false) def self.banner(command, all = false, subcommand = false)

View file

@ -97,7 +97,11 @@ class Bundler::Thor
protected protected
def can_display_colors? def can_display_colors?
stdout.tty? stdout.tty? && !are_colors_disabled?
end
def are_colors_disabled?
!ENV['NO_COLOR'].nil?
end end
# Overwrite show_diff to show diff with colors if Diff::LCS is # Overwrite show_diff to show diff with colors if Diff::LCS is

View file

@ -141,38 +141,61 @@ RSpec.describe "bundle binstubs <gem>" do
end end
context "when a lockfile exists with a locked bundler version" do context "when a lockfile exists with a locked bundler version" do
it "runs the correct version of bundler when the version is newer" do context "and the version is newer" do
lockfile lockfile.gsub(system_bundler_version, "999.999.999") before do
sys_exec "#{bundled_app("bin/bundle")} install" lockfile lockfile.gsub(system_bundler_version, "999.999")
expect(exitstatus).to eq(42) if exitstatus end
expect(err).to include("Activating bundler (~> 999.999) failed:").
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") it "runs the correct version of bundler" do
sys_exec "#{bundled_app("bin/bundle")} install"
expect(exitstatus).to eq(42) if exitstatus
expect(err).to include("Activating bundler (~> 999.999) failed:").
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`")
end
end end
it "runs the correct version of bundler when the version is older and a different major" do context "and the version is older and a different major" do
simulate_bundler_version "55" let(:system_bundler_version) { "55" }
lockfile lockfile.gsub(system_bundler_version, "44.0")
sys_exec "#{bundled_app("bin/bundle")} install" before do
expect(exitstatus).to eq(42) if exitstatus lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 44.0")
expect(err).to include("Activating bundler (~> 44.0) failed:"). end
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 44.0'`")
it "runs the correct version of bundler" do
sys_exec "#{bundled_app("bin/bundle")} install"
expect(exitstatus).to eq(42) if exitstatus
expect(err).to include("Activating bundler (~> 44.0) failed:").
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 44.0'`")
end
end end
it "runs the available version of bundler when the version is older and the same major" do context "and the version is older and the same major" do
simulate_bundler_version "55.1" let(:system_bundler_version) { "55.1" }
lockfile lockfile.gsub(system_bundler_version, "55.0")
sys_exec "#{bundled_app("bin/bundle")} install" before do
expect(exitstatus).not_to eq(42) if exitstatus lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 55.0")
expect(err).not_to include("Activating bundler (~> 55.0) failed:") end
it "runs the available version of bundler when the version is older and the same major" do
sys_exec "#{bundled_app("bin/bundle")} install"
expect(exitstatus).not_to eq(42) if exitstatus
expect(err).not_to include("Activating bundler (~> 55.0) failed:")
end
end end
it "runs the correct version of bundler when the version is a pre-release" do context "and the version is a pre-releaser" do
simulate_bundler_version "55" let(:system_bundler_version) { "55" }
lockfile lockfile.gsub(system_bundler_version, "2.12.0.a")
sys_exec "#{bundled_app("bin/bundle")} install" before do
expect(exitstatus).to eq(42) if exitstatus lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 2.12.0.a")
expect(err).to include("Activating bundler (~> 2.12.a) failed:"). end
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 2.12.a'`")
it "runs the correct version of bundler when the version is a pre-release" do
sys_exec "#{bundled_app("bin/bundle")} install"
expect(exitstatus).to eq(42) if exitstatus
expect(err).to include("Activating bundler (~> 2.12.a) failed:").
and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 2.12.a'`")
end
end end
end end

View file

@ -7,7 +7,6 @@ RSpec.describe "bundle install" do
it "overrides Gem.bindir" do it "overrides Gem.bindir" do
expect(Pathname.new("/usr/bin")).not_to be_writable unless Process.euid == 0 expect(Pathname.new("/usr/bin")).not_to be_writable unless Process.euid == 0
gemfile <<-G gemfile <<-G
require 'rubygems'
def Gem.bindir; "/usr/bin"; end def Gem.bindir; "/usr/bin"; end
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
gem "rack" gem "rack"

View file

@ -1056,7 +1056,6 @@ RSpec.describe "bundle install with git sources" do
File.open(lib_path("install_hooks.rb"), "w") do |h| File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H h.write <<-H
require '#{spec_dir}/support/rubygems'
Gem.pre_install_hooks << lambda do |inst| Gem.pre_install_hooks << lambda do |inst|
STDERR.puts "Ran pre-install hook: \#{inst.spec.full_name}" STDERR.puts "Ran pre-install hook: \#{inst.spec.full_name}"
end end
@ -1076,7 +1075,6 @@ RSpec.describe "bundle install with git sources" do
File.open(lib_path("install_hooks.rb"), "w") do |h| File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H h.write <<-H
require '#{spec_dir}/support/rubygems'
Gem.post_install_hooks << lambda do |inst| Gem.post_install_hooks << lambda do |inst|
STDERR.puts "Ran post-install hook: \#{inst.spec.full_name}" STDERR.puts "Ran post-install hook: \#{inst.spec.full_name}"
end end
@ -1096,7 +1094,6 @@ RSpec.describe "bundle install with git sources" do
File.open(lib_path("install_hooks.rb"), "w") do |h| File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H h.write <<-H
require '#{spec_dir}/support/rubygems'
Gem.pre_install_hooks << lambda do |inst| Gem.pre_install_hooks << lambda do |inst|
false false
end end

View file

@ -672,7 +672,6 @@ RSpec.describe "bundle install with explicit source paths" do
File.open(lib_path("install_hooks.rb"), "w") do |h| File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H h.write <<-H
require '#{spec_dir}/support/rubygems'
Gem.pre_install_hooks << lambda do |inst| Gem.pre_install_hooks << lambda do |inst|
STDERR.puts "Ran pre-install hook: \#{inst.spec.full_name}" STDERR.puts "Ran pre-install hook: \#{inst.spec.full_name}"
end end
@ -692,7 +691,6 @@ RSpec.describe "bundle install with explicit source paths" do
File.open(lib_path("install_hooks.rb"), "w") do |h| File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H h.write <<-H
require '#{spec_dir}/support/rubygems'
Gem.post_install_hooks << lambda do |inst| Gem.post_install_hooks << lambda do |inst|
STDERR.puts "Ran post-install hook: \#{inst.spec.full_name}" STDERR.puts "Ran post-install hook: \#{inst.spec.full_name}"
end end
@ -712,7 +710,6 @@ RSpec.describe "bundle install with explicit source paths" do
File.open(lib_path("install_hooks.rb"), "w") do |h| File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H h.write <<-H
require '#{spec_dir}/support/rubygems'
Gem.pre_install_hooks << lambda do |inst| Gem.pre_install_hooks << lambda do |inst|
false false
end end

View file

@ -1418,7 +1418,6 @@ RSpec.describe "the lockfile format" do
it "preserves Gemfile.lock \\n line endings" do it "preserves Gemfile.lock \\n line endings" do
expect do expect do
ruby <<-RUBY ruby <<-RUBY
require 'rubygems'
require 'bundler' require 'bundler'
Bundler.setup Bundler.setup
RUBY RUBY
@ -1432,7 +1431,6 @@ RSpec.describe "the lockfile format" do
expect do expect do
ruby <<-RUBY ruby <<-RUBY
require 'rubygems'
require 'bundler' require 'bundler'
Bundler.setup Bundler.setup
RUBY RUBY

View file

@ -356,9 +356,7 @@ RSpec.describe "major deprecations" do
G G
ruby <<-RUBY ruby <<-RUBY
require 'rubygems' require '#{lib_dir}/bundler'
require 'bundler'
require 'bundler/vendored_thor'
Bundler.setup Bundler.setup
Bundler.setup Bundler.setup

View file

@ -1086,7 +1086,6 @@ G
FileUtils.rm(bundled_app("Gemfile.lock")) FileUtils.rm(bundled_app("Gemfile.lock"))
ruby <<-R ruby <<-R
require 'rubygems'
require 'bundler/setup' require 'bundler/setup'
R R
@ -1106,7 +1105,6 @@ G
FileUtils.rm(bundled_app("Gemfile.lock")) FileUtils.rm(bundled_app("Gemfile.lock"))
ruby <<-R ruby <<-R
require 'rubygems'
require 'bundler/setup' require 'bundler/setup'
R R
@ -1127,7 +1125,6 @@ G
FileUtils.rm(bundled_app("Gemfile.lock")) FileUtils.rm(bundled_app("Gemfile.lock"))
ruby <<-R ruby <<-R
require 'rubygems'
require 'bundler/setup' require 'bundler/setup'
R R
@ -1148,7 +1145,6 @@ G
FileUtils.rm(bundled_app("Gemfile.lock")) FileUtils.rm(bundled_app("Gemfile.lock"))
ruby <<-R ruby <<-R
require 'rubygems'
require 'bundler/setup' require 'bundler/setup'
R R

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
require_relative "../support/rubygems_version_manager"
RubygemsVersionManager.new(ENV["RGV"]).switch
$:.delete("#{Spec::Path.spec_dir}/rubygems")
require "rubygems"

View file

@ -115,7 +115,7 @@ RSpec.describe "bundler/inline#gemfile" do
it "has an option for quiet installation" do it "has an option for quiet installation" do
script <<-RUBY, :artifice => "endpoint" script <<-RUBY, :artifice => "endpoint"
require 'bundler' require '#{lib_dir}/bundler/inline'
gemfile(true, :quiet => true) do gemfile(true, :quiet => true) do
source "https://notaserver.com" source "https://notaserver.com"

View file

@ -985,9 +985,7 @@ end
build_git "bar", :gemspec => false do |s| build_git "bar", :gemspec => false do |s|
s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0') s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0')
s.write "bar.gemspec", <<-G s.write "bar.gemspec", <<-G
lib = File.expand_path('../lib/', __FILE__) require_relative 'lib/bar/version'
$:.unshift lib unless $:.include?(lib)
require 'bar/version'
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = 'bar' s.name = 'bar'

View file

@ -82,7 +82,7 @@ RSpec.configure do |config|
config.before :suite do config.before :suite do
require_relative "support/rubygems_ext" require_relative "support/rubygems_ext"
Spec::Rubygems.setup Spec::Rubygems.setup
ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb" ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{Spec::Path.spec_dir}/rubygems -r#{Spec::Path.spec_dir}/support/hax.rb"
ENV["BUNDLE_SPEC_RUN"] = "true" ENV["BUNDLE_SPEC_RUN"] = "true"
ENV["BUNDLE_USER_CONFIG"] = ENV["BUNDLE_USER_CACHE"] = ENV["BUNDLE_USER_PLUGIN"] = nil ENV["BUNDLE_USER_CONFIG"] = ENV["BUNDLE_USER_CACHE"] = ENV["BUNDLE_USER_PLUGIN"] = nil
ENV["GEMRC"] = nil ENV["GEMRC"] = nil

View file

@ -28,7 +28,8 @@ module Gem
end end
if ENV["BUNDLER_SPEC_VERSION"] if ENV["BUNDLER_SPEC_VERSION"]
require "bundler/version" require_relative "path"
require "#{Spec::Path.lib_dir}/bundler/version"
module Bundler module Bundler
remove_const(:VERSION) if const_defined?(:VERSION) remove_const(:VERSION) if const_defined?(:VERSION)
@ -37,7 +38,8 @@ if ENV["BUNDLER_SPEC_VERSION"]
end end
if ENV["BUNDLER_SPEC_WINDOWS"] == "true" if ENV["BUNDLER_SPEC_WINDOWS"] == "true"
require "bundler/constants" require_relative "path"
require "#{Spec::Path.lib_dir}/bundler/constants"
module Bundler module Bundler
remove_const :WINDOWS if defined?(WINDOWS) remove_const :WINDOWS if defined?(WINDOWS)

View file

@ -110,7 +110,6 @@ module Spec
env["PATH"].gsub!("#{Path.root}/exe", "") if env["PATH"] && system_bundler env["PATH"].gsub!("#{Path.root}/exe", "") if env["PATH"] && system_bundler
requires = options.delete(:requires) || [] requires = options.delete(:requires) || []
requires << "support/rubygems"
requires << "support/hax" requires << "support/hax"
artifice = options.delete(:artifice) do artifice = options.delete(:artifice) do
@ -144,7 +143,7 @@ module Spec
end end
end.join end.join
cmd = "#{sudo} #{Gem.ruby} --disable-gems #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}"
sys_exec(cmd, env) {|i, o, thr| yield i, o, thr if block_given? } sys_exec(cmd, env) {|i, o, thr| yield i, o, thr if block_given? }
end end
bang :bundle bang :bundle

View file

@ -128,9 +128,10 @@ module Spec
groups << opts groups << opts
@errors = names.map do |name| @errors = names.map do |name|
name, version, platform = name.split(/\s+/) name, version, platform = name.split(/\s+/)
require_path = name == "bundler" ? "#{lib_dir}/bundler" : name
version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name) version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name)
begin begin
run! "require '#{name}.rb'; puts #{version_const}", *groups run! "require '#{require_path}.rb'; puts #{version_const}", *groups
rescue StandardError => e rescue StandardError => e
next "#{name} is not installed:\n#{indent(e)}" next "#{name} is not installed:\n#{indent(e)}"
end end

View file

@ -22,7 +22,7 @@ module Spec
end end
def gem_bin def gem_bin
@gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} --disable-gems -r#{spec_dir}/support/rubygems -S gem --backtrace" @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} -I#{spec_dir}/rubygems -S gem --backtrace"
end end
def spec_dir def spec_dir

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
require_relative "rubygems_version_manager"
RubygemsVersionManager.new(ENV["RGV"]).switch
require "rubygems"

View file

@ -1,7 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative "path" require_relative "path"
require "fileutils"
module Spec module Spec
module Rubygems module Rubygems
@ -40,7 +39,7 @@ module Spec
end end
def gem_load(gem_name, bin_container) def gem_load(gem_name, bin_container)
require_relative "rubygems" require_relative "../rubygems/rubygems"
gem_load_and_activate(gem_name, bin_container) gem_load_and_activate(gem_name, bin_container)
end end
@ -50,6 +49,8 @@ module Spec
end end
def setup def setup
require "fileutils"
Gem.clear_paths Gem.clear_paths
ENV["BUNDLE_PATH"] = nil ENV["BUNDLE_PATH"] = nil

View file

@ -56,7 +56,7 @@ private
end end
def rubygems_unrequire_needed? def rubygems_unrequire_needed?
defined?(Gem) && Gem::VERSION != target_gem_version defined?(Gem::VERSION) && Gem::VERSION != target_gem_version
end end
def local_copy_switch_needed? def local_copy_switch_needed?