diff options
34 files changed, 183 insertions, 96 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index 586ec9e319..01088346f3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +require: rubocop-performance + AllCops: DisabledByDefault: true TargetRubyVersion: 2.3 @@ -219,16 +221,6 @@ Lint/Void: Layout/AccessModifierIndentation: Enabled: true EnforcedStyle: outdent - Exclude: - - 'lib/bundler/cli.rb' - - 'lib/bundler/definition.rb' - - 'lib/bundler/feature_flag.rb' - - 'lib/bundler/gem_helpers.rb' - - 'lib/bundler/index.rb' - - 'lib/bundler/remote_specification.rb' - - 'lib/bundler/shared_helpers.rb' - - 'lib/bundler/source/path.rb' - - 'spec/realworld/gemfile_source_header_spec.rb' Layout/AlignArray: Enabled: true @@ -309,19 +301,19 @@ Layout/EndOfLine: Layout/ExtraSpacing: Enabled: true -Layout/FirstParameterIndentation: +Layout/IndentAssignment: Enabled: true -Layout/IndentArray: +Layout/IndentFirstArrayElement: Enabled: true EnforcedStyle: consistent -Layout/IndentAssignment: +Layout/IndentFirstHashElement: Enabled: true + EnforcedStyle: special_inside_parentheses -Layout/IndentHash: +Layout/IndentFirstArgument: Enabled: true - EnforcedStyle: special_inside_parentheses Layout/IndentationConsistency: Enabled: true @@ -464,21 +456,12 @@ Performance/EndWith: Performance/FixedSize: Enabled: true -Performance/LstripRstrip: - Enabled: true - -Performance/RedundantSortBy: - Enabled: true - Performance/RegexpMatch: Enabled: true Performance/ReverseEach: Enabled: true -Performance/Sample: - Enabled: true - Performance/Size: Enabled: true @@ -731,6 +714,9 @@ Style/RedundantParentheses: Style/RedundantSelf: Enabled: true +Style/RedundantSortBy: + Enabled: true + Style/RegexpLiteral: Enabled: true @@ -740,6 +726,9 @@ Style/RescueModifier: Style/RescueStandardError: Enabled: true +Style/Sample: + Enabled: true + Style/SelfAssignment: Enabled: true @@ -768,6 +757,9 @@ Style/StringLiteralsInInterpolation: Enabled: true EnforcedStyle: double_quotes +Style/Strip: + Enabled: true + Style/StructInheritance: Enabled: true diff --git a/bundler.gemspec b/bundler.gemspec index bcc1027a40..7e5346de36 100644 --- a/bundler.gemspec +++ b/bundler.gemspec @@ -38,7 +38,8 @@ Gem::Specification.new do |s| s.add_development_dependency "rake", "~> 12.0" s.add_development_dependency "ronn", "~> 0.7.3" s.add_development_dependency "rspec", "~> 3.6" - s.add_development_dependency "rubocop", "= 0.65.0" + s.add_development_dependency "rubocop", "= 0.68.0" + s.add_development_dependency "rubocop-performance", "~> 1.1" s.files = Dir.glob("{lib,exe}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) } diff --git a/lib/bundler.rb b/lib/bundler.rb index 0c24a21d7a..8ad5ab6634 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -197,19 +197,19 @@ module Bundler def user_bundle_path(dir = "home") env_var, fallback = case dir when "home" - ["BUNDLE_USER_HOME", Pathname.new(user_home).join(".bundle")] + ["BUNDLE_USER_HOME", proc { Pathname.new(user_home).join(".bundle") }] when "cache" - ["BUNDLE_USER_CACHE", user_bundle_path.join("cache")] + ["BUNDLE_USER_CACHE", proc { user_bundle_path.join("cache") }] when "config" - ["BUNDLE_USER_CONFIG", user_bundle_path.join("config")] + ["BUNDLE_USER_CONFIG", proc { user_bundle_path.join("config") }] when "plugin" - ["BUNDLE_USER_PLUGIN", user_bundle_path.join("plugin")] + ["BUNDLE_USER_PLUGIN", proc { user_bundle_path.join("plugin") }] else raise BundlerError, "Unknown user path requested: #{dir}" end # `fallback` will already be a Pathname, but Pathname.new() is # idempotent so it's OK - Pathname.new(ENV.fetch(env_var, fallback)) + Pathname.new(ENV.fetch(env_var, &fallback)) end def user_cache diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index 5ec541f722..cec7bcadb4 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -14,17 +14,18 @@ module Bundler Bundler.ui.info msg end - def self.output_without_groups_message + def self.output_without_groups_message(command) return if Bundler.settings[:without].empty? - Bundler.ui.confirm without_groups_message + Bundler.ui.confirm without_groups_message(command) end - def self.without_groups_message + def self.without_groups_message(command) + command_in_past_tense = command == :install ? "installed" : "updated" groups = Bundler.settings[:without] group_list = [groups[0...-1].join(", "), groups[-1..-1]]. reject {|s| s.to_s.empty? }.join(" and ") group_str = groups.size == 1 ? "group" : "groups" - "Gems in the #{group_str} #{group_list} were not installed." + "Gems in the #{group_str} #{group_list} were not #{command_in_past_tense}." end def self.select_spec(name, regex_match = nil) diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index 6fdd55d106..5dcf4a01ef 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -27,12 +27,7 @@ module Bundler if !Bundler.settings[:disable_exec_load] && ruby_shebang?(bin_path) return kernel_load(bin_path, *args) end - # First, try to exec directly to something in PATH - if Bundler.current_ruby.jruby_18? - kernel_exec(bin_path, *args) - else - kernel_exec([bin_path, cmd], *args) - end + kernel_exec(bin_path, *args) else # exec using the given command kernel_exec(cmd, *args) diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index cf0c71d766..d823fb632f 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -66,7 +66,7 @@ module Bundler Bundler.load.cache if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle? Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}." - Bundler::CLI::Common.output_without_groups_message + Bundler::CLI::Common.output_without_groups_message(:install) if Bundler.use_system_gems? Bundler.ui.confirm "Use `bundle info [gemname]` to see where a bundled gem is installed." diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 3a0521de1e..857caf0a03 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -133,7 +133,7 @@ module Bundler unless options[:parseable] if groups - Bundler.ui.info "===== Group #{groups} =====" + Bundler.ui.info "===== #{groups_text("Group", groups)} =====" else Bundler.ui.info "===== Without group =====" end @@ -167,6 +167,10 @@ module Bundler private + def groups_text(group_text, groups) + "#{group_text}#{groups.split(",").size > 1 ? "s" : ""} \"#{groups}\"" + end + def retrieve_active_spec(strict, definition, current_spec) if strict active_spec = definition.find_resolved_spec(current_spec) @@ -212,7 +216,7 @@ module Bundler elsif options_include_groups || !groups " * #{spec_outdated_info}" else - " * #{spec_outdated_info} in groups \"#{groups}\"" + " * #{spec_outdated_info} in #{groups_text("group", groups)}" end Bundler.ui.info output_message.rstrip diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb index 45d0374eef..60ea1c2a80 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -95,7 +95,7 @@ module Bundler end Bundler.ui.confirm "Bundle updated!" - Bundler::CLI::Common.output_without_groups_message + Bundler::CLI::Common.output_without_groups_message(:update) Bundler::CLI::Common.output_post_install_messages installer.post_install_messages end end diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 506b0620d2..81b362fed6 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -802,8 +802,10 @@ module Bundler deps2 = other.dependencies.select {|d| d.type != :development } runtime_dependencies = s.dependencies.select {|d| d.type != :development } - # If the dependencies of the path source have changed, unlock it - next unless runtime_dependencies.sort == deps2.sort + # If the dependencies of the path source have changed and locked spec can't satisfy new dependencies, unlock it + next unless deps2.sort == runtime_dependencies.sort || deps2.all? {|d| satisfies_locked_spec?(d) } + + s.dependencies.replace(other.dependencies) end converged << s diff --git a/lib/bundler/fetcher/downloader.rb b/lib/bundler/fetcher/downloader.rb index 2aeb9962c4..73f125af91 100644 --- a/lib/bundler/fetcher/downloader.rb +++ b/lib/bundler/fetcher/downloader.rb @@ -37,6 +37,7 @@ module Bundler when Net::HTTPTooManyRequests raise TooManyRequestsError, response.body when Net::HTTPUnauthorized + raise BadAuthenticationError, uri.host if uri.userinfo raise AuthenticationRequiredError, uri.host when Net::HTTPNotFound raise FallbackError, "Net::HTTPNotFound: #{URICredentialsFilter.credential_filtered_uri(uri)}" diff --git a/lib/bundler/fetcher/index.rb b/lib/bundler/fetcher/index.rb index e7baf63873..9beb0e27d8 100644 --- a/lib/bundler/fetcher/index.rb +++ b/lib/bundler/fetcher/index.rb @@ -13,6 +13,7 @@ module Bundler when /certificate verify failed/ raise CertificateFailureError.new(display_uri) when /401/ + raise BadAuthenticationError, remote_uri if remote_uri.userinfo raise AuthenticationRequiredError, remote_uri when /403/ raise BadAuthenticationError, remote_uri if remote_uri.userinfo diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index 45faf02020..b93ae68012 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -5,7 +5,7 @@ require_relative "vendored_thor" module Bundler module FriendlyErrors - module_function + module_function # rubocop:disable Layout/AccessModifierIndentation def log_error(error) case error diff --git a/lib/bundler/gem_version_promoter.rb b/lib/bundler/gem_version_promoter.rb index ed950ad28b..311b0cbbf3 100644 --- a/lib/bundler/gem_version_promoter.rb +++ b/lib/bundler/gem_version_promoter.rb @@ -81,8 +81,8 @@ module Bundler sort_dep_specs(spec_groups, locked_spec) end.tap do |specs| if DEBUG - STDERR.puts before_result - STDERR.puts " after sort_versions: #{debug_format_result(dep, specs).inspect}" + warn before_result + warn " after sort_versions: #{debug_format_result(dep, specs).inspect}" end end end diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index d3e5f268cf..c7caf01c7d 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -75,7 +75,7 @@ module Bundler return unless debug? debug_info = yield debug_info = debug_info.inspect unless debug_info.is_a?(String) - STDERR.puts debug_info.split("\n").map {|s| " " * depth + s } + warn debug_info.split("\n").map {|s| " " * depth + s } end def debug? diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index a0982f561f..e56a44a559 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -253,19 +253,6 @@ module Bundler current = File.expand_path(SharedHelpers.pwd).untaint until !File.directory?(current) || current == previous - if ENV["BUNDLE_SPEC_RUN"] - # avoid stepping above the tmp directory when testing - gemspec = if ENV["BUNDLE_RUBY"] && ENV["BUNDLE_GEM"] - # for Ruby Core - "lib/bundler/bundler.gemspec" - else - "bundler.gemspec" - end - - # avoid stepping above the tmp directory when testing - return nil if File.file?(File.join(current, gemspec)) - end - names.each do |name| filename = File.join(current, name) yield filename diff --git a/lib/bundler/uri_credentials_filter.rb b/lib/bundler/uri_credentials_filter.rb index ee3692268c..0f6ea4cefa 100644 --- a/lib/bundler/uri_credentials_filter.rb +++ b/lib/bundler/uri_credentials_filter.rb @@ -2,7 +2,7 @@ module Bundler module URICredentialsFilter - module_function + module_function # rubocop:disable Layout/AccessModifierIndentation def credential_filtered_uri(uri_to_anonymize) return uri_to_anonymize if uri_to_anonymize.nil? diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 374b3bb5e3..1965853931 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -3,7 +3,7 @@ module Bundler # A stub yaml serializer that can handle only hashes and strings (as of now). module YAMLSerializer - module_function + module_function # rubocop:disable Layout/AccessModifierIndentation def dump(hash) yaml = String.new("---") diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index e33c8dc606..9b772bffef 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -457,6 +457,7 @@ MESSAGE it "should use custom home path as root for other paths" do ENV["BUNDLE_USER_HOME"] = bundle_user_home_custom.to_s + allow(Bundler.rubygems).to receive(:user_home).and_raise expect(Bundler.user_bundle_path).to eq(bundle_user_home_custom) expect(Bundler.user_bundle_path("home")).to eq(bundle_user_home_custom) expect(Bundler.user_bundle_path("cache")).to eq(bundle_user_home_custom.join("cache")) diff --git a/spec/bundler/cli_spec.rb b/spec/bundler/cli_spec.rb index 2e12fbfc6b..eca911cc15 100644 --- a/spec/bundler/cli_spec.rb +++ b/spec/bundler/cli_spec.rb @@ -141,6 +141,7 @@ To install the latest version, run `gem install bundler` bundle! "config get --parseable foo" expect(last_command.stdboth).to eq "" + ensure_no_gemfile bundle "platform --ruby" expect(last_command.stdboth).to eq "Could not locate Gemfile" end diff --git a/spec/bundler/fetcher/downloader_spec.rb b/spec/bundler/fetcher/downloader_spec.rb index 07b507266b..f985b88982 100644 --- a/spec/bundler/fetcher/downloader_spec.rb +++ b/spec/bundler/fetcher/downloader_spec.rb @@ -82,6 +82,15 @@ RSpec.describe Bundler::Fetcher::Downloader do expect { subject.fetch(uri, options, counter) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError, /Authentication is required for www.uri-to-fetch.com/) end + + context "when the there are credentials provided in the request" do + let(:uri) { URI("http://user:password@www.uri-to-fetch.com") } + + it "should raise a Bundler::Fetcher::BadAuthenticationError that doesn't contain the password" do + expect { subject.fetch(uri, options, counter) }. + to raise_error(Bundler::Fetcher::BadAuthenticationError, /Bad username or password for www.uri-to-fetch.com/) + end + end end context "when the request response is a Net::HTTPNotFound" do diff --git a/spec/bundler/fetcher/index_spec.rb b/spec/bundler/fetcher/index_spec.rb index 0cf0ae764e..d5ededae3e 100644 --- a/spec/bundler/fetcher/index_spec.rb +++ b/spec/bundler/fetcher/index_spec.rb @@ -35,9 +35,26 @@ RSpec.describe Bundler::Fetcher::Index do context "when a 401 response occurs" do let(:error_message) { "401" } - it "should raise a Bundler::Fetcher::AuthenticationRequiredError" do - expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError, - %r{Authentication is required for http://remote-uri.org}) + before do + allow(remote_uri).to receive(:userinfo).and_return(userinfo) + end + + context "and there was userinfo" do + let(:userinfo) { double(:userinfo) } + + it "should raise a Bundler::Fetcher::BadAuthenticationError" do + expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::BadAuthenticationError, + %r{Bad username or password for http://remote-uri.org}) + end + end + + context "and there was no userinfo" do + let(:userinfo) { nil } + + it "should raise a Bundler::Fetcher::AuthenticationRequiredError" do + expect { subject.specs(gem_names) }.to raise_error(Bundler::Fetcher::AuthenticationRequiredError, + %r{Authentication is required for http://remote-uri.org}) + end end end diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb index 339428eb48..f105770c17 100644 --- a/spec/bundler/settings_spec.rb +++ b/spec/bundler/settings_spec.rb @@ -10,6 +10,7 @@ RSpec.describe Bundler::Settings do subject(:settings) { described_class.new(nil) } it "raises a GemfileNotFound error with explanation" do + ensure_no_gemfile expect { subject.set_local("foo", "bar") }. to raise_error(Bundler::GemfileNotFound, "Could not locate Gemfile") end diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb index f42d9ed485..7cd6aa7566 100644 --- a/spec/bundler/shared_helpers_spec.rb +++ b/spec/bundler/shared_helpers_spec.rb @@ -25,6 +25,7 @@ RSpec.describe Bundler::SharedHelpers do before { ENV["BUNDLE_GEMFILE"] = nil } it "raises a GemfileNotFound error" do + ensure_no_gemfile expect { subject.default_gemfile }.to raise_error( Bundler::GemfileNotFound, "Could not locate Gemfile" ) diff --git a/spec/commands/check_spec.rb b/spec/commands/check_spec.rb index cf88736612..d724ea79fa 100644 --- a/spec/commands/check_spec.rb +++ b/spec/commands/check_spec.rb @@ -199,6 +199,7 @@ RSpec.describe "bundle check" do end it "outputs an error when the default Gemfile is not found" do + ensure_no_gemfile bundle :check expect(exitstatus).to eq(10) if exitstatus expect(err).to include("Could not locate Gemfile") diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb index 40fab95803..abe31b1955 100644 --- a/spec/commands/config_spec.rb +++ b/spec/commands/config_spec.rb @@ -391,10 +391,10 @@ E describe "subcommands" do it "list", :ruby_repo do bundle! "config list" - expect(out).to eq "Settings are listed in order of priority. The top value will be used.\nspec_run\nSet via BUNDLE_SPEC_RUN: \"true\"" + expect(out).to eq "Settings are listed in order of priority. The top value will be used." bundle! "config list", :parseable => true - expect(out).to eq "spec_run=true" + expect(out).to be_empty end it "get" do diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 24aa5f46fe..39e27e94f2 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -55,6 +55,17 @@ RSpec.describe "bundle exec" do expect(out).to eq("hi") end + it "respects custom process title when loading through ruby" do + script_that_changes_its_own_title_and_checks_if_picked_up_by_ps_unix_utility = <<~RUBY + Process.setproctitle("1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16") + puts `ps -eo args | grep [1]-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16` + RUBY + create_file "Gemfile" + create_file "a.rb", script_that_changes_its_own_title_and_checks_if_picked_up_by_ps_unix_utility + bundle "exec ruby a.rb" + expect(out).to eq("1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16") + end + it "accepts --verbose" do install_gemfile 'gem "rack"' bundle "exec --verbose echo foobar" diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index 843bebf6e0..f0c2927218 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -59,15 +59,19 @@ RSpec.describe "bundle outdated" do install_gemfile <<-G source "file://#{gem_repo2}" + gem "terranova", '8' + group :development, :test do gem 'activesupport', '2.3.5' end G update_repo2 { build_gem "activesupport", "3.0" } + update_repo2 { build_gem "terranova", "9" } bundle "outdated --verbose" expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5) in groups \"development, test\"") + expect(out).to include("terranova (newest 9, installed 8, requested = 8) in group \"default\"") end end @@ -117,10 +121,10 @@ RSpec.describe "bundle outdated" do it "returns a sorted list of outdated gems from one group => 'default'" do test_group_option("default") - expect(out).to include("===== Group default =====") + expect(out).to include("===== Group \"default\" =====") expect(out).to include("terranova (") - expect(out).not_to include("===== Group development, test =====") + expect(out).not_to include("===== Groups \"development, test\" =====") expect(out).not_to include("activesupport") expect(out).not_to include("duradura") end @@ -128,10 +132,10 @@ RSpec.describe "bundle outdated" do it "returns a sorted list of outdated gems from one group => 'development'" do test_group_option("development", 2) - expect(out).not_to include("===== Group default =====") + expect(out).not_to include("===== Group \"default\" =====") expect(out).not_to include("terranova (") - expect(out).to include("===== Group development, test =====") + expect(out).to include("===== Groups \"development, test\" =====") expect(out).to include("activesupport") expect(out).to include("duradura") end @@ -139,10 +143,10 @@ RSpec.describe "bundle outdated" do it "returns a sorted list of outdated gems from one group => 'test'" do test_group_option("test", 2) - expect(out).not_to include("===== Group default =====") + expect(out).not_to include("===== Group \"default\" =====") expect(out).not_to include("terranova (") - expect(out).to include("===== Group development, test =====") + expect(out).to include("===== Groups \"development, test\" =====") expect(out).to include("activesupport") expect(out).to include("duradura") end @@ -184,9 +188,9 @@ RSpec.describe "bundle outdated" do end bundle "outdated --groups" - expect(out).to include("===== Group default =====") + expect(out).to include("===== Group \"default\" =====") expect(out).to include("terranova (newest 9, installed 8, requested = 8)") - expect(out).to include("===== Group development, test =====") + expect(out).to include("===== Groups \"development, test\" =====") expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5)") expect(out).to include("duradura (newest 8.0, installed 7.0, requested = 7.0)") diff --git a/spec/install/post_bundle_message_spec.rb b/spec/commands/post_bundle_message_spec.rb index 1efd0b8146..4d3aa7b450 100644 --- a/spec/install/post_bundle_message_spec.rb +++ b/spec/commands/post_bundle_message_spec.rb @@ -185,21 +185,21 @@ The source does not contain any versions of 'not-a-gem' it "with --without one group" do bundle! :install, forgotten_command_line_options(:without => "emo") bundle! :update, :all => true - expect(out).to include("Gems in the group emo were not installed") + expect(out).to include("Gems in the group emo were not updated") expect(out).to include(bundle_updated_message) end it "with --without two groups" do bundle! :install, forgotten_command_line_options(:without => "emo test") bundle! :update, :all => true - expect(out).to include("Gems in the groups emo and test were not installed") + expect(out).to include("Gems in the groups emo and test were not updated") expect(out).to include(bundle_updated_message) end it "with --without more groups" do bundle! :install, forgotten_command_line_options(:without => "emo obama test") bundle! :update, :all => true - expect(out).to include("Gems in the groups emo, obama and test were not installed") + expect(out).to include("Gems in the groups emo, obama and test were not updated") expect(out).to include(bundle_updated_message) end end diff --git a/spec/install/gemfile/path_spec.rb b/spec/install/gemfile/path_spec.rb index c6856ac974..e80764070c 100644 --- a/spec/install/gemfile/path_spec.rb +++ b/spec/install/gemfile/path_spec.rb @@ -484,6 +484,68 @@ RSpec.describe "bundle install with explicit source paths" do expect(the_bundle).to include_gems "rack 1.0.0" end + + it "keeps using the same version if it's compatible" do + build_lib "foo", "1.0", :path => lib_path("foo") do |s| + s.add_dependency "rack", "0.9.1" + end + + bundle "install" + + expect(the_bundle).to include_gems "rack 0.9.1" + + lockfile_should_be <<-G + PATH + remote: #{lib_path("foo")} + specs: + foo (1.0) + rack (= 0.9.1) + + GEM + remote: #{URI.parse("file://#{gem_repo1}/")} + specs: + rack (0.9.1) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + foo! + + BUNDLED WITH + #{Bundler::VERSION} + G + + build_lib "foo", "1.0", :path => lib_path("foo") do |s| + s.add_dependency "rack" + end + + bundle "install" + + lockfile_should_be <<-G + PATH + remote: #{lib_path("foo")} + specs: + foo (1.0) + rack + + GEM + remote: #{URI.parse("file://#{gem_repo1}/")} + specs: + rack (0.9.1) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + foo! + + BUNDLED WITH + #{Bundler::VERSION} + G + + expect(the_bundle).to include_gems "rack 0.9.1" + end end describe "switching sources" do diff --git a/spec/other/cli_dispatch_spec.rb b/spec/other/cli_dispatch_spec.rb index 548539ac89..1d4489acc3 100644 --- a/spec/other/cli_dispatch_spec.rb +++ b/spec/other/cli_dispatch_spec.rb @@ -2,12 +2,14 @@ RSpec.describe "bundle command names" do it "work when given fully" do + ensure_no_gemfile bundle "install" expect(err).to eq("Could not locate Gemfile") expect(last_command.stdboth).not_to include("Ambiguous command") end it "work when not ambiguous" do + ensure_no_gemfile bundle "ins" expect(err).to eq("Could not locate Gemfile") expect(last_command.stdboth).not_to include("Ambiguous command") diff --git a/spec/realworld/gemfile_source_header_spec.rb b/spec/realworld/gemfile_source_header_spec.rb index eaefd0f03e..382485b8fc 100644 --- a/spec/realworld/gemfile_source_header_spec.rb +++ b/spec/realworld/gemfile_source_header_spec.rb @@ -28,7 +28,7 @@ RSpec.describe "fetching dependencies with a mirrored source", :realworld => tru expect(the_bundle).to include_gems "weakling 0.0.3" end - private +private def setup_server require_rack diff --git a/spec/runtime/load_spec.rb b/spec/runtime/load_spec.rb index b74dbde3f6..05ed076b6d 100644 --- a/spec/runtime/load_spec.rb +++ b/spec/runtime/load_spec.rb @@ -45,6 +45,7 @@ RSpec.describe "Bundler.load" do describe "without a gemfile" do it "raises an exception if the default gemfile is not found" do + ensure_no_gemfile expect do Bundler.load end.to raise_error(Bundler::GemfileNotFound, /could not locate gemfile/i) @@ -56,19 +57,6 @@ RSpec.describe "Bundler.load" do Bundler.load end.to raise_error(Bundler::GemfileNotFound, /omg\.rb/) end - - it "does not find a Gemfile above the testing directory" do - bundler_gemfile = tmp.join("../Gemfile") - unless File.exist?(bundler_gemfile) - FileUtils.touch(bundler_gemfile) - @remove_bundler_gemfile = true - end - begin - expect { Bundler.load }.to raise_error(Bundler::GemfileNotFound) - ensure - bundler_gemfile.rmtree if @remove_bundler_gemfile - end - end end describe "when called twice" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 35cf8bfefb..ba7b362b5b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,7 +25,6 @@ $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" diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 478fe60822..0567b26c01 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -313,6 +313,12 @@ module Spec bundle :lock, opts end + # Makes tests that require absence of any Gemfiles pass, even if the running + # system has a Gemfile further up from the specs folder + def ensure_no_gemfile + allow(Bundler::SharedHelpers).to receive(:search_up).and_return(nil) + end + def install_gems(*gems) options = gems.last.is_a?(Hash) ? gems.pop : {} gem_repo = options.fetch(:gem_repo) { gem_repo1 } |