diff options
-rw-r--r-- | .github/bors.toml | 3 | ||||
-rw-r--r-- | CHANGELOG.md | 50 | ||||
-rw-r--r-- | Rakefile | 15 | ||||
-rw-r--r-- | lib/bundler.rb | 2 | ||||
-rw-r--r-- | lib/bundler/build_metadata.rb | 17 | ||||
-rw-r--r-- | lib/bundler/injector.rb | 14 | ||||
-rw-r--r-- | lib/bundler/templates/Executable.bundler | 2 | ||||
-rw-r--r-- | lib/bundler/templates/newgem/newgem.gemspec.tt | 15 | ||||
-rw-r--r-- | man/bundle-config.ronn | 16 | ||||
-rw-r--r-- | spec/bundler/bundler_spec.rb | 13 | ||||
-rw-r--r-- | spec/bundler/gem_helper_spec.rb | 19 | ||||
-rw-r--r-- | spec/bundler/plugin/installer_spec.rb | 4 | ||||
-rw-r--r-- | spec/bundler/settings_spec.rb | 4 | ||||
-rw-r--r-- | spec/bundler/source/git/git_proxy_spec.rb | 32 | ||||
-rw-r--r-- | spec/bundler/source/rubygems/remote_spec.rb | 24 | ||||
-rw-r--r-- | spec/commands/config_spec.rb | 51 | ||||
-rw-r--r-- | spec/commands/newgem_spec.rb | 24 | ||||
-rw-r--r-- | spec/commands/pristine_spec.rb | 4 | ||||
-rw-r--r-- | spec/commands/remove_spec.rb | 24 | ||||
-rw-r--r-- | spec/install/gemfile/git_spec.rb | 7 | ||||
-rw-r--r-- | spec/support/builders.rb | 7 | ||||
-rw-r--r-- | spec/support/helpers.rb | 9 | ||||
-rw-r--r-- | spec/support/rubygems_ext.rb | 6 |
23 files changed, 219 insertions, 143 deletions
diff --git a/.github/bors.toml b/.github/bors.toml index db93b69597..8f4d9a640a 100644 --- a/.github/bors.toml +++ b/.github/bors.toml @@ -2,7 +2,8 @@ status = [ "continuous-integration/travis-ci/push" ] -timeout-sec = 14400 +timeout_sec = 14400 +delete_merged_branches = true [committer] name = "Bundlerbot" diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cd024e21d..155c2503f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,53 @@ +## 1.17.1 (2018-10-25) + + - Convert `Pathname`s to `String`s before sorting them, fixing #6760 and #6758 ([#6761](https://github.com/bundler/bundler/pull/6761), @alexggordon) + +## 1.17.0 (2018-10-25) + +No new changes. + +## 1.17.0.pre.2 (2018-10-13) + +Features: + + - Configure Bundler home, cache, config and plugin directories with `BUNDLE_USER_HOME`, `BUNDLE_USER_CACHE`, `BUNDLE_USER_CONFIG` and `BUNDLE_USER_PLUGIN` env vars ([#4333](https://github.com/bundler/bundler/issues/4333), @gwerbin) + - Add `--all` option to `bundle binstubs` that will generate an executable file for all gems with commands in the bundle + - Add `bundle remove` command to remove gems from the Gemfile via the CLI + - Improve checking file permissions and asking for `sudo` in Bundler when it doesn't need to + - Add error message to `bundle add` to check adding duplicate gems to the Gemfile + - When asking for `sudo`, Bundler will show a list of folders/files that require elevated permissions to write to. + +The following new features are available but are not enabled by default. These are intended to be tested by users for the upcoming release of Bundler 2. + + - Improve deprecation warning message for `bundle show` command + - Improve deprecation warning message for the `--force` option in `bundle install` + +## 1.17.0.pre.1 (2018-09-24) + +Features: + + - Check folder/file permissions of the Bundle home directory in the `bundle doctor` command ([#5786](https://github.com/bundler/bundler/issues/5786), @ajwann) + - Remove compiled gem extensions when running `bundle clean` ([#5596](https://github.com/bundler/bundler/issues/5596), @akhramov) + - Add `--paths` option to `bundle list` command ([#6172](https://github.com/bundler/bundler/issues/6172), @colby-swandale) + - Add base error class to gems generated from `bundle gem` ([#6260](https://github.com/bundler/bundler/issues/6260), @christhekeele) + - Correctly re-install gem extensions with a git source when running `bundle pristine` ([#6294](https://github.com/bundler/bundler/issues/6294), @wagenet) + - Add config option to disable platform warnings ([#6124](https://github.com/bundler/bundler/issues/6124), @agrim123) + - Add `--skip-install` option to `bundle add` command to add gems to the Gemfile without installation ([#6511](https://github.com/bundler/bundler/issues/6511), @agrim123) + - Add `--only-explicit` option to `bundle outdated` to list only outdated gems in the Gemfile ([#5366](https://github.com/bundler/bundler/issues/5366), @peret) + - Support adding multiple gems to the Gemfile with `bundle add` ([#6543](https://github.com/bundler/bundler/issues/6543), @agrim123) + - Make registered plugin events easier to manage in the Plugin API (@jules2689) + - Add new gem install hooks to the Plugin API (@jules2689) + - Add `--optimistic` and `--strict` options to `bundle add` ([#6553](https://github.com/bundler/bundler/issues/6553), @agrim123) + - Add `--without-group` and `--only-group` options to `bundle list` ([#6564](https://github.com/bundler/bundler/issues/6564), @agrim123) + - Add `--gemfile` option to the `bundle exec` command ([#5924](https://github.com/bundler/bundler/issues/5924), @ankitkataria) + +The following new features are available but are not enabled by default. These are intended to be tested by users for the upcoming release of Bundler 2. + + - Make `install --path` relative to the current working directory ([#2048](https://github.com/bundler/bundler/issues/2048), @igorbozato) + - Auto-configure job count ([#5808](https://github.com/bundler/bundler/issues/5808), @segiddins) + - Use the Gem Version Promoter for major gem updates ([#5993](https://github.com/bundler/bundler/issues/5993), @segiddins) + - Add config option to add the Ruby scope to `bundle config path` when configured globally (@segiddins) + ## 1.16.6 (2018-10-05) Changes: @@ -51,17 +51,10 @@ namespace :spec do deps.delete("rdiscount") end - if Gem::VERSION < "2.0.0" - deps.sort_by {|name, _| name }.map do |name, version| - gem_install_command = "install --no-ri --no-rdoc --conservative #{name} -v '#{version}'" - sh %(#{Gem.ruby} -S gem #{gem_install_command}) - end - else - gem_install_command = "install --no-document --conservative " + deps.sort_by {|name, _| name }.map do |name, version| - "'#{name}:#{version}'" - end.join(" ") - sh %(#{Gem.ruby} -S gem #{gem_install_command}) - end + gem_install_command = "install --no-document --conservative " + deps.sort_by {|name, _| name }.map do |name, version| + "'#{name}:#{version}'" + end.join(" ") + sh %(#{Gem.ruby} -S gem #{gem_install_command}) # Download and install gems used inside tests $LOAD_PATH.unshift("./spec") diff --git a/lib/bundler.rb b/lib/bundler.rb index 2411ac20c2..1cb3b4fb21 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -371,7 +371,7 @@ EOF unwritable_files = files.reject {|f| File.writable?(f) } sudo_needed = !unwritable_files.empty? if sudo_needed - Bundler.ui.warn "Following files may not be writable, so sudo is needed:\n #{unwritable_files.sort.map(&:to_s).join("\n ")}" + Bundler.ui.warn "Following files may not be writable, so sudo is needed:\n #{unwritable_files.map(&:to_s).sort.join("\n ")}" end end diff --git a/lib/bundler/build_metadata.rb b/lib/bundler/build_metadata.rb index c9d7482b24..33f91e9162 100644 --- a/lib/bundler/build_metadata.rb +++ b/lib/bundler/build_metadata.rb @@ -28,14 +28,19 @@ module Bundler # If Bundler has been installed without its .git directory and without a # commit instance variable then we can't determine its commits SHA. git_dir = File.join(File.expand_path("../../..", __FILE__), ".git") - # Check for both a file or folder because RubyGems runs Bundler's test suite in a submodule - # which does not have a .git folder - return "unknown" unless File.exist?(git_dir) + if File.directory?(git_dir) + return @git_commit_sha = Dir.chdir(git_dir) { `git rev-parse --short HEAD`.strip.freeze } + end - # Otherwise shell out to git. - @git_commit_sha = Dir.chdir(File.expand_path("..", __FILE__)) do - `git rev-parse --short HEAD`.strip.freeze + # If Bundler is a submodule in RubyGems, get the submodule commit + git_sub_dir = File.join(File.expand_path("../../../..", __FILE__), ".git") + if File.directory?(git_sub_dir) + return @git_commit_sha = Dir.chdir(git_sub_dir) do + `git ls-tree --abbrev=8 HEAD bundler`.split(/\s/).fetch(2, "").strip.freeze + end end + + @git_commit_sha ||= "unknown" end # Whether this is an official release build of Bundler. diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index 1bb29f0b36..e67469f2dd 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -123,7 +123,7 @@ module Bundler end end - # evalutes a gemfile to remove the specified gem + # evaluates a gemfile to remove the specified gem # from it. def remove_deps(gemfile_path) initial_gemfile = IO.readlines(gemfile_path) @@ -136,8 +136,8 @@ module Bundler removed_deps = remove_gems_from_dependencies(builder, @deps, gemfile_path) - # abort the opertion if no gems were removed - # no need to operate on gemfile furthur + # abort the operation if no gems were removed + # no need to operate on gemfile further return [] if removed_deps.empty? cleaned_gemfile = remove_gems_from_gemfile(@deps, gemfile_path) @@ -153,8 +153,8 @@ module Bundler # @param [Dsl] builder Dsl object of current Gemfile. # @param [Array] gems Array of names of gems to be removed. - # @param [Pathname] path of the Gemfile - # @return [Array] removed_deps Array of removed dependencies. + # @param [Pathname] gemfile_path Path of the Gemfile. + # @return [Array] Array of removed dependencies. def remove_gems_from_dependencies(builder, gems, gemfile_path) removed_deps = [] @@ -206,7 +206,7 @@ module Bundler nested_blocks -= 1 gemfile.each_with_index do |line, index| - next unless !line.nil? && line.include?(block_name) + next unless !line.nil? && line.strip.start_with?(block_name) if gemfile[index + 1] =~ /^\s*end\s*$/ gemfile[index] = nil gemfile[index + 1] = nil @@ -222,7 +222,7 @@ module Bundler # @param [Array] removed_deps Array of removed dependencies. # @param [Array] initial_gemfile Contents of original Gemfile before any operation. def cross_check_for_errors(gemfile_path, original_deps, removed_deps, initial_gemfile) - # evalute the new gemfile to look for any failure cases + # evaluate the new gemfile to look for any failure cases builder = Dsl.new builder.eval_gemfile(gemfile_path) diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler index eeda90b584..3adac41e74 100644 --- a/lib/bundler/templates/Executable.bundler +++ b/lib/bundler/templates/Executable.bundler @@ -11,7 +11,7 @@ require "rubygems" m = Module.new do - module_function + module_function def invoked_as_script? File.expand_path($0) == File.expand_path(__FILE__) diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt index 113bf82eb2..c1a50fe912 100644 --- a/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -21,18 +21,11 @@ Gem::Specification.new do |spec| spec.license = "MIT" <%- end -%> - # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' - # to allow pushing to a single host or delete this section to allow pushing to any host. - if spec.respond_to?(:metadata) - spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" + spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here." - spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." - else - raise "RubyGems 2.0 or newer is required to protect against " \ - "public gem pushes." - end + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here." + spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn index 4d8bda61f7..379b778348 100644 --- a/man/bundle-config.ronn +++ b/man/bundle-config.ronn @@ -227,7 +227,7 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html). is used, defaults to vendor/bundle. * `path.system` (`BUNDLE_PATH__SYSTEM`): Whether Bundler will install gems into the default system path (`Gem.dir`). -* `path_relative_to_cwd` (`PATH_RELATIVE_TO_CWD`) +* `path_relative_to_cwd` (`BUNDLE_PATH_RELATIVE_TO_CWD`) Makes `--path` relative to the CWD instead of the `Gemfile`. * `plugins` (`BUNDLE_PLUGINS`): Enable Bundler's experimental plugin system. @@ -381,3 +381,17 @@ This is especially useful for private repositories on hosts such as Github, where you can use personal OAuth tokens: export BUNDLE_GITHUB__COM=abcd0123generatedtoken:x-oauth-basic + + +## CONFIGURE BUNDLER DIRECTORIES + +Bundler's home, config, cache and plugin directories are able to be configured +through environment variables. The default location for Bundler's home directory is +`~/.bundle`, which all directories inherit from by default. The following +outlines the available environment variables and their default values + + BUNDLE_USER_HOME : $HOME/.bundle + BUNDLE_USER_CACHE : $BUNDLE_USER_HOME/cache + BUNDLE_USER_CONFIG : $BUNDLE_USER_HOME/config + BUNDLE_USER_PLUGIN : $BUNDLE_USER_HOME/plugin + diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 4759005c0c..194d6752b2 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -378,9 +378,11 @@ EOF 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") if Bundler.respond_to?(:remove_instance_variable) Bundler.remove_instance_variable(:@requires_sudo_ran) Bundler.remove_instance_variable(:@requires_sudo) @@ -401,13 +403,24 @@ EOF 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 + + # 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 diff --git a/spec/bundler/gem_helper_spec.rb b/spec/bundler/gem_helper_spec.rb index 3620035fe1..e2cd7e8bc6 100644 --- a/spec/bundler/gem_helper_spec.rb +++ b/spec/bundler/gem_helper_spec.rb @@ -29,15 +29,6 @@ RSpec.describe Bundler::GemHelper do end context "interpolates the name" do - before do - # Remove exception that prevents public pushes on older RubyGems versions - if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0") - content = File.read(app_gemspec_path) - content.sub!(/raise "RubyGems 2\.0 or newer.*/, "") - File.open(app_gemspec_path, "w") {|f| f.write(content) } - end - end - it "when there is only one gemspec" do expect(subject.gemspec.name).to eq(app_name) end @@ -72,7 +63,7 @@ RSpec.describe Bundler::GemHelper do let(:app_version) { "0.1.0" } let(:app_gem_dir) { app_path.join("pkg") } let(:app_gem_path) { app_gem_dir.join("#{app_name}-#{app_version}.gem") } - let(:app_gemspec_content) { remove_push_guard(File.read(app_gemspec_path)) } + let(:app_gemspec_content) { File.read(app_gemspec_path) } before(:each) do content = app_gemspec_content.gsub("TODO: ", "") @@ -81,14 +72,6 @@ RSpec.describe Bundler::GemHelper do File.open(app_gemspec_path, "w") {|file| file << content } end - def remove_push_guard(gemspec_content) - # Remove exception that prevents public pushes on older RubyGems versions - if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0") - gemspec_content.sub!(/raise "RubyGems 2\.0 or newer.*/, "") - end - gemspec_content - end - it "uses a shell UI for output" do expect(Bundler.ui).to be_a(Bundler::UI::Shell) end diff --git a/spec/bundler/plugin/installer_spec.rb b/spec/bundler/plugin/installer_spec.rb index 7ad4a9d37a..71fef76042 100644 --- a/spec/bundler/plugin/installer_spec.rb +++ b/spec/bundler/plugin/installer_spec.rb @@ -3,10 +3,6 @@ RSpec.describe Bundler::Plugin::Installer do subject(:installer) { Bundler::Plugin::Installer.new } - before do - # allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(Pathname.new("/Gemfile")) - end - describe "cli install" do it "uses Gem.sources when non of the source is provided" do sources = double(:sources) diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb index 1a31493e20..339428eb48 100644 --- a/spec/bundler/settings_spec.rb +++ b/spec/bundler/settings_spec.rb @@ -130,13 +130,15 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow describe "#temporary" do it "reset after used" do - Bundler.settings.set_local :no_install, true + Bundler.settings.set_command_option :no_install, true Bundler.settings.temporary(:no_install => false) do expect(Bundler.settings[:no_install]).to eq false end expect(Bundler.settings[:no_install]).to eq true + + Bundler.settings.set_command_option :no_install, nil end it "returns the return value of the block" do diff --git a/spec/bundler/source/git/git_proxy_spec.rb b/spec/bundler/source/git/git_proxy_spec.rb index 3a29c97461..016105ccde 100644 --- a/spec/bundler/source/git/git_proxy_spec.rb +++ b/spec/bundler/source/git/git_proxy_spec.rb @@ -10,29 +10,33 @@ RSpec.describe Bundler::Source::Git::GitProxy do context "with configured credentials" do it "adds username and password to URI" do - Bundler.settings.temporary(uri => "u:p") - expect(subject).to receive(:git_retry).with(match("https://u:p@github.com/bundler/bundler.git")) - subject.checkout + Bundler.settings.temporary(uri => "u:p") do + expect(subject).to receive(:git_retry).with(match("https://u:p@github.com/bundler/bundler.git")) + subject.checkout + end end it "adds username and password to URI for host" do - Bundler.settings.temporary("github.com" => "u:p") - expect(subject).to receive(:git_retry).with(match("https://u:p@github.com/bundler/bundler.git")) - subject.checkout + Bundler.settings.temporary("github.com" => "u:p") do + expect(subject).to receive(:git_retry).with(match("https://u:p@github.com/bundler/bundler.git")) + subject.checkout + end end it "does not add username and password to mismatched URI" do - Bundler.settings.temporary("https://u:p@github.com/bundler/bundler-mismatch.git" => "u:p") - expect(subject).to receive(:git_retry).with(match(uri)) - subject.checkout + Bundler.settings.temporary("https://u:p@github.com/bundler/bundler-mismatch.git" => "u:p") do + expect(subject).to receive(:git_retry).with(match(uri)) + subject.checkout + end end it "keeps original userinfo" do - Bundler.settings.temporary("github.com" => "u:p") - original = "https://orig:info@github.com/bundler/bundler.git" - subject = described_class.new(Pathname("path"), original, "HEAD") - expect(subject).to receive(:git_retry).with(match(original)) - subject.checkout + Bundler.settings.temporary("github.com" => "u:p") do + original = "https://orig:info@github.com/bundler/bundler.git" + subject = described_class.new(Pathname("path"), original, "HEAD") + expect(subject).to receive(:git_retry).with(match(original)) + subject.checkout + end end end diff --git a/spec/bundler/source/rubygems/remote_spec.rb b/spec/bundler/source/rubygems/remote_spec.rb index 9a7ab42128..52fb4e7f1c 100644 --- a/spec/bundler/source/rubygems/remote_spec.rb +++ b/spec/bundler/source/rubygems/remote_spec.rb @@ -22,8 +22,9 @@ RSpec.describe Bundler::Source::Rubygems::Remote do end it "applies configured credentials" do - Bundler.settings.temporary(uri_no_auth.to_s => credentials) - expect(remote(uri_no_auth).uri).to eq(uri_with_auth) + Bundler.settings.temporary(uri_no_auth.to_s => credentials) do + expect(remote(uri_no_auth).uri).to eq(uri_with_auth) + end end end @@ -33,8 +34,9 @@ RSpec.describe Bundler::Source::Rubygems::Remote do end it "does not apply given credentials" do - Bundler.settings.temporary(uri_no_auth.to_s => credentials) - expect(remote(uri_no_auth).anonymized_uri).to eq(uri_no_auth) + Bundler.settings.temporary(uri_no_auth.to_s => credentials) do + expect(remote(uri_no_auth).anonymized_uri).to eq(uri_no_auth) + end end end @@ -44,8 +46,9 @@ RSpec.describe Bundler::Source::Rubygems::Remote do end it "only applies the given user" do - Bundler.settings.temporary(uri_no_auth.to_s => credentials) - expect(remote(uri_no_auth).cache_slug).to eq("gems.example.com.username.443.MD5HEX(gems.example.com.username.443./)") + Bundler.settings.temporary(uri_no_auth.to_s => credentials) do + expect(remote(uri_no_auth).cache_slug).to eq("gems.example.com.username.443.MD5HEX(gems.example.com.username.443./)") + end end end end @@ -106,7 +109,9 @@ RSpec.describe Bundler::Source::Rubygems::Remote do let(:mirror_uri_with_auth) { URI("https://username:password@rubygems-mirror.org/") } let(:mirror_uri_no_auth) { URI("https://rubygems-mirror.org/") } - before { Bundler.settings.set_local("mirror.https://rubygems.org/", mirror_uri_with_auth.to_s) } + before { Bundler.settings.temporary("mirror.https://rubygems.org/" => mirror_uri_with_auth.to_s) } + + after { Bundler.settings.temporary("mirror.https://rubygems.org/" => nil) } specify "#uri returns the mirror URI with credentials" do expect(remote(uri).uri).to eq(mirror_uri_with_auth) @@ -135,6 +140,11 @@ RSpec.describe Bundler::Source::Rubygems::Remote do Bundler.settings.temporary(mirror_uri_no_auth.to_s => credentials) end + after do + Bundler.settings.temporary("mirror.https://rubygems.org/" => nil) + Bundler.settings.temporary(mirror_uri_no_auth.to_s => nil) + end + specify "#uri returns the mirror URI with credentials" do expect(remote(uri).uri).to eq(mirror_uri_with_auth) end diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb index c76135d72c..61734ef005 100644 --- a/spec/commands/config_spec.rb +++ b/spec/commands/config_spec.rb @@ -1,13 +1,6 @@ # frozen_string_literal: true RSpec.describe ".bundle/config" do - before :each do - gemfile <<-G - source "file://#{gem_repo1}" - gem "rack", "1.0.0" - G - end - describe "config" do before { bundle "config foo bar" } @@ -42,7 +35,14 @@ RSpec.describe ".bundle/config" do end end - describe "BUNDLE_APP_CONFIG" do + describe "location" do + before :each do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "1.0.0" + G + end + it "can be moved with an environment variable" do ENV["BUNDLE_APP_CONFIG"] = tmp("foo/bar").to_s bundle "install", forgotten_command_line_options(:path => "vendor/bundle") @@ -66,7 +66,12 @@ RSpec.describe ".bundle/config" do end describe "global" do - before(:each) { bundle :install } + before(:each) do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "1.0.0" + G + end it "is the default" do bundle "config foo global" @@ -155,7 +160,12 @@ RSpec.describe ".bundle/config" do end describe "local" do - before(:each) { bundle :install } + before(:each) do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "1.0.0" + G + end it "can also be set explicitly" do bundle "config --local foo local" @@ -208,7 +218,12 @@ RSpec.describe ".bundle/config" do end describe "env" do - before(:each) { bundle :install } + before(:each) do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "1.0.0" + G + end it "can set boolean properties via the environment" do ENV["BUNDLE_FROZEN"] = "true" @@ -276,7 +291,12 @@ RSpec.describe ".bundle/config" do end describe "gem mirrors" do - before(:each) { bundle :install } + before(:each) do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "1.0.0" + G + end it "configures mirrors using keys with `mirror.`" do bundle "config --local mirror.http://gems.example.org http://gem-mirror.example.org" @@ -338,7 +358,12 @@ E end describe "very long lines" do - before(:each) { bundle :install } + before(:each) do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "1.0.0" + G + end let(:long_string) do "--with-xml2-include=/usr/pkg/include/libxml2 --with-xml2-lib=/usr/pkg/lib " \ diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index e6d6e19122..2914ba66c5 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -6,18 +6,8 @@ RSpec.describe "bundle gem" do global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false" end - def remove_push_guard(gem_name) - # Remove exception that prevents public pushes on older RubyGems versions - if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0") - path = "#{gem_name}/#{gem_name}.gemspec" - content = File.read(path).sub(/raise "RubyGems 2\.0 or newer.*/, "") - File.open(path, "w") {|f| f.write(content) } - end - end - - def execute_bundle_gem(gem_name, flag = "", to_remove_push_guard = true) + def execute_bundle_gem(gem_name, flag = "") bundle! "gem #{gem_name} #{flag}" - remove_push_guard(gem_name) if to_remove_push_guard # reset gemspec cache for each test because of commit 3d4163a Bundler.clear_gemspec_cache end @@ -96,7 +86,7 @@ RSpec.describe "bundle gem" do shared_examples_for "--coc flag" do before do - execute_bundle_gem(gem_name, "--coc", false) + execute_bundle_gem(gem_name, "--coc") end it "generates a gem skeleton with MIT license" do gem_skeleton_assertions(gem_name) @@ -113,7 +103,7 @@ RSpec.describe "bundle gem" do shared_examples_for "--no-coc flag" do before do - execute_bundle_gem(gem_name, "--no-coc", false) + execute_bundle_gem(gem_name, "--no-coc") end it "generates a gem skeleton without Code of Conduct" do gem_skeleton_assertions(gem_name) @@ -149,7 +139,6 @@ RSpec.describe "bundle gem" do reset! in_app_root bundle "gem #{gem_name}" - remove_push_guard(gem_name) end it "contribute URL set to [USERNAME]" do @@ -202,9 +191,6 @@ RSpec.describe "bundle gem" do line.gsub(/\=.*$/, "= %q{A short summary of my new gem.}") when /spec\.description/ line.gsub(/\=.*$/, "= %q{A longer description of my new gem.}") - # Remove exception that prevents public pushes on older RubyGems versions - when /raise "RubyGems 2.0 or newer/ - line.gsub(/.*/, "") if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0") else line end @@ -298,7 +284,6 @@ RSpec.describe "bundle gem" do reset! in_app_root bundle "gem #{gem_name}" - remove_push_guard(gem_name) end it_should_behave_like "git config is absent" @@ -397,7 +382,6 @@ RSpec.describe "bundle gem" do end it "depends on a specific version of rspec", :rubygems => ">= 1.8.1" do - remove_push_guard(gem_name) rspec_dep = generated_gem.gemspec.development_dependencies.find {|d| d.name == "rspec" } expect(rspec_dep).to be_specific end @@ -448,7 +432,6 @@ RSpec.describe "bundle gem" do end it "depends on a specific version of minitest", :rubygems => ">= 1.8.1" do - remove_push_guard(gem_name) rspec_dep = generated_gem.gemspec.development_dependencies.find {|d| d.name == "minitest" } expect(rspec_dep).to be_specific end @@ -592,7 +575,6 @@ RSpec.describe "bundle gem" do reset! in_app_root bundle "gem #{gem_name}" - remove_push_guard(gem_name) end it_should_behave_like "git config is absent" diff --git a/spec/commands/pristine_spec.rb b/spec/commands/pristine_spec.rb index 76848c5e44..a868465c03 100644 --- a/spec/commands/pristine_spec.rb +++ b/spec/commands/pristine_spec.rb @@ -48,9 +48,7 @@ RSpec.describe "bundle pristine", :ruby_repo do bundle! "install" bundle! "pristine", :system_bundler => true bundle! "-v", :system_bundler => true - # An old rubygems couldn't handle a correct version of vendoered bundler. - bundler_version = Gem::VERSION < "2.1" ? "1.16.0" : Bundler::VERSION - expect(out).to end_with(bundler_version) + expect(out).to end_with(Bundler::VERSION) end end diff --git a/spec/commands/remove_spec.rb b/spec/commands/remove_spec.rb index 37594b1ece..daed91c034 100644 --- a/spec/commands/remove_spec.rb +++ b/spec/commands/remove_spec.rb @@ -140,6 +140,30 @@ RSpec.describe "bundle remove" do end end + context "when gem to be removed is outside block" do + it "does not modify group" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + group :test do + gem "coffee-script-source" + end + G + + bundle! "remove rack" + + expect(out).to include("rack was removed.") + gemfile_should_be <<-G + source "file://#{gem_repo1}" + + group :test do + gem "coffee-script-source" + end + G + end + end + context "when an empty block is also present" do it "removes all empty blocks" do gemfile <<-G diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb index ab9fdd9f86..08fe21cacf 100644 --- a/spec/install/gemfile/git_spec.rb +++ b/spec/install/gemfile/git_spec.rb @@ -922,12 +922,11 @@ RSpec.describe "bundle install with git sources" do build_git "foo", :path => lib_path("nested") build_git "bar", :path => lib_path("nested") - gemfile <<-G + install_gemfile <<-G gem "foo", :git => "#{lib_path("nested")}" gem "bar", :git => "#{lib_path("nested")}" G - bundle "install" expect(File.read(bundled_app("Gemfile.lock")).scan("GIT").size).to eq(1) end @@ -1010,13 +1009,11 @@ RSpec.describe "bundle install with git sources" do install_gemfile <<-G gem "foo", :git => "file://#{lib_path("foo-1.0")}", :ref => "#{revision}" G - bundle "install" expect(out).to_not match(/Revision.*does not exist/) install_gemfile <<-G gem "foo", :git => "file://#{lib_path("foo-1.0")}", :ref => "deadbeef" G - bundle "install" expect(out).to include("Revision deadbeef does not exist in the repository") end end @@ -1423,7 +1420,6 @@ In Gemfile: end G - bundle :install expect(last_command.stdboth).to_not include("password1") expect(last_command.stdout).to include("Fetching https://user1@github.com/company/private-repo") end @@ -1439,7 +1435,6 @@ In Gemfile: end G - bundle :install expect(last_command.stdboth).to_not include("oauth_token") expect(last_command.stdout).to include("Fetching https://x-oauth-basic@github.com/company/private-repo") end diff --git a/spec/support/builders.rb b/spec/support/builders.rb index fa32b12b65..188b1d3eb7 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -210,12 +210,7 @@ module Spec # The yard gem iterates over Gem.source_index looking for plugins build_gem "yard" do |s| s.write "lib/yard.rb", <<-Y - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("1.8.10") - specs = Gem::Specification - else - specs = Gem.source_index.find_name('') - end - specs.sort_by(&:name).each do |gem| + Gem::Specification.sort_by(&:name).each do |gem| puts gem.full_name end Y diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index b027e7a922..98a4096216 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -228,9 +228,9 @@ module Spec 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 @@ -327,11 +327,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 diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index eff142118f..7a69d713cb 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -59,11 +59,7 @@ module Spec no_reqs.map!(&:first) reqs.map! {|name, req| "'#{name}:#{req}'" } deps = reqs.concat(no_reqs).join(" ") - cmd = if Gem::VERSION < "2.0.0" - "#{Gem.ruby} -S gem install #{deps} --no-rdoc --no-ri --conservative" - else - "#{Gem.ruby} -S gem install #{deps} --no-document --conservative" - end + cmd = "#{Gem.ruby} -S gem install #{deps} --no-document --conservative" puts cmd system(cmd) || raise("Installing gems #{deps} for the tests to use failed!") end |