summaryrefslogtreecommitdiff
path: root/spec/bundler/support/helpers.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-14 06:01:35 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-14 06:01:35 +0000
commit68ddd4d300e9a88737c4f37af74e1a0312949b2f (patch)
tree787e1e83d76934ce039eb336995a8d5bb53a89e6 /spec/bundler/support/helpers.rb
parentd636809c057432e8d42abe30c6c6785eb0721d77 (diff)
Merge Bundler 2.1.0.pre.1 as developed version from upstream.
https://github.com/bundler/bundler/commit/a53709556b95a914e874b22ed2116a46b0528852 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/bundler/support/helpers.rb')
-rw-r--r--spec/bundler/support/helpers.rb72
1 files changed, 37 insertions, 35 deletions
diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb
index 89c67c45b7..09e7419a98 100644
--- a/spec/bundler/support/helpers.rb
+++ b/spec/bundler/support/helpers.rb
@@ -41,19 +41,25 @@ module Spec
end
def out
- last_command.stdboth
+ last_command.stdout
end
def err
- last_command.stderr
+ Bundler.feature_flag.error_on_stderr? ? last_command.stderr : last_command.stdout
end
- def exitstatus
- last_command.exitstatus
+ MAJOR_DEPRECATION = /^\[DEPRECATED\]\s*/.freeze
+
+ def err_without_deprecations
+ last_command.stderr.gsub(/#{MAJOR_DEPRECATION}.+[\n]?/, "")
end
- def bundle_update_requires_all?
- Bundler::VERSION.start_with?("2.") ? nil : true
+ def deprecations
+ err.split("\n").select {|l| l =~ MAJOR_DEPRECATION }.join("\n").split(MAJOR_DEPRECATION)
+ end
+
+ def exitstatus
+ last_command.exitstatus
end
def in_app_root(&blk)
@@ -71,7 +77,7 @@ module Spec
def run(cmd, *args)
opts = args.last.is_a?(Hash) ? args.pop : {}
groups = args.map(&:inspect).join(", ")
- setup = "require 'rubygems' ; require 'bundler' ; Bundler.setup(#{groups})\n"
+ setup = "require 'bundler' ; Bundler.setup(#{groups})\n"
ruby(setup + cmd, opts)
end
bang :run
@@ -131,8 +137,6 @@ module Spec
load_path << spec
load_path_str = "-I#{load_path.join(File::PATH_SEPARATOR)}"
- env = env.map {|k, v| "#{k}='#{v}'" }.join(" ")
-
args = options.map do |k, v|
case v
when nil
@@ -146,13 +150,13 @@ module Spec
end
end.join
- cmd = "#{env} #{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}"
- sys_exec(cmd) {|i, o, thr| yield i, o, thr if block_given? }
+ 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? }
end
bang :bundle
def forgotten_command_line_options(options)
- remembered = Bundler.bundler_major_version < 3
+ remembered = Bundler::VERSION.split(".", 2).first == "2"
options = options.map do |k, v|
k = Array(k)[remembered ? 0 : -1]
v = '""' if v && v.to_s.empty?
@@ -161,9 +165,9 @@ module Spec
return Hash[options] if remembered
options.each do |k, v|
if v.nil?
- bundle! "config --delete #{k}"
+ bundle! "config unset #{k}"
else
- bundle! "config --local #{k} #{v}"
+ bundle! "config set --local #{k} #{v}"
end
end
{}
@@ -174,11 +178,6 @@ module Spec
bundle(cmd, options)
end
- def bundle_ruby(options = {})
- options["bundle_bin"] = bindir.join("bundle_ruby")
- bundle("", options)
- end
-
def ruby(ruby, options = {})
env = (options.delete(:env) || {}).map {|k, v| "#{k}='#{v}' " }.join
ruby = ruby.gsub(/["`\$]/) {|m| "\\#{m}" }
@@ -221,16 +220,18 @@ module Spec
"#{Gem.ruby} -S #{ENV["GEM_PATH"]}/bin/rake"
end
- def sys_exec(cmd)
+ def sys_exec(cmd, env = {})
command_execution = CommandExecution.new(cmd.to_s, Dir.pwd)
- Open3.popen3(cmd.to_s) do |stdin, stdout, stderr, wait_thr|
+ env = env.map {|k, v| [k.to_s, v.to_s] }.to_h # convert env keys and values to string
+
+ Open3.popen3(env, cmd.to_s) do |stdin, stdout, stderr, wait_thr|
yield stdin, stdout, wait_thr if block_given?
stdin.close
- command_execution.exitstatus = wait_thr && wait_thr.value.exitstatus
command_execution.stdout = Thread.new { stdout.read }.value.strip
command_execution.stderr = Thread.new { stderr.read }.value.strip
+ command_execution.exitstatus = wait_thr && wait_thr.value.exitstatus
end
(@command_executions ||= []) << command_execution
@@ -263,18 +264,22 @@ module Spec
end
def gemfile(*args)
- if args.empty?
+ contents = args.shift
+
+ if contents.nil?
File.open("Gemfile", "r", &:read)
else
- create_file("Gemfile", *args)
+ create_file("Gemfile", contents, *args)
end
end
def lockfile(*args)
- if args.empty?
+ contents = args.shift
+
+ if contents.nil?
File.open("Gemfile.lock", "r", &:read)
else
- create_file("Gemfile.lock", *args)
+ create_file("Gemfile.lock", normalize_uri_file(contents), *args)
end
end
@@ -323,7 +328,7 @@ module Spec
Dir.chdir(root) { gem_command! :build, gemspec.to_s }
end
bundler_path = root + "bundler-#{Bundler::VERSION}.gem"
- elsif g.to_s =~ %r{\A/.*\.gem\z}
+ elsif g.to_s =~ %r{\A(?:[A-Z]:)?/.*\.gem\z}
g
else
"#{gem_repo}/gems/#{g}.gem"
@@ -331,11 +336,8 @@ module Spec
raise "OMG `#{path}` does not exist!" unless File.exist?(path)
- if Gem::VERSION < "2.0.0"
- gem_command! :install, "--no-rdoc --no-ri --ignore-dependencies '#{path}'"
- else
- gem_command! :install, "--no-document --ignore-dependencies '#{path}'"
- end
+ gem_command! :install, "--no-document --ignore-dependencies '#{path}'"
+
bundler_path && bundler_path.rmtree
end
end
@@ -437,7 +439,7 @@ module Spec
ENV["GEM_PATH"] = system_gem_path.to_s
gems.each do |gem|
- gem_command :install, "--no-rdoc --no-ri #{gem}"
+ gem_command! :install, "--no-document #{gem}"
end
return unless block_given?
begin
@@ -577,7 +579,7 @@ module Spec
tries = 0
sleep 0.5
TCPSocket.new(host, port)
- rescue => e
+ rescue StandardError => e
raise(e) if tries > (seconds * 2)
tries += 1
retry
@@ -587,7 +589,7 @@ module Spec
port = 21_453
begin
port += 1 while TCPSocket.new("127.0.0.1", port)
- rescue
+ rescue StandardError
false
end
port