diff options
33 files changed, 176 insertions, 160 deletions
diff --git a/.azure-pipelines/patch_readline.sh b/.azure-pipelines/patch_readline.sh new file mode 100644 index 0000000000..69bf661a1b --- /dev/null +++ b/.azure-pipelines/patch_readline.sh @@ -0,0 +1,3 @@ +ruby_version=$(ruby -e 'puts RUBY_VERSION') + +git apply --ignore-space-change --ignore-whitespace '.azure-pipelines\rbreadline.diff' --directory="C:/hostedtoolcache/windows/Ruby/$ruby_version/x64/lib/ruby/site_ruby" --unsafe-paths diff --git a/.azure-pipelines/steps.yml b/.azure-pipelines/steps.yml index bb989ac70c..d23c52b584 100644 --- a/.azure-pipelines/steps.yml +++ b/.azure-pipelines/steps.yml @@ -16,7 +16,7 @@ steps: displayName: 'work around readline crash (for https://github.com/bundler/bundler/issues/6902)' - script: | - git apply --ignore-space-change --ignore-whitespace .azure-pipelines\rbreadline.diff --directory=C:/hostedtoolcache/windows/Ruby/2.4.3/x64/lib/ruby/site_ruby --unsafe-paths + bash .azure-pipelines\patch_readline.sh displayName: 'patch local readline implementation (for https://github.com/bundler/bundler/issues/6907)' - script: | diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000000..be53aae226 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: https://rubytogether.org @@ -2,3 +2,4 @@ --color --warnings --require spec_helper +--order random diff --git a/LICENSE.md b/LICENSE.md index e356f59f94..52b5c2132f 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,23 +1,22 @@ -Portions copyright (c) 2010 Andre Arko -Portions copyright (c) 2009 Engine Yard +The MIT License -MIT License +Portions copyright (c) 2010-2019 André Arko +Portions copyright (c) 2009 Engine Yard -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. @@ -97,17 +97,12 @@ namespace :spec do end desc "Run the spec suite with the sudo tests" - task :sudo => %w[set_sudo spec clean_sudo] + task :sudo => %w[set_sudo spec] task :set_sudo do ENV["BUNDLER_SUDO_TESTS"] = "1" end - task :clean_sudo do - puts "Cleaning up sudo test files..." - system "sudo rm -rf #{File.expand_path("../tmp/sudo_gem_home", __FILE__)}" - end - # RubyGems specs by version namespace :rubygems do # When editing this list, also edit .travis.yml! @@ -121,7 +116,7 @@ namespace :spec do # Create tasks like spec:rubygems:v1.8.3:sudo to run the sudo specs namespace rg do - task :sudo => ["set_sudo", rg, "clean_sudo"] + task :sudo => ["set_sudo", rg] task :realworld => ["set_realworld", rg] end @@ -139,7 +134,7 @@ namespace :spec do end namespace "co" do - task :sudo => ["set_sudo", "co", "clean_sudo"] + task :sudo => ["set_sudo", "co"] task :realworld => ["set_realworld", "co"] end @@ -247,6 +242,7 @@ namespace :man do end task :build_all_pages => "index.txt" + desc "Remove all built man pages" task :clean do leftovers = Dir["man/*"].reject do |f| File.extname(f) == ".ronn" @@ -256,11 +252,6 @@ namespace :man do desc "Build the man pages" task :build => ["man:clean", "man:build_all_pages"] - - desc "Remove all built man pages" - task :clobber do - rm_rf "lib/bundler/man" - end end end end diff --git a/exe/bundle b/exe/bundle index aaf773745d..fccece038b 100755 --- a/exe/bundle +++ b/exe/bundle @@ -7,7 +7,7 @@ Signal.trap("INT") do exit 1 end -require "bundler" +require_relative "../lib/bundler" # Check if an older version of bundler is installed $LOAD_PATH.each do |path| next unless path =~ %r{/bundler-0\.(\d+)} && $1.to_i < 9 @@ -18,9 +18,9 @@ $LOAD_PATH.each do |path| abort(err) end -require "bundler/friendly_errors" +require_relative "../lib/bundler/friendly_errors" Bundler.with_friendly_errors do - require "bundler/cli" + require_relative "../lib/bundler/cli" # Allow any command to use --help flag to show help for that command help_flags = %w[--help -h] diff --git a/lib/bundler.rb b/lib/bundler.rb index d8f9462c6d..735750f59d 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -564,7 +564,7 @@ EOF private def eval_yaml_gemspec(path, contents) - Kernel.send(:require, "bundler/psyched_yaml") + require_relative "bundler/psyched_yaml" # If the YAML is invalid, Syck raises an ArgumentError, and Psych # raises a Psych::SyntaxError. See psyched_yaml.rb for more info. diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 0d588bc892..55ffea02b6 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -19,6 +19,7 @@ module Bundler :ruby_23 => Gem::Platform::RUBY, :ruby_24 => Gem::Platform::RUBY, :ruby_25 => Gem::Platform::RUBY, + :ruby_26 => Gem::Platform::RUBY, :mri => Gem::Platform::RUBY, :mri_18 => Gem::Platform::RUBY, :mri_19 => Gem::Platform::RUBY, @@ -28,6 +29,7 @@ module Bundler :mri_23 => Gem::Platform::RUBY, :mri_24 => Gem::Platform::RUBY, :mri_25 => Gem::Platform::RUBY, + :mri_26 => Gem::Platform::RUBY, :rbx => Gem::Platform::RUBY, :truffleruby => Gem::Platform::RUBY, :jruby => Gem::Platform::JAVA, @@ -42,6 +44,7 @@ module Bundler :mswin_23 => Gem::Platform::MSWIN, :mswin_24 => Gem::Platform::MSWIN, :mswin_25 => Gem::Platform::MSWIN, + :mswin_26 => Gem::Platform::MSWIN, :mswin64 => Gem::Platform::MSWIN64, :mswin64_19 => Gem::Platform::MSWIN64, :mswin64_20 => Gem::Platform::MSWIN64, @@ -50,6 +53,7 @@ module Bundler :mswin64_23 => Gem::Platform::MSWIN64, :mswin64_24 => Gem::Platform::MSWIN64, :mswin64_25 => Gem::Platform::MSWIN64, + :mswin64_26 => Gem::Platform::MSWIN64, :mingw => Gem::Platform::MINGW, :mingw_18 => Gem::Platform::MINGW, :mingw_19 => Gem::Platform::MINGW, @@ -59,6 +63,7 @@ module Bundler :mingw_23 => Gem::Platform::MINGW, :mingw_24 => Gem::Platform::MINGW, :mingw_25 => Gem::Platform::MINGW, + :mingw_26 => Gem::Platform::MINGW, :x64_mingw => Gem::Platform::X64_MINGW, :x64_mingw_20 => Gem::Platform::X64_MINGW, :x64_mingw_21 => Gem::Platform::X64_MINGW, @@ -66,6 +71,7 @@ module Bundler :x64_mingw_23 => Gem::Platform::X64_MINGW, :x64_mingw_24 => Gem::Platform::X64_MINGW, :x64_mingw_25 => Gem::Platform::X64_MINGW, + :x64_mingw_26 => Gem::Platform::X64_MINGW, }.freeze REVERSE_PLATFORM_MAP = {}.tap do |reverse_platform_map| diff --git a/lib/bundler/vendor/thor/lib/thor.rb b/lib/bundler/vendor/thor/lib/thor.rb index 999e8b7e61..6017ee9ad8 100644 --- a/lib/bundler/vendor/thor/lib/thor.rb +++ b/lib/bundler/vendor/thor/lib/thor.rb @@ -1,5 +1,5 @@ require "set" -require "bundler/vendor/thor/lib/thor/base" +require_relative "thor/base" class Bundler::Thor class << self diff --git a/lib/bundler/vendor/thor/lib/thor/actions.rb b/lib/bundler/vendor/thor/lib/thor/actions.rb index b06feac2a0..5681d5a7c6 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions.rb @@ -1,11 +1,11 @@ require "uri" -require "bundler/vendor/thor/lib/thor/core_ext/io_binary_read" -require "bundler/vendor/thor/lib/thor/actions/create_file" -require "bundler/vendor/thor/lib/thor/actions/create_link" -require "bundler/vendor/thor/lib/thor/actions/directory" -require "bundler/vendor/thor/lib/thor/actions/empty_directory" -require "bundler/vendor/thor/lib/thor/actions/file_manipulation" -require "bundler/vendor/thor/lib/thor/actions/inject_into_file" +require_relative "core_ext/io_binary_read" +require_relative "actions/create_file" +require_relative "actions/create_link" +require_relative "actions/directory" +require_relative "actions/empty_directory" +require_relative "actions/file_manipulation" +require_relative "actions/inject_into_file" class Bundler::Thor module Actions diff --git a/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb b/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb index 97d22d9bbd..330fc08cae 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb @@ -1,4 +1,4 @@ -require "bundler/vendor/thor/lib/thor/actions/empty_directory" +require_relative "empty_directory" class Bundler::Thor module Actions diff --git a/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb b/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb index 3a664401b4..70504a2c1f 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb @@ -1,4 +1,4 @@ -require "bundler/vendor/thor/lib/thor/actions/create_file" +require_relative "create_file" class Bundler::Thor module Actions diff --git a/lib/bundler/vendor/thor/lib/thor/actions/directory.rb b/lib/bundler/vendor/thor/lib/thor/actions/directory.rb index f555f7b7e0..03c97bf630 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/directory.rb @@ -1,4 +1,4 @@ -require "bundler/vendor/thor/lib/thor/actions/empty_directory" +require_relative "empty_directory" class Bundler::Thor module Actions diff --git a/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb b/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb index 349b26ff65..cf651a4e78 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb @@ -1,4 +1,4 @@ -require "bundler/vendor/thor/lib/thor/actions/empty_directory" +require_relative "empty_directory" class Bundler::Thor module Actions diff --git a/lib/bundler/vendor/thor/lib/thor/base.rb b/lib/bundler/vendor/thor/lib/thor/base.rb index f55b14fbfc..7d7cd3b5fe 100644 --- a/lib/bundler/vendor/thor/lib/thor/base.rb +++ b/lib/bundler/vendor/thor/lib/thor/base.rb @@ -1,12 +1,12 @@ -require "bundler/vendor/thor/lib/thor/command" -require "bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access" -require "bundler/vendor/thor/lib/thor/core_ext/ordered_hash" -require "bundler/vendor/thor/lib/thor/error" -require "bundler/vendor/thor/lib/thor/invocation" -require "bundler/vendor/thor/lib/thor/parser" -require "bundler/vendor/thor/lib/thor/shell" -require "bundler/vendor/thor/lib/thor/line_editor" -require "bundler/vendor/thor/lib/thor/util" +require_relative "command" +require_relative "core_ext/hash_with_indifferent_access" +require_relative "core_ext/ordered_hash" +require_relative "error" +require_relative "invocation" +require_relative "parser" +require_relative "shell" +require_relative "line_editor" +require_relative "util" class Bundler::Thor autoload :Actions, File.expand_path("actions", __dir__) diff --git a/lib/bundler/vendor/thor/lib/thor/group.rb b/lib/bundler/vendor/thor/lib/thor/group.rb index 30db46529e..7861d05345 100644 --- a/lib/bundler/vendor/thor/lib/thor/group.rb +++ b/lib/bundler/vendor/thor/lib/thor/group.rb @@ -1,4 +1,4 @@ -require "bundler/vendor/thor/lib/thor/base" +require_relative "base" # Bundler::Thor has a special class called Bundler::Thor::Group. The main difference to Bundler::Thor class # is that it invokes all commands at once. It also include some methods that allows diff --git a/lib/bundler/vendor/thor/lib/thor/line_editor.rb b/lib/bundler/vendor/thor/lib/thor/line_editor.rb index ce81a17484..5c0c336e7a 100644 --- a/lib/bundler/vendor/thor/lib/thor/line_editor.rb +++ b/lib/bundler/vendor/thor/lib/thor/line_editor.rb @@ -1,5 +1,5 @@ -require "bundler/vendor/thor/lib/thor/line_editor/basic" -require "bundler/vendor/thor/lib/thor/line_editor/readline" +require_relative "line_editor/basic" +require_relative "line_editor/readline" class Bundler::Thor module LineEditor diff --git a/lib/bundler/vendor/thor/lib/thor/parser.rb b/lib/bundler/vendor/thor/lib/thor/parser.rb index 08f80e565d..45394732ca 100644 --- a/lib/bundler/vendor/thor/lib/thor/parser.rb +++ b/lib/bundler/vendor/thor/lib/thor/parser.rb @@ -1,4 +1,4 @@ -require "bundler/vendor/thor/lib/thor/parser/argument" -require "bundler/vendor/thor/lib/thor/parser/arguments" -require "bundler/vendor/thor/lib/thor/parser/option" -require "bundler/vendor/thor/lib/thor/parser/options" +require_relative "parser/argument" +require_relative "parser/arguments" +require_relative "parser/option" +require_relative "parser/options" diff --git a/lib/bundler/vendor/thor/lib/thor/runner.rb b/lib/bundler/vendor/thor/lib/thor/runner.rb index 65ae422d7f..ed44853a00 100644 --- a/lib/bundler/vendor/thor/lib/thor/runner.rb +++ b/lib/bundler/vendor/thor/lib/thor/runner.rb @@ -1,6 +1,6 @@ -require "bundler/vendor/thor/lib/thor" -require "bundler/vendor/thor/lib/thor/group" -require "bundler/vendor/thor/lib/thor/core_ext/io_binary_read" +require_relative "../thor" +require_relative "group" +require_relative "core_ext/io_binary_read" require "yaml" require "digest/md5" @@ -111,7 +111,7 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: # rubocop:disable ClassLeng desc "version", "Show Bundler::Thor version" def version - require "bundler/vendor/thor/lib/thor/version" + require_relative "version" say "Bundler::Thor #{Bundler::Thor::VERSION}" end diff --git a/lib/bundler/vendor/thor/lib/thor/shell/color.rb b/lib/bundler/vendor/thor/lib/thor/shell/color.rb index da289cb50c..6c821d4a09 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell/color.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell/color.rb @@ -1,4 +1,4 @@ -require "bundler/vendor/thor/lib/thor/shell/basic" +require_relative "basic" class Bundler::Thor module Shell diff --git a/lib/bundler/vendor/thor/lib/thor/shell/html.rb b/lib/bundler/vendor/thor/lib/thor/shell/html.rb index 83d2054988..55262f19cc 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell/html.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell/html.rb @@ -1,4 +1,4 @@ -require "bundler/vendor/thor/lib/thor/shell/basic" +require_relative "basic" class Bundler::Thor module Shell diff --git a/lib/bundler/vendored_thor.rb b/lib/bundler/vendored_thor.rb index b0b7e7be84..0666cfc9b9 100644 --- a/lib/bundler/vendored_thor.rb +++ b/lib/bundler/vendored_thor.rb @@ -2,7 +2,7 @@ module Bundler def self.require_thor_actions - Kernel.send(:require, "bundler/vendor/thor/lib/thor/actions") + require_relative "vendor/thor/lib/thor/actions" end end require_relative "vendor/thor/lib/thor" diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 9b772bffef..f74c1780bd 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -370,54 +370,51 @@ EOF it { should be true } end end - end - describe "#requires_sudo?" do - before do - allow(Bundler).to receive(:which).with("sudo").and_return("/usr/bin/sudo") - FileUtils.mkdir_p("tmp/vendor/bundle") - FileUtils.mkdir_p("tmp/vendor/bin_dir") - end - after do - FileUtils.rm_rf("tmp/vendor/bundle") - FileUtils.rm_rf("tmp/vendor/bin_dir") - Bundler.remove_instance_variable(:@requires_sudo_ran) - Bundler.remove_instance_variable(:@requires_sudo) - end - context "writable paths" do - it "should return false and display nothing" do - allow(Bundler).to receive(:bundle_path).and_return(Pathname("tmp/vendor/bundle")) - expect(Bundler.ui).to_not receive(:warn) - expect(Bundler.requires_sudo?).to eq(false) - end - end - context "unwritable paths" do + context "path writability" do before do - FileUtils.touch("tmp/vendor/bundle/unwritable1.txt") - FileUtils.touch("tmp/vendor/bundle/unwritable2.txt") - FileUtils.touch("tmp/vendor/bin_dir/unwritable3.txt") - FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable1.txt") - FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable2.txt") - FileUtils.chmod(0o400, "tmp/vendor/bin_dir/unwritable3.txt") + FileUtils.mkdir_p("tmp/vendor/bundle") + FileUtils.mkdir_p("tmp/vendor/bin_dir") + end + after do + FileUtils.rm_rf("tmp/vendor/bundle") + FileUtils.rm_rf("tmp/vendor/bin_dir") end - it "should return true and display warn message" do - allow(Bundler).to receive(:bundle_path).and_return(Pathname("tmp/vendor/bundle")) - bin_dir = Pathname("tmp/vendor/bin_dir/") + context "writable paths" do + it "should return false and display nothing" do + allow(Bundler).to receive(:bundle_path).and_return(Pathname("tmp/vendor/bundle")) + expect(Bundler.ui).to_not receive(:warn) + expect(Bundler.requires_sudo?).to eq(false) + end + end + context "unwritable paths" do + before do + FileUtils.touch("tmp/vendor/bundle/unwritable1.txt") + FileUtils.touch("tmp/vendor/bundle/unwritable2.txt") + FileUtils.touch("tmp/vendor/bin_dir/unwritable3.txt") + FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable1.txt") + FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable2.txt") + FileUtils.chmod(0o400, "tmp/vendor/bin_dir/unwritable3.txt") + end + it "should return true and display warn message" do + allow(Bundler).to receive(:bundle_path).and_return(Pathname("tmp/vendor/bundle")) + bin_dir = Pathname("tmp/vendor/bin_dir/") - # allow File#writable? to be called with args other than the stubbed on below - allow(File).to receive(:writable?).and_call_original + # allow File#writable? to be called with args other than the stubbed on below + allow(File).to receive(:writable?).and_call_original - # fake make the directory unwritable - allow(File).to receive(:writable?).with(bin_dir).and_return(false) - allow(Bundler).to receive(:system_bindir).and_return(Pathname("tmp/vendor/bin_dir/")) - message = <<-MESSAGE.chomp + # fake make the directory unwritable + allow(File).to receive(:writable?).with(bin_dir).and_return(false) + allow(Bundler).to receive(:system_bindir).and_return(Pathname("tmp/vendor/bin_dir/")) + message = <<-MESSAGE.chomp Following files may not be writable, so sudo is needed: tmp/vendor/bin_dir/ tmp/vendor/bundle/unwritable1.txt tmp/vendor/bundle/unwritable2.txt MESSAGE - expect(Bundler.ui).to receive(:warn).with(message) - expect(Bundler.requires_sudo?).to eq(true) + expect(Bundler.ui).to receive(:warn).with(message) + expect(Bundler.requires_sudo?).to eq(true) + end end end end diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb index 60c12706a5..69e4107408 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -98,8 +98,8 @@ RSpec.describe Bundler::Dsl do end describe "#gem" do - [:ruby, :ruby_18, :ruby_19, :ruby_20, :ruby_21, :ruby_22, :ruby_23, :ruby_24, :ruby_25, :mri, :mri_18, :mri_19, - :mri_20, :mri_21, :mri_22, :mri_23, :mri_24, :mri_25, :jruby, :rbx, :truffleruby].each do |platform| + [:ruby, :ruby_18, :ruby_19, :ruby_20, :ruby_21, :ruby_22, :ruby_23, :ruby_24, :ruby_25, :ruby_26, :mri, :mri_18, :mri_19, + :mri_20, :mri_21, :mri_22, :mri_23, :mri_24, :mri_25, :mri_26, :jruby, :rbx, :truffleruby].each do |platform| it "allows #{platform} as a valid platform" do subject.gem("foo", :platform => platform) end @@ -277,9 +277,9 @@ RSpec.describe Bundler::Dsl do describe "Runtime errors", :unless => Bundler.current_ruby.on_18? do it "will raise a Bundler::GemfileError" do - gemfile "s = 'foo'.freeze; s.strip!" + gemfile "raise RuntimeError, 'foo'" expect { Bundler::Dsl.evaluate(bundled_app("Gemfile"), nil, true) }. - to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: can't modify frozen String. Bundler cannot continue./i) + to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: foo. Bundler cannot continue./i) end end diff --git a/spec/bundler/fetcher/compact_index_spec.rb b/spec/bundler/fetcher/compact_index_spec.rb index 5a2d22193a..2f622f6653 100644 --- a/spec/bundler/fetcher/compact_index_spec.rb +++ b/spec/bundler/fetcher/compact_index_spec.rb @@ -11,11 +11,14 @@ RSpec.describe Bundler::Fetcher::CompactIndex do end describe "#specs_for_names" do + let(:thread_list) { Thread.list.select {|thread| thread.status == "run" } } + let(:thread_inspection) { thread_list.map {|th| " * #{th}:\n #{th.backtrace_locations.join("\n ")}" }.join("\n") } + it "has only one thread open at the end of the run" do compact_index.specs_for_names(["lskdjf"]) - thread_count = Thread.list.count {|thread| thread.status == "run" } - expect(thread_count).to eq 1 + thread_count = thread_list.count + expect(thread_count).to eq(1), "Expected 1 active thread after `#specs_for_names`, but found #{thread_count}. In particular, found:\n#{thread_inspection}" end it "calls worker#stop during the run" do diff --git a/spec/bundler/plugin/events_spec.rb b/spec/bundler/plugin/events_spec.rb index b09e915682..28d70c6fdd 100644 --- a/spec/bundler/plugin/events_spec.rb +++ b/spec/bundler/plugin/events_spec.rb @@ -2,10 +2,14 @@ RSpec.describe Bundler::Plugin::Events do context "plugin events" do + before { Bundler::Plugin::Events.send :reset } + describe "#define" do it "raises when redefining a constant" do + Bundler::Plugin::Events.send(:define, :TEST_EVENT, "foo") + expect do - Bundler::Plugin::Events.send(:define, :GEM_BEFORE_INSTALL_ALL, "another-value") + Bundler::Plugin::Events.send(:define, :TEST_EVENT, "bar") end.to raise_error(ArgumentError) end diff --git a/spec/bundler/ruby_version_spec.rb b/spec/bundler/ruby_version_spec.rb index 46a1b2918b..3ac7d9ef3a 100644 --- a/spec/bundler/ruby_version_spec.rb +++ b/spec/bundler/ruby_version_spec.rb @@ -399,8 +399,14 @@ RSpec.describe "Bundler::RubyVersion and its subclasses" do let(:bundler_system_ruby_version) { subject } - before do - Bundler::RubyVersion.instance_variable_set("@ruby_version", nil) + around do |example| + begin + old_ruby_version = Bundler::RubyVersion.instance_variable_get("@ruby_version") + Bundler::RubyVersion.instance_variable_set("@ruby_version", nil) + example.run + ensure + Bundler::RubyVersion.instance_variable_set("@ruby_version", old_ruby_version) + end end it "should return an instance of Bundler::RubyVersion" do diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb index 8e82d1b910..f24d85c241 100644 --- a/spec/bundler/shared_helpers_spec.rb +++ b/spec/bundler/shared_helpers_spec.rb @@ -223,6 +223,14 @@ RSpec.describe Bundler::SharedHelpers do ENV["BUNDLE_GEMFILE"] = "Gemfile" end + let(:setup_path) do + if ruby_core? + File.expand_path("../../../lib/bundler/setup", __dir__) + else + File.expand_path("../../lib/bundler/setup", __dir__) + end + end + shared_examples_for "ENV['PATH'] gets set correctly" do before { Dir.mkdir ".bundle" } @@ -236,7 +244,7 @@ RSpec.describe Bundler::SharedHelpers do shared_examples_for "ENV['RUBYOPT'] gets set correctly" do it "ensures -rbundler/setup is at the beginning of ENV['RUBYOPT']" do subject.set_bundle_environment - expect(ENV["RUBYOPT"].split(" ")).to start_with("-r#{File.expand_path("../../lib/bundler/setup", __dir__)}") + expect(ENV["RUBYOPT"].split(" ")).to start_with("-r#{setup_path}") end end @@ -393,7 +401,7 @@ RSpec.describe Bundler::SharedHelpers do it "sets BUNDLE_BIN_PATH to the bundle executable file" do subject.set_bundle_environment - bundle_exe = ruby_core? ? "../../../../exe/bundle" : "../../../exe/bundle" + bundle_exe = ruby_core? ? "../../../../../bin/bundle" : "../../../exe/bundle" expect(ENV["BUNDLE_BIN_PATH"]).to eq(File.expand_path(bundle_exe, __FILE__)) end end diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 8f49c576b5..b3ec2c2cfe 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -279,7 +279,12 @@ RSpec.describe "bundle exec" do G rubyopt = ENV["RUBYOPT"] - rubyopt = "-r#{File.expand_path("../../lib/bundler/setup", __dir__)} #{rubyopt}" + setup_path = if ruby_core? + File.expand_path("../../../lib/bundler/setup", __dir__) + else + File.expand_path("../../lib/bundler/setup", __dir__) + end + rubyopt = "-r#{setup_path} #{rubyopt}" bundle "exec 'echo $RUBYOPT'" expect(out).to have_rubyopts(rubyopt) diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index dcd36d3fe4..203b474877 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -1,11 +1,6 @@ # frozen_string_literal: true RSpec.describe "bundle gem" do - def reset! - super - global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false" - end - def execute_bundle_gem(gem_name, flag = "") bundle! "gem #{gem_name} #{flag}" # reset gemspec cache for each test because of commit 3d4163a @@ -22,6 +17,7 @@ RSpec.describe "bundle gem" do end before do + global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false" git_config_content = <<-EOF [user] name = "Bundler User" @@ -136,7 +132,6 @@ RSpec.describe "bundle gem" do context "git config github.user is absent" do before do sys_exec("git config --unset github.user") - reset! in_app_root bundle "gem #{gem_name}" end @@ -209,7 +204,6 @@ RSpec.describe "bundle gem" do context "gem naming with relative paths" do before do - reset! in_app_root end @@ -281,7 +275,6 @@ RSpec.describe "bundle gem" do before do `git config --unset user.name` `git config --unset user.email` - reset! in_app_root bundle "gem #{gem_name}" end @@ -322,7 +315,6 @@ RSpec.describe "bundle gem" do context "--exe parameter set" do before do - reset! in_app_root bundle "gem #{gem_name} --exe" end @@ -338,7 +330,6 @@ RSpec.describe "bundle gem" do context "--bin parameter set" do before do - reset! in_app_root bundle "gem #{gem_name} --bin" end @@ -354,7 +345,6 @@ RSpec.describe "bundle gem" do context "no --test parameter" do before do - reset! in_app_root bundle "gem #{gem_name}" end @@ -370,7 +360,6 @@ RSpec.describe "bundle gem" do context "--test parameter set to rspec" do before do - reset! in_app_root bundle "gem #{gem_name} --test=rspec" end @@ -397,7 +386,6 @@ RSpec.describe "bundle gem" do context "gem.test setting set to rspec" do before do - reset! in_app_root bundle "config set gem.test rspec" bundle "gem #{gem_name}" @@ -412,7 +400,6 @@ RSpec.describe "bundle gem" do context "gem.test setting set to rspec and --test is set to minitest" do before do - reset! in_app_root bundle "config set gem.test rspec" bundle "gem #{gem_name} --test=minitest" @@ -426,7 +413,6 @@ RSpec.describe "bundle gem" do context "--test parameter set to minitest" do before do - reset! in_app_root bundle "gem #{gem_name} --test=minitest" end @@ -456,7 +442,6 @@ RSpec.describe "bundle gem" do context "gem.test setting set to minitest" do before do - reset! in_app_root bundle "config set gem.test minitest" bundle "gem #{gem_name}" @@ -482,7 +467,6 @@ RSpec.describe "bundle gem" do context "--test with no arguments" do before do - reset! in_app_root bundle "gem #{gem_name} --test" end @@ -499,7 +483,6 @@ RSpec.describe "bundle gem" do context "--edit option" do it "opens the generated gemspec in the user's text editor" do - reset! in_app_root output = bundle "gem #{gem_name} --edit=echo" gemspec_path = File.join(Dir.pwd, gem_name, "#{gem_name}.gemspec") @@ -515,7 +498,6 @@ RSpec.describe "bundle gem" do before do global_config "BUNDLE_GEM__MIT" => "true", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false" end - after { reset! } it_behaves_like "--mit flag" it_behaves_like "--no-mit flag" end @@ -529,7 +511,6 @@ RSpec.describe "bundle gem" do before do global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "true" end - after { reset! } it_behaves_like "--coc flag" it_behaves_like "--no-coc flag" end @@ -572,7 +553,6 @@ RSpec.describe "bundle gem" do before do `git config --unset user.name` `git config --unset user.email` - reset! in_app_root bundle "gem #{gem_name}" end @@ -604,7 +584,6 @@ RSpec.describe "bundle gem" do context "--bin parameter set" do before do - reset! in_app_root bundle "gem #{gem_name} --bin" end @@ -620,7 +599,6 @@ RSpec.describe "bundle gem" do context "no --test parameter" do before do - reset! in_app_root bundle "gem #{gem_name}" end @@ -636,7 +614,6 @@ RSpec.describe "bundle gem" do context "--test parameter set to rspec" do before do - reset! in_app_root bundle "gem #{gem_name} --test=rspec" end @@ -671,7 +648,6 @@ RSpec.describe "bundle gem" do context "--test parameter set to minitest" do before do - reset! in_app_root bundle "gem #{gem_name} --test=minitest" end @@ -713,7 +689,6 @@ RSpec.describe "bundle gem" do context "--test with no arguments" do before do - reset! in_app_root bundle "gem #{gem_name} --test" end @@ -726,7 +701,6 @@ RSpec.describe "bundle gem" do context "--ext parameter set" do before do - reset! in_app_root bundle "gem test_gem --ext" end diff --git a/spec/install/gems/sudo_spec.rb b/spec/install/gems/sudo_spec.rb index a7372b1fbe..0d2d6b7eb4 100644 --- a/spec/install/gems/sudo_spec.rb +++ b/spec/install/gems/sudo_spec.rb @@ -3,13 +3,20 @@ RSpec.describe "when using sudo", :sudo => true do describe "and BUNDLE_PATH is writable" do context "but BUNDLE_PATH/build_info is not writable" do + let(:subdir) do + system_gem_path("cache") + end + before do bundle! "config set path.system true" - subdir = system_gem_path("cache") subdir.mkpath sudo "chmod u-w #{subdir}" end + after do + sudo "chmod u+w #{subdir}" + end + it "installs" do install_gemfile <<-G source "file://#{gem_repo1}" @@ -101,6 +108,10 @@ RSpec.describe "when using sudo", :sudo => true do sudo "chmod ugo-w #{default_bundle_path}" end + after do + sudo "chmod ugo+w #{default_bundle_path}" + end + it "installs" do install_gemfile <<-G source "file://#{gem_repo1}" @@ -142,6 +153,8 @@ RSpec.describe "when using sudo", :sudo => true do bundle :install, :env => { "GEM_HOME" => gem_home.to_s, "GEM_PATH" => nil } expect(gem_home.join("bin/rackup")).to exist expect(the_bundle).to include_gems "rack 1.0", :env => { "GEM_HOME" => gem_home.to_s, "GEM_PATH" => nil } + + sudo "rm -rf #{tmp("sudo_gem_home")}" end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 067c8dc070..d3de1ff784 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,12 +23,6 @@ end $debug = false Spec::Manpages.setup unless Gem.win_platform? -Spec::Rubygems.setup -ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb" -ENV["BUNDLE_SPEC_RUN"] = "true" - -# Don't wrap output in tests -ENV["THOR_COLUMNS"] = "10000" module Gem def self.ruby=(ruby) @@ -58,6 +52,8 @@ RSpec.configure do |config| # forever due to memory constraints config.fail_fast ||= 25 if ENV["CI"] + config.bisect_runner = :shell + if ENV["BUNDLER_SUDO_TESTS"] && Spec::Sudo.present? config.filter_run :sudo => true else @@ -102,6 +98,15 @@ RSpec.configure do |config| end config.before :suite do + Spec::Rubygems.setup + ENV["RUBYOPT"] = original_env["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb" + ENV["BUNDLE_SPEC_RUN"] = original_env["BUNDLE_SPEC_RUN"] = "true" + + # Don't wrap output in tests + ENV["THOR_COLUMNS"] = "10000" + + original_env = ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) } + if ENV["BUNDLE_RUBY"] FileUtils.cp_r Spec::Path.bindir, File.join(Spec::Path.root, "lib", "exe") end @@ -111,14 +116,15 @@ RSpec.configure do |config| build_repo1 end - config.before :each do + config.around :each do |example| + ENV.replace(original_env) reset! system_gems [] in_app_root @command_executions = [] - end - config.after :each do |example| + example.run + all_output = @command_executions.map(&:to_s_verbose).join("\n\n") if example.exception && !all_output.empty? warn all_output unless config.formatters.grep(RSpec::Core::Formatters::DocumentationFormatter).empty? @@ -129,7 +135,6 @@ RSpec.configure do |config| end Dir.chdir(original_wd) - ENV.replace(original_env) end config.after :suite do |