diff options
Diffstat (limited to 'spec')
121 files changed, 2678 insertions, 1959 deletions
diff --git a/spec/bundler/bundler/bundler_spec.rb b/spec/bundler/bundler/bundler_spec.rb index 247838600b..56ef4ce75a 100644 --- a/spec/bundler/bundler/bundler_spec.rb +++ b/spec/bundler/bundler/bundler_spec.rb @@ -124,7 +124,15 @@ RSpec.describe Bundler do describe "#which" do let(:executable) { "executable" } - let(:path) { %w[/a /b c ../d /e] } + + let(:path) do + if Gem.win_platform? + %w[C:/a C:/b C:/c C:/../d C:/e] + else + %w[/a /b c ../d /e] + end + end + let(:expected) { "executable" } before do @@ -149,7 +157,13 @@ RSpec.describe Bundler do it_behaves_like "it returns the correct executable" context "when the executable in inside a quoted path" do - let(:expected) { "/e/executable" } + let(:expected) do + if Gem.win_platform? + "C:/e/executable" + else + "/e/executable" + end + end it_behaves_like "it returns the correct executable" end @@ -196,6 +210,8 @@ EOF gem "rack" G + allow(Bundler).to receive(:root).and_return(bundled_app) + Bundler.mkdir_p(bundled_app.join("foo", "bar")) expect(bundled_app.join("foo", "bar")).to exist end @@ -322,7 +338,7 @@ EOF end context "with unwritable files in a parent dir" do - # Regression test for https://github.com/bundler/bundler/pull/6316 + # Regression test for https://github.com/rubygems/bundler/pull/6316 # It doesn't matter if there are other unwritable files so long as # bundle_path can be created before do diff --git a/spec/bundler/bundler/cli_spec.rb b/spec/bundler/bundler/cli_spec.rb index ddcd699d6c..a56e148e89 100644 --- a/spec/bundler/bundler/cli_spec.rb +++ b/spec/bundler/bundler/cli_spec.rb @@ -14,6 +14,8 @@ RSpec.describe "bundle executable" do end it "looks for a binary and executes it if it's named bundler-<task>" do + skip "obscure error" if Gem.win_platform? + File.open(tmp("bundler-testtasks"), "w", 0o755) do |f| ruby = ENV["RUBY"] || "/usr/bin/env ruby" f.puts "#!#{ruby}\nputs 'Hello, world'\n" @@ -91,7 +93,7 @@ RSpec.describe "bundle executable" do context "when ENV['BUNDLE_GEMFILE'] is set to an empty string" do it "ignores it" do - gemfile bundled_app("Gemfile"), <<-G + gemfile bundled_app_gemfile, <<-G source "#{file_uri_for(gem_repo1)}" gem 'rack' G @@ -104,7 +106,7 @@ RSpec.describe "bundle executable" do context "when ENV['RUBYGEMS_GEMDEPS'] is set" do it "displays a warning" do - gemfile bundled_app("Gemfile"), <<-G + gemfile bundled_app_gemfile, <<-G source "#{file_uri_for(gem_repo1)}" gem 'rack' G @@ -149,7 +151,7 @@ RSpec.describe "bundle executable" do before do bundle! "config set --global disable_version_check false" - simulate_bundler_version(bundler_version) + system_gems "bundler-#{bundler_version}" if latest_version info_path = home(".bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/info/bundler") info_path.parent.mkpath @@ -174,7 +176,7 @@ RSpec.describe "bundle executable" do context "when the latest version is greater than the current version" do let(:latest_version) { "222.0" } it "prints the version warning" do - bundle "fail" + bundle "fail", :system_bundler => true, :env => { "BUNDLER_SPEC_IGNORE_DEFAULT_BUNDLER_GEM" => "true" } expect(err).to start_with(<<-EOS.strip) The latest bundler is #{latest_version}, but you are currently running #{bundler_version}. To install the latest version, run `gem install bundler` @@ -199,7 +201,7 @@ To install the latest version, run `gem install bundler` context "and is a pre-release" do let(:latest_version) { "222.0.0.pre.4" } it "prints the version warning" do - bundle "fail" + bundle "fail", :system_bundler => true, :env => { "BUNDLER_SPEC_IGNORE_DEFAULT_BUNDLER_GEM" => "true" } expect(err).to start_with(<<-EOS.strip) The latest bundler is #{latest_version}, but you are currently running #{bundler_version}. To install the latest version, run `gem install bundler --pre` diff --git a/spec/bundler/bundler/compact_index_client/gem_parser_spec.rb b/spec/bundler/bundler/compact_index_client/gem_parser_spec.rb new file mode 100644 index 0000000000..5f5305426f --- /dev/null +++ b/spec/bundler/bundler/compact_index_client/gem_parser_spec.rb @@ -0,0 +1,174 @@ +# frozen_string_literal: true + +require "bundler/compact_index_client/gem_parser" + +RSpec.describe Bundler::CompactIndexClient::GemParser do + def parse(line) + parser = Bundler::CompactIndexClient::GemParser.new + parser.parse(line) + end + + context "platform" do + it "existent" do + checksum = "d5956d2bcb509af2cd07c90d9e5fdb331be8845a75bfd823a31c147b52cff471" + line = "1.11.3-java |checksum:#{checksum}" + expected = [ + "1.11.3", + "java", + [], + [ + ["checksum", [checksum]], + ], + ] + expect(parse(line)).to eq expected + end + + it "nonexistent" do + checksum = "6da2eb3c4867e64df28d3e0b1008422dfacda7c046f9a8f3c56c52505b195e81" + line = "1.11.3 |checksum:#{checksum}" + expected = [ + "1.11.3", + nil, + [], + [ + ["checksum", [checksum]], + ], + ] + expect(parse(line)).to eq expected + end + end + + context "dependencies" do + it "nothing" do + checksum = "6da2eb3c4867e64df28d3e0b1008422dfacda7c046f9a8f3c56c52505b195e81" + line = "1.11.3 |checksum:#{checksum}" + expected = [ + "1.11.3", + nil, + [], + [ + ["checksum", [checksum]], + ], + ] + expect(parse(line)).to eq expected + end + + it "one" do + checksum = "5f0b378d12ab5665e2b6a1525274de97350238963002583cf088dae988527647" + line = "0.3.2 bones:>= 2.4.2|checksum:#{checksum}" + expected = [ + "0.3.2", + nil, + [ + ["bones", [">= 2.4.2"]], + ], + [ + ["checksum", [checksum]], + ], + ] + expect(parse(line)).to eq expected + end + + it "multiple" do + checksum = "199e892ada86c44d1f2e110b822d5da46b52fa2cbd2f00d89695b4cf610f9927" + line = "3.1.2 native-package-installer:>= 0,pkg-config:>= 0|checksum:#{checksum}" + expected = [ + "3.1.2", + nil, + [ + ["native-package-installer", [">= 0"]], + ["pkg-config", [">= 0"]], + ], + [ + ["checksum", [checksum]], + ], + ] + expect(parse(line)).to eq expected + end + + context "version" do + it "multiple" do + checksum = "1ec894b8090cb2c9393153552be2f3b6b1975265cbc1e0a3c6b28ebfea7e76a1" + line = "3.1.5 multi_json:< 1.3&>= 1.0|checksum:#{checksum}" + expected = [ + "3.1.5", + nil, + [ + ["multi_json", ["< 1.3", ">= 1.0"]], + ], + [ + ["checksum", [checksum]], + ], + ] + expect(parse(line)).to eq expected + end + end + end + + context "requirements" do + context "ruby" do + it "one version" do + checksum ="6da2eb3c4867e64df28d3e0b1008422dfacda7c046f9a8f3c56c52505b195e81" + line = "1.11.3 |checksum:#{checksum},ruby:>= 2.0" + expected = [ + "1.11.3", + nil, + [], + [ + ["checksum", [checksum]], + ["ruby", [">= 2.0"]], + ], + ] + expect(parse(line)).to eq expected + end + + it "multiple versions" do + checksum = "99e4845796c8dec1c3fc80dc772860a01633b33291bd7534007f5c7724f0b876" + line = "1.11.3-x86-mingw32 |checksum:#{checksum},ruby:>= 2.2, < 2.7.dev" + expected = [ + "1.11.3", + "x86-mingw32", + [], + [ + ["checksum", [checksum]], + ["ruby", [">= 2.2", "< 2.7.dev"]], + ], + ] + expect(parse(line)).to eq expected + end + + it "with rubygems" do + checksum = "7a82b358f00da749b01f8c84df8e8eb21c1bc389740aab9a2bf4ce59894564ac" + line = "1.9.23.pre1 |checksum:#{checksum},ruby:>= 1.9, < 2.7.dev,rubygems:> 1.3.1" + expected = [ + "1.9.23.pre1", + nil, + [], + [ + ["checksum", [checksum]], + ["ruby", [">= 1.9", "< 2.7.dev"]], + ["rubygems", ["> 1.3.1"]], + ], + ] + expect(parse(line)).to eq expected + end + end + + context "rubygems" do + it "existent" do + checksum = "91ddb4c1b5482a4aff957f6733e282ce2767b2d3051138e0203e39d6df4eba10" + line = "1.0.12.pre |checksum:#{checksum},rubygems:> 1.3.1" + expected = [ + "1.0.12.pre", + nil, + [], + [ + ["checksum", [checksum]], + ["rubygems", ["> 1.3.1"]], + ], + ] + expect(parse(line)).to eq expected + end + end + end +end diff --git a/spec/bundler/bundler/compact_index_client/updater_spec.rb b/spec/bundler/bundler/compact_index_client/updater_spec.rb index fd554a7b0d..26159dccd8 100644 --- a/spec/bundler/bundler/compact_index_client/updater_spec.rb +++ b/spec/bundler/bundler/compact_index_client/updater_spec.rb @@ -9,10 +9,10 @@ RSpec.describe Bundler::CompactIndexClient::Updater do let(:local_path) { Pathname("/tmp/localpath") } let(:remote_path) { double(:remote_path) } - subject(:updater) { described_class.new(fetcher) } + let!(:updater) { described_class.new(fetcher) } context "when the ETag header is missing" do - # Regression test for https://github.com/bundler/bundler/issues/5463 + # Regression test for https://github.com/rubygems/bundler/issues/5463 let(:response) { double(:response, :body => "") } @@ -42,8 +42,6 @@ RSpec.describe Bundler::CompactIndexClient::Updater do end context "when bundler doesn't have permissions on Dir.tmpdir" do - let(:response) { double(:response, :body => "") } - it "Errno::EACCES is raised" do allow(Dir).to receive(:mktmpdir) { raise Errno::EACCES } diff --git a/spec/bundler/bundler/definition_spec.rb b/spec/bundler/bundler/definition_spec.rb index 1f4c1a0807..d0ebb37933 100644 --- a/spec/bundler/bundler/definition_spec.rb +++ b/spec/bundler/bundler/definition_spec.rb @@ -210,10 +210,12 @@ RSpec.describe Bundler::Definition do source "#{file_uri_for(gem_repo1)}" gem "foo" G + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end it "should get a locked specs list when updating all" do - definition = Bundler::Definition.new(bundled_app("Gemfile.lock"), [], Bundler::SourceList.new, true) + definition = Bundler::Definition.new(bundled_app_lock, [], Bundler::SourceList.new, true) locked_specs = definition.gem_version_promoter.locked_specs expect(locked_specs.to_a.map(&:name)).to eq ["foo"] expect(definition.instance_variable_get("@locked_specs").empty?).to eq true @@ -267,6 +269,8 @@ RSpec.describe Bundler::Definition do BUNDLED WITH 1.13.0 L + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end it "should not eagerly unlock shared dependency with bundle install conservative updating behavior" do @@ -275,7 +279,7 @@ RSpec.describe Bundler::Definition do Bundler::Dependency.new("shared_owner_b", ">= 0")] unlock_hash_for_bundle_install = {} definition = Bundler::Definition.new( - bundled_app("Gemfile.lock"), + bundled_app_lock, updated_deps_in_gemfile, source_list, unlock_hash_for_bundle_install @@ -289,7 +293,7 @@ RSpec.describe Bundler::Definition do Bundler::Dependency.new("shared_owner_a", ">= 0"), Bundler::Dependency.new("shared_owner_b", ">= 0")] definition = Bundler::Definition.new( - bundled_app("Gemfile.lock"), + bundled_app_lock, updated_deps_in_gemfile, source_list, :gems => ["shared_owner_a"], :lock_shared_dependencies => true diff --git a/spec/bundler/bundler/dsl_spec.rb b/spec/bundler/bundler/dsl_spec.rb index 40739a431b..9299c014af 100644 --- a/spec/bundler/bundler/dsl_spec.rb +++ b/spec/bundler/bundler/dsl_spec.rb @@ -72,7 +72,7 @@ RSpec.describe Bundler::Dsl do describe "#method_missing" do it "raises an error for unknown DSL methods" do - expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s). + expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s). and_return("unknown") error_msg = "There was an error parsing `Gemfile`: Undefined local variable or method `unknown' for Gemfile. Bundler cannot continue." @@ -83,13 +83,13 @@ RSpec.describe Bundler::Dsl do describe "#eval_gemfile" do it "handles syntax errors with a useful message" do - expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s).and_return("}") + expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).and_return("}") expect { subject.eval_gemfile("Gemfile") }. to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: (syntax error, unexpected tSTRING_DEND|(compile error - )?syntax error, unexpected '\}'). Bundler cannot continue./) end it "distinguishes syntax errors from evaluation errors" do - expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s).and_return( + expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).and_return( "ruby '2.1.5', :engine => 'ruby', :engine_version => '1.2.4'" ) expect { subject.eval_gemfile("Gemfile") }. @@ -174,40 +174,6 @@ RSpec.describe Bundler::Dsl do end end - describe "#gemspec" do - let(:spec) do - Gem::Specification.new do |gem| - gem.name = "example" - gem.platform = platform - end - end - - before do - allow(Dir).to receive(:[]).and_return(["spec_path"]) - allow(Bundler).to receive(:load_gemspec).with("spec_path").and_return(spec) - allow(Bundler).to receive(:default_gemfile).and_return(Pathname.new("./Gemfile")) - end - - context "with a ruby platform" do - let(:platform) { "ruby" } - - it "keeps track of the ruby platforms in the dependency" do - subject.gemspec - expect(subject.dependencies.last.platforms).to eq(Bundler::Dependency::REVERSE_PLATFORM_MAP[Gem::Platform::RUBY]) - end - end - - context "with a jruby platform" do - let(:platform) { "java" } - - it "keeps track of the jruby platforms in the dependency" do - allow(Gem::Platform).to receive(:local).and_return(java) - subject.gemspec - expect(subject.dependencies.last.platforms).to eq(Bundler::Dependency::REVERSE_PLATFORM_MAP[Gem::Platform::JAVA]) - end - end - end - context "can bundle groups of gems with" do # git "https://github.com/rails/rails.git" do # gem "railties" @@ -270,7 +236,7 @@ RSpec.describe Bundler::Dsl do describe "syntax errors" do it "will raise a Bundler::GemfileError" do gemfile "gem 'foo', :path => /unquoted/string/syntax/error" - expect { Bundler::Dsl.evaluate(bundled_app("Gemfile"), nil, true) }. + expect { Bundler::Dsl.evaluate(bundled_app_gemfile, nil, true) }. to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`:( compile error -)? unknown regexp options - trg.+ Bundler cannot continue./) end end @@ -278,7 +244,7 @@ RSpec.describe Bundler::Dsl do describe "Runtime errors" do it "will raise a Bundler::GemfileError" do gemfile "raise RuntimeError, 'foo'" - expect { Bundler::Dsl.evaluate(bundled_app("Gemfile"), nil, true) }. + expect { Bundler::Dsl.evaluate(bundled_app_gemfile, nil, true) }. to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: foo. Bundler cannot continue./i) end end diff --git a/spec/bundler/bundler/env_spec.rb b/spec/bundler/bundler/env_spec.rb index 9631a109bd..fb593639bd 100644 --- a/spec/bundler/bundler/env_spec.rb +++ b/spec/bundler/bundler/env_spec.rb @@ -34,6 +34,8 @@ RSpec.describe Bundler::Env do end it "prints user home" do + skip "needs to use a valid HOME" if Gem.win_platform? && RUBY_VERSION < "2.6.0" + with_clear_paths("HOME", "/a/b/c") do out = described_class.report expect(out).to include("User Home /a/b/c") @@ -41,15 +43,13 @@ RSpec.describe Bundler::Env do end it "prints user path" do - if Gem::VERSION >= "3.2.0.pre.1" - allow(Gem).to receive(:data_home) { "/a/b/c/.local/share" } + skip "needs to use a valid HOME" if Gem.win_platform? && RUBY_VERSION < "2.6.0" + + with_clear_paths("HOME", "/a/b/c") do + allow(File).to receive(:exist?) + allow(File).to receive(:exist?).with("/a/b/c/.gem").and_return(true) out = described_class.report - expect(out).to include("User Path /a/b/c/.local/share/gem") - else - with_clear_paths("HOME", "/a/b/c") do - out = described_class.report - expect(out).to include("User Path /a/b/c/.gem") - end + expect(out).to include("User Path /a/b/c/.gem") end end @@ -88,6 +88,8 @@ RSpec.describe Bundler::Env do BUNDLED WITH 1.10.0 L + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end let(:output) { described_class.report(:print_gemfile => true) } @@ -127,6 +129,8 @@ RSpec.describe Bundler::Env do File.open(bundled_app.join("foo.gemspec"), "wb") do |f| f.write(gemspec) end + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end it "prints the gemspec" do @@ -139,13 +143,15 @@ RSpec.describe Bundler::Env do context "when eval_gemfile is used" do it "prints all gemfiles" do - create_file "other/Gemfile-other", "gem 'rack'" - create_file "other/Gemfile", "eval_gemfile 'Gemfile-other'" - create_file "Gemfile-alt", <<-G + create_file bundled_app("other/Gemfile-other"), "gem 'rack'" + create_file bundled_app("other/Gemfile"), "eval_gemfile 'Gemfile-other'" + create_file bundled_app("Gemfile-alt"), <<-G source "#{file_uri_for(gem_repo1)}" eval_gemfile "other/Gemfile" G - gemfile "eval_gemfile #{File.expand_path("Gemfile-alt").dump}" + gemfile "eval_gemfile #{bundled_app("Gemfile-alt").to_s.dump}" + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) output = described_class.report(:print_gemspecs => true) expect(output).to include(strip_whitespace(<<-ENV)) @@ -154,7 +160,7 @@ RSpec.describe Bundler::Env do ### Gemfile ```ruby - eval_gemfile #{File.expand_path("Gemfile-alt").dump} + eval_gemfile #{bundled_app("Gemfile-alt").to_s.dump} ``` ### Gemfile-alt @@ -179,7 +185,7 @@ RSpec.describe Bundler::Env do ### Gemfile.lock ``` - <No #{bundled_app("Gemfile.lock")} found> + <No #{bundled_app_lock} found> ``` ENV end diff --git a/spec/bundler/bundler/fetcher/compact_index_spec.rb b/spec/bundler/bundler/fetcher/compact_index_spec.rb index c9419d3eb1..b00eadceab 100644 --- a/spec/bundler/bundler/fetcher/compact_index_spec.rb +++ b/spec/bundler/bundler/fetcher/compact_index_spec.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +# load CompactIndexClient upfront to prevent thread safety issues during parallel specs +require "bundler/compact_index_client" + RSpec.describe Bundler::Fetcher::CompactIndex do let(:downloader) { double(:downloader) } let(:display_uri) { Bundler::URI("http://sampleuri.com") } diff --git a/spec/bundler/bundler/fetcher_spec.rb b/spec/bundler/bundler/fetcher_spec.rb index 539179db43..256d342775 100644 --- a/spec/bundler/bundler/fetcher_spec.rb +++ b/spec/bundler/bundler/fetcher_spec.rb @@ -150,9 +150,10 @@ RSpec.describe Bundler::Fetcher do end it "from many CI" do - with_env_vars("TRAVIS" => "foo", "CI_NAME" => "my_ci") do + with_env_vars("TRAVIS" => "foo", "GITLAB_CI" => "gitlab", "CI_NAME" => "my_ci") do ci_part = fetcher.user_agent.split(" ").find {|x| x.start_with?("ci/") } expect(ci_part).to match("travis") + expect(ci_part).to match("gitlab") expect(ci_part).to match("my_ci") end end diff --git a/spec/bundler/bundler/friendly_errors_spec.rb b/spec/bundler/bundler/friendly_errors_spec.rb index dc9d539a30..747d774b25 100644 --- a/spec/bundler/bundler/friendly_errors_spec.rb +++ b/spec/bundler/bundler/friendly_errors_spec.rb @@ -6,59 +6,26 @@ require "cgi" RSpec.describe Bundler, "friendly errors" do context "with invalid YAML in .gemrc" do - context "with the old ~/.gemrc" do - before do - File.open(home(".gemrc"), "w") do |f| - f.write "invalid: yaml: hah" - end - end - - after do - FileUtils.rm(home(".gemrc")) - end - - it "reports a relevant friendly error message" do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G - - bundle :install, :env => { "DEBUG" => "true" } - - expect(err).to include("Failed to load #{home(".gemrc")}") - expect(exitstatus).to eq(0) if exitstatus + before do + File.open(home(".gemrc"), "w") do |f| + f.write "invalid: yaml: hah" end end - context "with XDG_CONFIG_HOME" do - let(:config_home) { File.dirname(Gem.configuration.config_file_name) } - - before do - FileUtils.mkdir_p config_home - File.open(Gem.configuration.config_file_name, "w") do |f| - f.write "invalid: yaml: hah" - end - end - - after do - FileUtils.rm(Gem.configuration.config_file_name) - end + after do + FileUtils.rm(home(".gemrc")) + end - it "reports a relevant friendly error message" do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G + it "reports a relevant friendly error message" do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G - bundle :install, :env => { "DEBUG" => "true" } + bundle :install, :env => { "DEBUG" => "true" } - if Gem::VERSION >= "3.2.0.pre.1" - expect(err).to include("Failed to load #{File.join(config_home, "gemrc")}") - else - expect(err).to include("Failed to load #{home(".gemrc")}") - end - expect(exitstatus).to eq(0) if exitstatus - end + expect(err).to include("Failed to load #{home(".gemrc")}") + expect(exitstatus).to eq(0) if exitstatus end end @@ -148,18 +115,12 @@ RSpec.describe Bundler, "friendly errors" do context "LoadError" do let(:error) { LoadError.new("cannot load such file -- openssl") } - it "Bundler.ui receive error" do - expect(Bundler.ui).to receive(:error).with("\nCould not load OpenSSL.") - Bundler::FriendlyErrors.log_error(error) - end - - it "Bundler.ui receive warn" do - expect(Bundler.ui).to receive(:warn).with(any_args, :wrap => true) - Bundler::FriendlyErrors.log_error(error) + before do + allow(error).to receive(:backtrace).and_return(["backtrace"]) end - it "Bundler.ui receive trace" do - expect(Bundler.ui).to receive(:trace).with(error) + it "Bundler.ui receive error" do + expect(Bundler.ui).to receive(:error).with("\nCould not load OpenSSL. LoadError: cannot load such file -- openssl\nbacktrace") Bundler::FriendlyErrors.log_error(error) end end @@ -254,7 +215,7 @@ RSpec.describe Bundler, "friendly errors" do it "generates a search URL for the exception message" do exception = Exception.new("Exception message") - expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/bundler/bundler/search?q=Exception+message&type=Issues") + expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/rubygems/bundler/search?q=Exception+message&type=Issues") end it "generates a search URL for only the first line of a multi-line exception message" do @@ -263,7 +224,7 @@ First line of the exception message Second line of the exception message END - expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/bundler/bundler/search?q=First+line+of+the+exception+message&type=Issues") + expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/rubygems/bundler/search?q=First+line+of+the+exception+message&type=Issues") end it "generates the url without colons" do @@ -272,7 +233,7 @@ Exception ::: with ::: colons ::: END issues_url = Bundler::FriendlyErrors.issues_url(exception) expect(issues_url).not_to include("%3A") - expect(issues_url).to eq("https://github.com/bundler/bundler/search?q=#{CGI.escape("Exception with colons ")}&type=Issues") + expect(issues_url).to eq("https://github.com/rubygems/bundler/search?q=#{CGI.escape("Exception with colons ")}&type=Issues") end it "removes information after - for Errono::EACCES" do @@ -282,7 +243,7 @@ END allow(exception).to receive(:is_a?).with(Errno).and_return(true) issues_url = Bundler::FriendlyErrors.issues_url(exception) expect(issues_url).not_to include("/Users/foo/bar") - expect(issues_url).to eq("https://github.com/bundler/bundler/search?q=#{CGI.escape("Errno EACCES Permission denied @ dir_s_mkdir ")}&type=Issues") + expect(issues_url).to eq("https://github.com/rubygems/bundler/search?q=#{CGI.escape("Errno EACCES Permission denied @ dir_s_mkdir ")}&type=Issues") end end end diff --git a/spec/bundler/bundler/gem_helper_spec.rb b/spec/bundler/bundler/gem_helper_spec.rb index 29e10d64f8..548425b11e 100644 --- a/spec/bundler/bundler/gem_helper_spec.rb +++ b/spec/bundler/bundler/gem_helper_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Bundler::GemHelper do let(:app_gemspec_path) { app_path.join("#{app_name}.gemspec") } before(:each) do - global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false" + global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false", "BUNDLE_GEM__RUBOCOP" => "false" bundle "gem #{app_name}" prepare_gemspec(app_gemspec_path) end @@ -138,6 +138,26 @@ RSpec.describe Bundler::GemHelper do expect(app_gem_path).to exist end end + + context "when building in the current working directory" do + it "creates .gem file" do + mock_build_message app_name, app_version + Dir.chdir app_path do + Bundler::GemHelper.new.build_gem + end + expect(app_gem_path).to exist + end + end + + context "when building in a location relative to the current working directory" do + it "creates .gem file" do + mock_build_message app_name, app_version + Dir.chdir File.dirname(app_path) do + Bundler::GemHelper.new(File.basename(app_path)).build_gem + end + expect(app_gem_path).to exist + end + end end describe "#install_gem" do @@ -178,13 +198,11 @@ RSpec.describe Bundler::GemHelper do end before do - Dir.chdir(app_path) do - `git init` - `git config user.email "[email protected]"` - `git config user.name "name"` - `git config commit.gpgsign false` - `git config push.default simple` - end + sys_exec("git init", :dir => app_path) + sys_exec("git config user.email \"[email protected]\"", :dir => app_path) + sys_exec("git config user.name \"name\"", :dir => app_path) + sys_exec("git config commit.gpgsign false", :dir => app_path) + sys_exec("git config push.default simple", :dir => app_path) # silence messages allow(Bundler.ui).to receive(:confirm) @@ -198,13 +216,13 @@ RSpec.describe Bundler::GemHelper do end it "when there are uncommitted files" do - Dir.chdir(app_path) { `git add .` } + sys_exec("git add .", :dir => app_path) expect { Rake.application["release"].invoke }. to raise_error("There are files that need to be committed first.") end it "when there is no git remote" do - Dir.chdir(app_path) { `git commit -a -m "initial commit"` } + sys_exec("git commit -a -m \"initial commit\"", :dir => app_path) expect { Rake.application["release"].invoke }.to raise_error(RuntimeError) end end @@ -213,10 +231,8 @@ RSpec.describe Bundler::GemHelper do let(:repo) { build_git("foo", :bare => true) } before do - Dir.chdir(app_path) do - sys_exec("git remote add origin #{file_uri_for(repo.path)}") - sys_exec('git commit -a -m "initial commit"') - end + sys_exec("git remote add origin #{file_uri_for(repo.path)}", :dir => app_path) + sys_exec('git commit -a -m "initial commit"', :dir => app_path) end context "on releasing" do @@ -225,7 +241,7 @@ RSpec.describe Bundler::GemHelper do mock_confirm_message "Tagged v#{app_version}." mock_confirm_message "Pushed git commits and tags." - Dir.chdir(app_path) { sys_exec("git push -u origin master") } + sys_exec("git push -u origin master", :dir => app_path) end it "calls rubygem_push with proper arguments" do @@ -235,7 +251,8 @@ RSpec.describe Bundler::GemHelper do end it "uses Kernel.system" do - expect(Kernel).to receive(:system).with(gem_bin, "push", app_gem_path.to_s, "--host", "http://example.org").and_return(true) + cmd = gem_bin.shellsplit + expect(Kernel).to receive(:system).with(*cmd, "push", app_gem_path.to_s, "--host", "http://example.org").and_return(true) Rake.application["release"].invoke end @@ -246,9 +263,7 @@ RSpec.describe Bundler::GemHelper do mock_confirm_message "Tag v#{app_version} has already been created." expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s) - Dir.chdir(app_path) do - `git tag -a -m \"Version #{app_version}\" v#{app_version}` - end + sys_exec("git tag -a -m \"Version #{app_version}\" v#{app_version}", :dir => app_path) Rake.application["release"].invoke end @@ -269,12 +284,10 @@ RSpec.describe Bundler::GemHelper do end before do - Dir.chdir(app_path) do - `git init` - `git config user.email "[email protected]"` - `git config user.name "name"` - `git config push.default simple` - end + sys_exec("git init", :dir => app_path) + sys_exec("git config user.email \"[email protected]\"", :dir => app_path) + sys_exec("git config user.name \"name\"", :dir => app_path) + sys_exec("git config push.gpgsign simple", :dir => app_path) # silence messages allow(Bundler.ui).to receive(:confirm) diff --git a/spec/bundler/bundler/mirror_spec.rb b/spec/bundler/bundler/mirror_spec.rb index 4a8a0c7c48..1eaf1e9a8e 100644 --- a/spec/bundler/bundler/mirror_spec.rb +++ b/spec/bundler/bundler/mirror_spec.rb @@ -305,6 +305,8 @@ RSpec.describe Bundler::Settings::TCPSocketProbe do end it "probes the server correctly" do + skip "obscure error" if Gem.win_platform? + with_server_and_mirror do |server, mirror| expect(server.closed?).to be_falsey expect(probe.replies?(mirror)).to be_truthy diff --git a/spec/bundler/bundler/plugin/index_spec.rb b/spec/bundler/bundler/plugin/index_spec.rb index e18e960fb8..925dc558ac 100644 --- a/spec/bundler/bundler/plugin/index_spec.rb +++ b/spec/bundler/bundler/plugin/index_spec.rb @@ -4,6 +4,7 @@ RSpec.describe Bundler::Plugin::Index do Index = Bundler::Plugin::Index before do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) gemfile "" path = lib_path(plugin_name) index.register_plugin("new-plugin", path.to_s, [path.join("lib").to_s], commands, sources, hooks) @@ -117,11 +118,11 @@ RSpec.describe Bundler::Plugin::Index do describe "global index" do before do - Dir.chdir(tmp) do - Bundler::Plugin.reset! - path = lib_path("gplugin") - index.register_plugin("gplugin", path.to_s, [path.join("lib").to_s], [], ["glb_source"], []) - end + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(nil) + + Bundler::Plugin.reset! + path = lib_path("gplugin") + index.register_plugin("gplugin", path.to_s, [path.join("lib").to_s], [], ["glb_source"], []) end it "skips sources" do diff --git a/spec/bundler/bundler/plugin_spec.rb b/spec/bundler/bundler/plugin_spec.rb index e0e2e9afdf..8c95723bcc 100644 --- a/spec/bundler/bundler/plugin_spec.rb +++ b/spec/bundler/bundler/plugin_spec.rb @@ -107,7 +107,7 @@ RSpec.describe Bundler::Plugin do describe "evaluate gemfile for plugins" do let(:definition) { double("definition") } let(:builder) { double("builder") } - let(:gemfile) { bundled_app("Gemfile") } + let(:gemfile) { bundled_app_gemfile } before do allow(Plugin::DSL).to receive(:new) { builder } @@ -237,7 +237,7 @@ RSpec.describe Bundler::Plugin do describe "#root" do context "in app dir" do before do - gemfile "" + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end it "returns plugin dir in app .bundle path" do @@ -246,8 +246,11 @@ RSpec.describe Bundler::Plugin do end context "outside app dir" do + before do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(nil) + end + it "returns plugin dir in global bundle path" do - Dir.chdir tmp expect(subject.root).to eq(home.join(".bundle/plugin")) end end diff --git a/spec/bundler/bundler/settings_spec.rb b/spec/bundler/bundler/settings_spec.rb index b83d768477..116a038445 100644 --- a/spec/bundler/bundler/settings_spec.rb +++ b/spec/bundler/bundler/settings_spec.rb @@ -130,6 +130,8 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow describe "#temporary" do it "reset after used" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + Bundler.settings.set_command_option :no_install, true Bundler.settings.temporary(:no_install => false) do diff --git a/spec/bundler/bundler/shared_helpers_spec.rb b/spec/bundler/bundler/shared_helpers_spec.rb index 4530a9a5cd..73adcf44d6 100644 --- a/spec/bundler/bundler/shared_helpers_spec.rb +++ b/spec/bundler/bundler/shared_helpers_spec.rb @@ -4,10 +4,13 @@ RSpec.describe Bundler::SharedHelpers do let(:ext_lock_double) { double(:ext_lock) } before do + pwd_stub allow(Bundler.rubygems).to receive(:ext_lock).and_return(ext_lock_double) allow(ext_lock_double).to receive(:synchronize) {|&block| block.call } end + let(:pwd_stub) { allow(subject).to receive(:pwd).and_return(bundled_app) } + subject { Bundler::SharedHelpers } describe "#default_gemfile" do @@ -77,7 +80,7 @@ RSpec.describe Bundler::SharedHelpers do let(:global_rubygems_dir) { Pathname.new(bundled_app) } before do - Dir.mkdir ".bundle" + Dir.mkdir bundled_app(".bundle") allow(Bundler.rubygems).to receive(:user_home).and_return(global_rubygems_dir) end @@ -91,7 +94,7 @@ RSpec.describe Bundler::SharedHelpers do let(:expected_bundle_dir_path) { Pathname.new("#{bundled_app}/.bundle") } before do - Dir.mkdir ".bundle" + Dir.mkdir bundled_app(".bundle") allow(Bundler.rubygems).to receive(:user_home).and_return(global_rubygems_dir) end @@ -109,7 +112,8 @@ RSpec.describe Bundler::SharedHelpers do shared_examples_for "correctly determines whether to return a Gemfile path" do context "currently in directory with a Gemfile" do - before { File.new("Gemfile", "w") } + before { FileUtils.touch(bundled_app_gemfile) } + after { FileUtils.rm(bundled_app_gemfile) } it "returns path of the bundle Gemfile" do expect(subject.in_bundle?).to eq("#{bundled_app}/Gemfile") @@ -147,22 +151,24 @@ RSpec.describe Bundler::SharedHelpers do describe "#chdir" do let(:op_block) { proc { Dir.mkdir "nested_dir" } } - before { Dir.mkdir "chdir_test_dir" } + before { Dir.mkdir bundled_app("chdir_test_dir") } it "executes the passed block while in the specified directory" do - subject.chdir("chdir_test_dir", &op_block) - expect(Pathname.new("chdir_test_dir/nested_dir")).to exist + subject.chdir(bundled_app("chdir_test_dir"), &op_block) + expect(bundled_app("chdir_test_dir/nested_dir")).to exist end end describe "#pwd" do + let(:pwd_stub) { nil } + it "returns the current absolute path" do - expect(subject.pwd).to eq(bundled_app) + expect(subject.pwd).to eq(root) end end describe "#with_clean_git_env" do - let(:with_clean_git_env_block) { proc { Dir.mkdir "with_clean_git_env_test_dir" } } + let(:with_clean_git_env_block) { proc { Dir.mkdir bundled_app("with_clean_git_env_test_dir") } } before do ENV["GIT_DIR"] = "ORIGINAL_ENV_GIT_DIR" @@ -171,20 +177,20 @@ RSpec.describe Bundler::SharedHelpers do it "executes the passed block" do subject.with_clean_git_env(&with_clean_git_env_block) - expect(Pathname.new("with_clean_git_env_test_dir")).to exist + expect(bundled_app("with_clean_git_env_test_dir")).to exist end context "when a block is passed" do let(:with_clean_git_env_block) do proc do - Dir.mkdir "git_dir_test_dir" unless ENV["GIT_DIR"].nil? - Dir.mkdir "git_work_tree_test_dir" unless ENV["GIT_WORK_TREE"].nil? + Dir.mkdir bundled_app("git_dir_test_dir") unless ENV["GIT_DIR"].nil? + Dir.mkdir bundled_app("git_work_tree_test_dir") unless ENV["GIT_WORK_TREE"].nil? end end it "uses a fresh git env for execution" do subject.with_clean_git_env(&with_clean_git_env_block) - expect(Pathname.new("git_dir_test_dir")).to_not exist - expect(Pathname.new("git_work_tree_test_dir")).to_not exist + expect(bundled_app("git_dir_test_dir")).to_not exist + expect(bundled_app("git_work_tree_test_dir")).to_not exist end end @@ -224,7 +230,7 @@ RSpec.describe Bundler::SharedHelpers do end shared_examples_for "ENV['PATH'] gets set correctly" do - before { Dir.mkdir ".bundle" } + before { Dir.mkdir bundled_app(".bundle") } it "ensures bundle bin path is in ENV['PATH']" do subject.set_bundle_environment @@ -244,7 +250,7 @@ RSpec.describe Bundler::SharedHelpers do let(:ruby_lib_path) { "stubbed_ruby_lib_dir" } before do - allow(Bundler::SharedHelpers).to receive(:bundler_ruby_lib).and_return(ruby_lib_path) + allow(subject).to receive(:bundler_ruby_lib).and_return(ruby_lib_path) end it "ensures bundler's ruby version lib path is in ENV['RUBYLIB']" do @@ -263,7 +269,7 @@ RSpec.describe Bundler::SharedHelpers do end it "ignores if bundler_ruby_lib is same as rubylibdir" do - allow(Bundler::SharedHelpers).to receive(:bundler_ruby_lib).and_return(RbConfig::CONFIG["rubylibdir"]) + allow(subject).to receive(:bundler_ruby_lib).and_return(RbConfig::CONFIG["rubylibdir"]) subject.set_bundle_environment @@ -422,8 +428,8 @@ RSpec.describe Bundler::SharedHelpers do let(:file_op_block) { proc {|path| FileUtils.mkdir_p(path) } } it "performs the operation in the passed block" do - subject.filesystem_access("./test_dir", &file_op_block) - expect(Pathname.new("test_dir")).to exist + subject.filesystem_access(bundled_app("test_dir"), &file_op_block) + expect(bundled_app("test_dir")).to exist end end diff --git a/spec/bundler/bundler/source/git/git_proxy_spec.rb b/spec/bundler/bundler/source/git/git_proxy_spec.rb index c18490233d..169d7234b4 100644 --- a/spec/bundler/bundler/source/git/git_proxy_spec.rb +++ b/spec/bundler/bundler/source/git/git_proxy_spec.rb @@ -123,6 +123,7 @@ RSpec.describe Bundler::Source::Git::GitProxy do end describe "#copy_to" do + let(:cache) { tmpdir("cache_path") } let(:destination) { tmpdir("copy_to_path") } let(:submodules) { false } @@ -132,8 +133,8 @@ RSpec.describe Bundler::Source::Git::GitProxy do it "fails gracefully when resetting to the revision fails" do expect(subject).to receive(:git_retry).with(start_with("clone ")) { destination.mkpath } - expect(subject).to receive(:git_retry).with(start_with("fetch ")) - expect(subject).to receive(:git).with(command).and_raise(Bundler::Source::Git::GitCommandError, command) + expect(subject).to receive(:git_retry).with(start_with("fetch "), :dir => destination) + expect(subject).to receive(:git).with(command, :dir => destination).and_raise(Bundler::Source::Git::GitCommandError.new(command, cache, destination)) expect(subject).not_to receive(:git) expect { subject.copy_to(destination, submodules) }. diff --git a/spec/bundler/cache/gems_spec.rb b/spec/bundler/cache/gems_spec.rb index 89d6d41570..a67aab8a7b 100644 --- a/spec/bundler/cache/gems_spec.rb +++ b/spec/bundler/cache/gems_spec.rb @@ -7,7 +7,7 @@ RSpec.describe "bundle cache" do gem 'rack' G - system_gems "rack-1.0.0", :path => :bundle_path + system_gems "rack-1.0.0", :path => path bundle! :cache end @@ -27,7 +27,7 @@ RSpec.describe "bundle cache" do end it "uses the cache as a source when installing gems with --local" do - system_gems [], :path => :bundle_path + system_gems [], :path => default_bundle_path bundle "install --local" expect(the_bundle).to include_gems("rack 1.0.0") @@ -46,7 +46,7 @@ RSpec.describe "bundle cache" do end it "does not reinstall gems from the cache if they exist in the bundle" do - system_gems "rack-1.0.0", :path => :bundle_path + system_gems "rack-1.0.0", :path => default_bundle_path gemfile <<-G gem "rack" @@ -69,17 +69,19 @@ RSpec.describe "bundle cache" do bundle "cache" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end end context "using system gems" do before { bundle! "config set path.system true" } + let(:path) { system_gem_path } it_behaves_like "when there are only gemsources" end context "installing into a local path" do before { bundle! "config set path ./.bundle" } + let(:path) { local_gem_path } it_behaves_like "when there are only gemsources" end @@ -165,11 +167,11 @@ RSpec.describe "bundle cache" do end it "should not explode if the lockfile is not present" do - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) bundle :cache - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end end diff --git a/spec/bundler/cache/git_spec.rb b/spec/bundler/cache/git_spec.rb index 75525d405b..ecdc97f837 100644 --- a/spec/bundler/cache/git_spec.rb +++ b/spec/bundler/cache/git_spec.rb @@ -155,10 +155,8 @@ RSpec.describe "bundle cache with git" do s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", :dir => lib_path("has_submodule-1.0") + sys_exec "git commit -m \"submodulator\"", :dir => lib_path("has_submodule-1.0") install_gemfile <<-G git "#{lib_path("has_submodule-1.0")}", :submodules => true do diff --git a/spec/bundler/cache/path_spec.rb b/spec/bundler/cache/path_spec.rb index 79e8b4a82b..bd47ac925d 100644 --- a/spec/bundler/cache/path_spec.rb +++ b/spec/bundler/cache/path_spec.rb @@ -26,13 +26,12 @@ RSpec.describe "bundle cache with path" do expect(bundled_app("vendor/cache/foo-1.0")).to exist expect(bundled_app("vendor/cache/foo-1.0/.bundlecache")).to be_file - FileUtils.rm_rf lib_path("foo-1.0") expect(the_bundle).to include_gems "foo 1.0" end it "copies when the path is outside the bundle and the paths intersect" do - libname = File.basename(Dir.pwd) + "_gem" - libpath = File.join(File.dirname(Dir.pwd), libname) + libname = File.basename(bundled_app) + "_gem" + libpath = File.join(File.dirname(bundled_app), libname) build_lib libname, :path => libpath @@ -45,7 +44,6 @@ RSpec.describe "bundle cache with path" do expect(bundled_app("vendor/cache/#{libname}")).to exist expect(bundled_app("vendor/cache/#{libname}/.bundlecache")).to be_file - FileUtils.rm_rf libpath expect(the_bundle).to include_gems "#{libname} 1.0" end @@ -66,7 +64,6 @@ RSpec.describe "bundle cache with path" do bundle :cache expect(bundled_app("vendor/cache/foo-1.0")).to exist - FileUtils.rm_rf lib_path("foo-1.0") run "require 'foo'" expect(out).to eq("CACHE") diff --git a/spec/bundler/commands/add_spec.rb b/spec/bundler/commands/add_spec.rb index 35fd43d3d2..7ea384c1dc 100644 --- a/spec/bundler/commands/add_spec.rb +++ b/spec/bundler/commands/add_spec.rb @@ -13,7 +13,7 @@ RSpec.describe "bundle add" do build_git "foo", "2.0" - install_gemfile <<-G + install_gemfile! <<-G source "#{file_uri_for(gem_repo2)}" gem "weakling", "~> 0.0.1" G @@ -30,25 +30,25 @@ RSpec.describe "bundle add" do describe "without version specified" do it "version requirement becomes ~> major.minor.patch when resolved version is < 1.0" do bundle "add 'bar'" - expect(bundled_app("Gemfile").read).to match(/gem "bar", "~> 0.12.3"/) + expect(bundled_app_gemfile.read).to match(/gem "bar", "~> 0.12.3"/) expect(the_bundle).to include_gems "bar 0.12.3" end it "version requirement becomes ~> major.minor when resolved version is > 1.0" do bundle "add 'baz'" - expect(bundled_app("Gemfile").read).to match(/gem "baz", "~> 1.2"/) + expect(bundled_app_gemfile.read).to match(/gem "baz", "~> 1.2"/) expect(the_bundle).to include_gems "baz 1.2.3" end it "version requirement becomes ~> major.minor.patch.pre when resolved version is < 1.0" do bundle "add 'cat'" - expect(bundled_app("Gemfile").read).to match(/gem "cat", "~> 0.12.3.pre"/) + expect(bundled_app_gemfile.read).to match(/gem "cat", "~> 0.12.3.pre"/) expect(the_bundle).to include_gems "cat 0.12.3.pre" end it "version requirement becomes ~> major.minor.pre when resolved version is > 1.0.pre" do bundle "add 'dog'" - expect(bundled_app("Gemfile").read).to match(/gem "dog", "~> 1.1.pre"/) + expect(bundled_app_gemfile.read).to match(/gem "dog", "~> 1.1.pre"/) expect(the_bundle).to include_gems "dog 1.1.3.pre" end end @@ -56,14 +56,14 @@ RSpec.describe "bundle add" do describe "with --version" do it "adds dependency of specified version and runs install" do bundle "add 'foo' --version='~> 1.0'" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 1.0"/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 1.0"/) expect(the_bundle).to include_gems "foo 1.1" end it "adds multiple version constraints when specified" do requirements = ["< 3.0", "> 1.0"] bundle "add 'foo' --version='#{requirements.join(", ")}'" - expect(bundled_app("Gemfile").read).to match(/gem "foo", #{Gem::Requirement.new(requirements).as_list.map(&:dump).join(', ')}/) + expect(bundled_app_gemfile.read).to match(/gem "foo", #{Gem::Requirement.new(requirements).as_list.map(&:dump).join(', ')}/) expect(the_bundle).to include_gems "foo 2.0" end end @@ -71,13 +71,13 @@ RSpec.describe "bundle add" do describe "with --group" do it "adds dependency for the specified group" do bundle "add 'foo' --group='development'" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :group => :development/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :group => :development/) expect(the_bundle).to include_gems "foo 2.0" end it "adds dependency to more than one group" do bundle "add 'foo' --group='development, test'" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :groups => \[:development, :test\]/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :groups => \[:development, :test\]/) expect(the_bundle).to include_gems "foo 2.0" end end @@ -86,7 +86,7 @@ RSpec.describe "bundle add" do it "adds dependency with specified source" do bundle "add 'foo' --source='#{file_uri_for(gem_repo2)}'" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :source => "#{file_uri_for(gem_repo2)}"/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :source => "#{file_uri_for(gem_repo2)}"/) expect(the_bundle).to include_gems "foo 2.0" end end @@ -95,7 +95,7 @@ RSpec.describe "bundle add" do it "adds dependency with specified github source" do bundle "add foo --git=#{lib_path("foo-2.0")}" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}"/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}"/) expect(the_bundle).to include_gems "foo 2.0" end end @@ -108,7 +108,7 @@ RSpec.describe "bundle add" do it "adds dependency with specified github source and branch" do bundle "add foo --git=#{lib_path("foo-2.0")} --branch=test" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :branch => "test"/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :branch => "test"/) expect(the_bundle).to include_gems "foo 2.0" end end @@ -117,14 +117,14 @@ RSpec.describe "bundle add" do it "adds gem to Gemfile but is not installed" do bundle "add foo --skip-install --version=2.0" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "= 2.0"/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "= 2.0"/) expect(the_bundle).to_not include_gems "foo 2.0" end end it "using combination of short form options works like long form" do bundle "add 'foo' -s='#{file_uri_for(gem_repo2)}' -g='development' -v='~>1.0'" - expect(bundled_app("Gemfile").read).to include %(gem "foo", "~> 1.0", :group => :development, :source => "#{file_uri_for(gem_repo2)}") + expect(bundled_app_gemfile.read).to include %(gem "foo", "~> 1.0", :group => :development, :source => "#{file_uri_for(gem_repo2)}") expect(the_bundle).to include_gems "foo 1.1" end @@ -153,7 +153,7 @@ RSpec.describe "bundle add" do describe "with --optimistic" do it "adds optimistic version" do bundle! "add 'foo' --optimistic" - expect(bundled_app("Gemfile").read).to include %(gem "foo", ">= 2.0") + expect(bundled_app_gemfile.read).to include %(gem "foo", ">= 2.0") expect(the_bundle).to include_gems "foo 2.0" end end @@ -161,7 +161,7 @@ RSpec.describe "bundle add" do describe "with --strict option" do it "adds strict version" do bundle! "add 'foo' --strict" - expect(bundled_app("Gemfile").read).to include %(gem "foo", "= 2.0") + expect(bundled_app_gemfile.read).to include %(gem "foo", "= 2.0") expect(the_bundle).to include_gems "foo 2.0" end end @@ -169,7 +169,7 @@ RSpec.describe "bundle add" do describe "with no option" do it "adds pessimistic version" do bundle! "add 'foo'" - expect(bundled_app("Gemfile").read).to include %(gem "foo", "~> 2.0") + expect(bundled_app_gemfile.read).to include %(gem "foo", "~> 2.0") expect(the_bundle).to include_gems "foo 2.0" end end @@ -186,8 +186,8 @@ RSpec.describe "bundle add" do it "adds multiple gems to gemfile" do bundle! "add bar baz" - expect(bundled_app("Gemfile").read).to match(/gem "bar", "~> 0.12.3"/) - expect(bundled_app("Gemfile").read).to match(/gem "baz", "~> 1.2"/) + expect(bundled_app_gemfile.read).to match(/gem "bar", "~> 0.12.3"/) + expect(bundled_app_gemfile.read).to match(/gem "baz", "~> 1.2"/) end it "throws error if any of the specified gems are present in the gemfile with different version" do @@ -200,7 +200,7 @@ RSpec.describe "bundle add" do describe "when a gem is added which is already specified in Gemfile with version" do it "shows an error when added with different version requirement" do - install_gemfile <<-G + install_gemfile! <<-G source "#{file_uri_for(gem_repo2)}" gem "rack", "1.0" G @@ -212,7 +212,7 @@ RSpec.describe "bundle add" do end it "shows error when added without version requirements" do - install_gemfile <<-G + install_gemfile! <<-G source "#{file_uri_for(gem_repo2)}" gem "rack", "1.0" G @@ -227,7 +227,7 @@ RSpec.describe "bundle add" do describe "when a gem is added which is already specified in Gemfile without version" do it "shows an error when added with different version requirement" do - install_gemfile <<-G + install_gemfile! <<-G source "#{file_uri_for(gem_repo2)}" gem "rack" G diff --git a/spec/bundler/commands/binstubs_spec.rb b/spec/bundler/commands/binstubs_spec.rb index 7c04e8ddbd..409c32c4f0 100644 --- a/spec/bundler/commands/binstubs_spec.rb +++ b/spec/bundler/commands/binstubs_spec.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true RSpec.describe "bundle binstubs <gem>" do + before do + skip "https://github.com/rubygems/bundler/issues/6894" if Gem.win_platform? + end + context "when the gem exists in the lockfile" do it "sets up the binstub" do install_gemfile <<-G @@ -82,7 +86,7 @@ RSpec.describe "bundle binstubs <gem>" do bundle "binstubs rack" - File.open("bin/bundle", "wb") do |file| + File.open(bundled_app("bin/bundle"), "wb") do |file| file.print "OMG" end @@ -94,18 +98,7 @@ RSpec.describe "bundle binstubs <gem>" do context "the bundle binstub" do before do - if system_bundler_version == :bundler - system_gems :bundler - elsif system_bundler_version - build_repo4 do - build_gem "bundler", system_bundler_version do |s| - s.executables = "bundle" - s.bindir = "exe" - s.write "exe/bundle", "puts %(system bundler #{system_bundler_version}\\n\#{ARGV.inspect})" - end - end - system_gems "bundler-#{system_bundler_version}", :gem_repo => gem_repo4 - end + system_gems "bundler-#{system_bundler_version}" build_repo2 do build_gem "prints_loaded_gems", "1.0" do |s| s.executables = "print_loaded_gems" @@ -127,13 +120,13 @@ RSpec.describe "bundle binstubs <gem>" do let(:system_bundler_version) { Bundler::VERSION } it "runs bundler" do - sys_exec! "#{bundled_app("bin/bundle")} install" - expect(out).to eq %(system bundler #{system_bundler_version}\n["install"]) + sys_exec! "bin/bundle install", :env => { "DEBUG" => "1" } + expect(out).to include %(Using bundler #{system_bundler_version}\n) end context "when BUNDLER_VERSION is set" do it "runs the correct version of bundler" do - sys_exec "#{bundled_app("bin/bundle")} install", "BUNDLER_VERSION" => "999.999.999" + sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "999.999.999" } expect(exitstatus).to eq(42) if exitstatus expect(err).to include("Activating bundler (~> 999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") @@ -147,7 +140,7 @@ RSpec.describe "bundle binstubs <gem>" do end it "runs the correct version of bundler" do - sys_exec "#{bundled_app("bin/bundle")} install" + sys_exec "bin/bundle install" expect(exitstatus).to eq(42) if exitstatus expect(err).to include("Activating bundler (~> 999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") @@ -162,7 +155,7 @@ RSpec.describe "bundle binstubs <gem>" do end it "runs the correct version of bundler" do - sys_exec "#{bundled_app("bin/bundle")} install" + sys_exec "bin/bundle install" expect(exitstatus).to eq(42) if exitstatus expect(err).to include("Activating bundler (~> 44.0) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 44.0'`") @@ -177,7 +170,7 @@ RSpec.describe "bundle binstubs <gem>" do end it "runs the available version of bundler when the version is older and the same major" do - sys_exec "#{bundled_app("bin/bundle")} install" + sys_exec "bin/bundle install" expect(exitstatus).not_to eq(42) if exitstatus expect(err).not_to include("Activating bundler (~> 55.0) failed:") end @@ -191,7 +184,7 @@ RSpec.describe "bundle binstubs <gem>" do end it "runs the correct version of bundler when the version is a pre-release" do - sys_exec "#{bundled_app("bin/bundle")} install" + sys_exec "bin/bundle install" expect(exitstatus).to eq(42) if exitstatus expect(err).to include("Activating bundler (~> 2.12.a) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 2.12.a'`") @@ -203,12 +196,12 @@ RSpec.describe "bundle binstubs <gem>" do before { lockfile.gsub(system_bundler_version, "1.1.1") } it "calls through to the latest bundler version" do - sys_exec! "#{bundled_app("bin/bundle")} update --bundler" - expect(out).to eq %(system bundler #{system_bundler_version}\n["update", "--bundler"]) + sys_exec! "bin/bundle update --bundler", :env => { "DEBUG" => "1" } + expect(out).to include %(Using bundler #{system_bundler_version}\n) end it "calls through to the explicit bundler version" do - sys_exec "#{bundled_app("bin/bundle")} update --bundler=999.999.999" + sys_exec "bin/bundle update --bundler=999.999.999" expect(exitstatus).to eq(42) if exitstatus expect(err).to include("Activating bundler (~> 999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") @@ -217,14 +210,13 @@ RSpec.describe "bundle binstubs <gem>" do context "without a lockfile" do it "falls back to the latest installed bundler" do - FileUtils.rm bundled_app("Gemfile.lock") - sys_exec! bundled_app("bin/bundle").to_s - expect(out).to eq "system bundler #{system_bundler_version}\n[]" + FileUtils.rm bundled_app_lock + sys_exec! "bin/bundle install", :env => { "DEBUG" => "1" } + expect(out).to include "Using bundler #{system_bundler_version}\n" end end context "using another binstub" do - let(:system_bundler_version) { :bundler } it "loads all gems" do sys_exec! bundled_app("bin/print_loaded_gems").to_s expect(out).to eq %(["bundler-#{Bundler::VERSION}", "prints_loaded_gems-1.0", "rack-1.2"]) @@ -274,6 +266,8 @@ RSpec.describe "bundle binstubs <gem>" do end it "sets correct permissions for binstubs" do + skip "https://github.com/rubygems/bundler/issues/6895" if Gem.win_platform? + with_umask(0o002) do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -295,7 +289,7 @@ RSpec.describe "bundle binstubs <gem>" do bundle "binstubs rack --shebang jruby" - expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env jruby\n") + expect(File.open(bundled_app("bin/rackup")).gets).to eq("#!/usr/bin/env jruby\n") end end end diff --git a/spec/bundler/commands/cache_spec.rb b/spec/bundler/commands/cache_spec.rb index 07ec186c2f..04dfee5b16 100644 --- a/spec/bundler/commands/cache_spec.rb +++ b/spec/bundler/commands/cache_spec.rb @@ -198,6 +198,10 @@ RSpec.describe "bundle cache" do end context "with --all-platforms" do + before do + skip "doesn't put gems where it should" if Gem.win_platform? + end + it "puts the gems in vendor/cache even for other rubies" do gemfile <<-D source "#{file_uri_for(gem_repo1)}" diff --git a/spec/bundler/commands/check_spec.rb b/spec/bundler/commands/check_spec.rb index c755ef2804..8955e51dff 100644 --- a/spec/bundler/commands/check_spec.rb +++ b/spec/bundler/commands/check_spec.rb @@ -18,8 +18,7 @@ RSpec.describe "bundle check" do gem "rails" G - Dir.chdir tmp - bundle "check --gemfile bundled_app/Gemfile" + bundle "check --gemfile bundled_app/Gemfile", :dir => tmp expect(out).to include("The Gemfile's dependencies are satisfied") end @@ -29,11 +28,11 @@ RSpec.describe "bundle check" do gem "rails" G - FileUtils.rm("Gemfile.lock") + FileUtils.rm(bundled_app_lock) bundle "check" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "does not create a Gemfile.lock if --dry-run was passed" do @@ -42,11 +41,11 @@ RSpec.describe "bundle check" do gem "rails" G - FileUtils.rm("Gemfile.lock") + FileUtils.rm(bundled_app_lock) bundle "check --dry-run" - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist end it "prints a generic error if the missing gems are unresolvable" do @@ -145,7 +144,7 @@ RSpec.describe "bundle check" do end G - system_gems "rack-1.0.0", :path => :bundle_path + system_gems "rack-1.0.0", :path => default_bundle_path lockfile <<-G GEM @@ -176,7 +175,7 @@ RSpec.describe "bundle check" do end G - system_gems "rack-1.0.0", :path => :bundle_path + system_gems "rack-1.0.0", :path => default_bundle_path lockfile <<-G GEM @@ -232,7 +231,7 @@ RSpec.describe "bundle check" do G bundle! "install", forgotten_command_line_options(:deployment => true) - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) bundle :check expect(last_command).to be_failure diff --git a/spec/bundler/commands/clean_spec.rb b/spec/bundler/commands/clean_spec.rb index 5cc97de912..590852b02d 100644 --- a/spec/bundler/commands/clean_spec.rb +++ b/spec/bundler/commands/clean_spec.rb @@ -536,7 +536,7 @@ RSpec.describe "bundle clean" do expect(out).to include("rack (1.0.0)") end - describe "when missing permissions" do + describe "when missing permissions", :permissions do before { ENV["BUNDLE_PATH__SYSTEM"] = "true" } let(:system_cache_path) { system_gem_path("cache") } after do @@ -585,11 +585,11 @@ RSpec.describe "bundle clean" do bundle "install" # mimic 7 length git revisions in Gemfile.lock - gemfile_lock = File.read(bundled_app("Gemfile.lock")).split("\n") + gemfile_lock = File.read(bundled_app_lock).split("\n") gemfile_lock.each_with_index do |line, index| gemfile_lock[index] = line[0..(11 + 7)] if line.include?(" revision:") end - lockfile(bundled_app("Gemfile.lock"), gemfile_lock.join("\n")) + lockfile(bundled_app_lock, gemfile_lock.join("\n")) bundle "config set path vendor/bundle" bundle "install" diff --git a/spec/bundler/commands/config_spec.rb b/spec/bundler/commands/config_spec.rb index ef580463e5..3a6b72d988 100644 --- a/spec/bundler/commands/config_spec.rb +++ b/spec/bundler/commands/config_spec.rb @@ -35,7 +35,7 @@ RSpec.describe ".bundle/config" do end end - describe "location" do + describe "location with a gemfile" do before :each do gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -54,14 +54,23 @@ RSpec.describe ".bundle/config" do it "can provide a relative path with the environment variable" do FileUtils.mkdir_p bundled_app("omg") - Dir.chdir bundled_app("omg") ENV["BUNDLE_APP_CONFIG"] = "../foo" - bundle "install", forgotten_command_line_options(:path => "vendor/bundle") + bundle "install", forgotten_command_line_options(:path => "vendor/bundle").merge(:dir => bundled_app("omg")) expect(bundled_app(".bundle")).not_to exist expect(bundled_app("../foo/config")).to exist - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "rack 1.0.0", :dir => bundled_app("omg") + end + end + + describe "location without a gemfile" do + it "works with an absolute path" do + ENV["BUNDLE_APP_CONFIG"] = tmp("foo/bar").to_s + bundle "config set --local path vendor/bundle" + + expect(bundled_app(".bundle")).not_to exist + expect(tmp("foo/bar/config")).to exist end end @@ -138,7 +147,7 @@ RSpec.describe ".bundle/config" do it "expands the path at time of setting" do bundle "config set --global local.foo .." run "puts Bundler.settings['local.foo']" - expect(out).to eq(File.expand_path(Dir.pwd + "/..")) + expect(out).to eq(File.expand_path(bundled_app.to_s + "/..")) end it "saves with parseable option" do @@ -205,7 +214,7 @@ RSpec.describe ".bundle/config" do it "expands the path at time of setting" do bundle "config set --local local.foo .." run "puts Bundler.settings['local.foo']" - expect(out).to eq(File.expand_path(Dir.pwd + "/..")) + expect(out).to eq(File.expand_path(bundled_app.to_s + "/..")) end it "can be deleted with parseable option" do @@ -484,7 +493,7 @@ RSpec.describe "setting gemfile via config" do G bundle "config set --local gemfile #{bundled_app("NotGemfile")}" - expect(File.exist?(".bundle/config")).to eq(true) + expect(File.exist?(bundled_app(".bundle/config"))).to eq(true) bundle "config list" expect(out).to include("NotGemfile") diff --git a/spec/bundler/commands/console_spec.rb b/spec/bundler/commands/console_spec.rb index a0b71ff016..3092184f45 100644 --- a/spec/bundler/commands/console_spec.rb +++ b/spec/bundler/commands/console_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe "bundle console", :bundler => "< 3" do +RSpec.describe "bundle console", :bundler => "< 3", :readline => true do before :each do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" diff --git a/spec/bundler/commands/doctor_spec.rb b/spec/bundler/commands/doctor_spec.rb index d829f00092..0731bb08db 100644 --- a/spec/bundler/commands/doctor_spec.rb +++ b/spec/bundler/commands/doctor_spec.rb @@ -32,6 +32,7 @@ RSpec.describe "bundle doctor" do before(:each) do stat = double("stat") unwritable_file = double("file") + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) allow(Find).to receive(:find).with(Bundler.bundle_path.to_s) { [unwritable_file] } allow(File).to receive(:stat).with(unwritable_file) { stat } allow(stat).to receive(:uid) { Process.uid } @@ -72,6 +73,7 @@ RSpec.describe "bundle doctor" do before(:each) do @stat = double("stat") @unwritable_file = double("file") + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) allow(Find).to receive(:find).with(Bundler.bundle_path.to_s) { [@unwritable_file] } allow(File).to receive(:stat).with(@unwritable_file) { @stat } end @@ -87,7 +89,7 @@ RSpec.describe "bundle doctor" do expect(@stdout.string).not_to include("No issues") end - context "when home contains files that are not owned by the current process" do + context "when home contains files that are not owned by the current process", :permissions do before(:each) do allow(@stat).to receive(:uid) { 0o0000 } end diff --git a/spec/bundler/commands/exec_spec.rb b/spec/bundler/commands/exec_spec.rb index 42f760ab12..442f5be8b9 100644 --- a/spec/bundler/commands/exec_spec.rb +++ b/spec/bundler/commands/exec_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "bundle exec" do let(:system_gems_to_install) { %w[rack-1.0.0 rack-0.9.1] } before :each do - system_gems(system_gems_to_install, :path => :bundle_path) + system_gems(system_gems_to_install, :path => default_bundle_path) end it "works with --gemfile flag" do @@ -68,6 +68,8 @@ RSpec.describe "bundle exec" do end it "respects custom process title when loading through ruby" do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + 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") puts `ps -ocommand= -p#{$$}` @@ -91,6 +93,8 @@ RSpec.describe "bundle exec" do end it "handles --keep-file-descriptors" do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + require "tempfile" command = Tempfile.new("io-test") @@ -122,12 +126,14 @@ RSpec.describe "bundle exec" do end it "can run a command named --verbose" do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + install_gemfile 'gem "rack"' - File.open("--verbose", "w") do |f| + File.open(bundled_app("--verbose"), "w") do |f| f.puts "#!/bin/sh" f.puts "echo foobar" end - File.chmod(0o744, "--verbose") + File.chmod(0o744, bundled_app("--verbose")) with_path_as(".") do bundle "exec -- --verbose" end @@ -146,21 +152,17 @@ RSpec.describe "bundle exec" do gem "rack", "0.9.1" G - Dir.chdir bundled_app2 do - install_gemfile bundled_app2("Gemfile"), <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack_two", "1.0.0" - G - end + install_gemfile bundled_app2("Gemfile"), <<-G, :dir => bundled_app2 + source "#{file_uri_for(gem_repo2)}" + gem "rack_two", "1.0.0" + G bundle! "exec rackup" expect(out).to eq("0.9.1") - Dir.chdir bundled_app2 do - bundle! "exec rackup" - expect(out).to eq("1.0.0") - end + bundle! "exec rackup", :dir => bundled_app2 + expect(out).to eq("1.0.0") end context "with default gems" do @@ -254,12 +256,10 @@ RSpec.describe "bundle exec" do gem "rack", "0.9.1" G - Dir.chdir bundled_app2 do - install_gemfile bundled_app2("Gemfile"), <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack_two", "1.0.0" - G - end + install_gemfile bundled_app2("Gemfile"), <<-G, :dir => bundled_app2 + source "#{file_uri_for(gem_repo2)}" + gem "rack_two", "1.0.0" + G bundle! "exec rackup" @@ -286,21 +286,26 @@ RSpec.describe "bundle exec" do end it "does not duplicate already exec'ed RUBYOPT" do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + install_gemfile <<-G gem "rack" G - rubyopt = ENV["RUBYOPT"] - rubyopt = "-r#{lib_dir}/bundler/setup #{rubyopt}" + bundler_setup_opt = "-r#{lib_dir}/bundler/setup" + + rubyopt = opt_add(bundler_setup_opt, ENV["RUBYOPT"]) bundle "exec 'echo $RUBYOPT'" - expect(out).to have_rubyopts(rubyopt) + expect(out.split(" ").count(bundler_setup_opt)).to eq(1) bundle "exec 'echo $RUBYOPT'", :env => { "RUBYOPT" => rubyopt } - expect(out).to have_rubyopts(rubyopt) + expect(out.split(" ").count(bundler_setup_opt)).to eq(1) end it "does not duplicate already exec'ed RUBYLIB" do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + install_gemfile <<-G gem "rack" G @@ -368,6 +373,8 @@ RSpec.describe "bundle exec" do each_prefix.call("exec") do |exec| describe "when #{exec} is used" do before(:each) do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + install_gemfile <<-G gem "rack" G @@ -581,6 +588,8 @@ RSpec.describe "bundle exec" do describe "with gems bundled for deployment" do it "works when calling bundler from another script" do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + gemfile <<-G module Monkey def bin_path(a,b,c) @@ -610,8 +619,8 @@ RSpec.describe "bundle exec" do RUBY before do - path.open("w") {|f| f << executable } - path.chmod(0o755) + bundled_app(path).open("w") {|f| f << executable } + bundled_app(path).chmod(0o755) install_gemfile <<-G gem "rack" @@ -634,6 +643,8 @@ RSpec.describe "bundle exec" do shared_examples_for "it runs" do it "like a normally executed executable" do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + subject expect(exitstatus).to eq(exit_code) if exitstatus expect(err).to eq(expected_err) @@ -782,7 +793,7 @@ __FILE__: #{path.to_s.inspect} end context "when the path is relative with a leading ./" do - let(:path) { Pathname.new("./#{super().relative_path_from(Pathname.pwd)}") } + let(:path) { Pathname.new("./#{super().relative_path_from(bundled_app)}") } pending "relative paths with ./ have absolute __FILE__" end @@ -813,6 +824,8 @@ __FILE__: #{path.to_s.inspect} RUBY it "receives the signal" do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + bundle!("exec #{path}") do |_, o, thr| o.gets # Consumes 'Started' and ensures that thread has started Process.kill("INT", thr.pid) @@ -834,6 +847,8 @@ __FILE__: #{path.to_s.inspect} RUBY it "makes sure no unexpected signals are restored to DEFAULT" do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + test_signals.each do |n| Signal.trap(n, "IGNORE") end @@ -858,11 +873,13 @@ __FILE__: #{path.to_s.inspect} end it "correctly shells out", :ruby_repo do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? + file = bundled_app("file_that_bundle_execs.rb") - create_file(file, <<-RB) + create_file(file, <<-RUBY) #!#{Gem.ruby} puts `bundle exec echo foo` - RB + RUBY file.chmod(0o777) bundle! "exec #{file}" expect(out).to eq("foo") @@ -874,27 +891,28 @@ __FILE__: #{path.to_s.inspect} let(:expected) { ruby "gem 'openssl', '< 999999'; require 'openssl'; puts OpenSSL::VERSION", :artifice => nil } it "only leaves the default gem in the stdlib available" do + skip "https://github.com/rubygems/bundler/issues/6898" if Gem.win_platform? skip "openssl isn't a default gem" if expected.empty? install_gemfile! "" # must happen before installing the broken system gem build_repo4 do build_gem "openssl", openssl_version do |s| - s.write("lib/openssl.rb", <<-RB) + s.write("lib/openssl.rb", <<-RUBY) raise "custom openssl should not be loaded, it's not in the gemfile!" - RB + RUBY end end system_gems(:bundler, "openssl-#{openssl_version}", :gem_repo => gem_repo4) file = bundled_app("require_openssl.rb") - create_file(file, <<-RB) + create_file(file, <<-RUBY) #!/usr/bin/env ruby require "openssl" puts OpenSSL::VERSION warn Gem.loaded_specs.values.map(&:full_name) - RB + RUBY file.chmod(0o777) aggregate_failures do diff --git a/spec/bundler/commands/help_spec.rb b/spec/bundler/commands/help_spec.rb index f4f90b9347..658b1374d4 100644 --- a/spec/bundler/commands/help_spec.rb +++ b/spec/bundler/commands/help_spec.rb @@ -28,6 +28,8 @@ RSpec.describe "bundle help" do end it "looks for a binary and executes it with --help option if it's named bundler-<task>" do + skip "obscure error" if Gem.win_platform? + File.open(tmp("bundler-testtasks"), "w", 0o755) do |f| f.puts "#!/usr/bin/env ruby\nputs ARGV.join(' ')\n" end diff --git a/spec/bundler/commands/info_spec.rb b/spec/bundler/commands/info_spec.rb index 4572823498..df2d5f2824 100644 --- a/spec/bundler/commands/info_spec.rb +++ b/spec/bundler/commands/info_spec.rb @@ -3,22 +3,23 @@ RSpec.describe "bundle info" do context "with a standard Gemfile" do before do - install_gemfile <<-G + install_gemfile! <<-G source "#{file_uri_for(gem_repo1)}" gem "rails" + gem "has_metadata" G end it "creates a Gemfile.lock when invoked with a gem name" do - FileUtils.rm("Gemfile.lock") + FileUtils.rm(bundled_app_lock) - bundle "info rails" + bundle! "info rails" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "prints information if gem exists in bundle" do - bundle "info rails" + bundle! "info rails" expect(out).to include "* rails (2.3.2) \tSummary: This is just a fake gem for testing \tHomepage: http://example.com @@ -26,12 +27,12 @@ RSpec.describe "bundle info" do end it "prints path if gem exists in bundle" do - bundle "info rails --path" + bundle! "info rails --path" expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) end it "prints the path to the running bundler" do - bundle "info bundler --path" + bundle! "info bundler --path" expect(out).to eq(root.to_s) end @@ -42,12 +43,28 @@ RSpec.describe "bundle info" do context "given a default gem shippped in ruby", :ruby_repo do it "prints information about the default gem" do - bundle "info rdoc" + bundle! "info rdoc" expect(out).to include("* rdoc") expect(out).to include("Default Gem: yes") end end + context "given a gem with metadata" do + it "prints the gem metadata" do + bundle! "info has_metadata" + expect(out).to include "* has_metadata (1.0) +\tSummary: This is just a fake gem for testing +\tHomepage: http://example.com +\tDocumentation: https://www.example.info/gems/bestgemever/0.0.1 +\tSource Code: https://example.com/user/bestgemever +\tWiki: https://example.com/user/bestgemever/wiki +\tChangelog: https://example.com/user/bestgemever/CHANGELOG.md +\tBug Tracker: https://example.com/user/bestgemever/issues +\tMailing List: https://groups.example.com/bestgemever +\tPath: #{default_bundle_path("gems", "has_metadata-1.0")}" + end + end + context "when gem does not have homepage" do before do build_repo2 do @@ -70,12 +87,12 @@ RSpec.describe "bundle info" do end it "prints out git info" do - install_gemfile <<-G + install_gemfile! <<-G gem "foo", :git => "#{lib_path("foo-1.0")}" G expect(the_bundle).to include_gems "foo 1.0" - bundle "info foo" + bundle! "info foo" expect(out).to include("foo (1.0 #{@git.ref_for("master", 6)}") end @@ -85,28 +102,28 @@ RSpec.describe "bundle info" do end @revision = revision_for(lib_path("foo-1.0"))[0...6] - install_gemfile <<-G + install_gemfile! <<-G gem "foo", :git => "#{lib_path("foo-1.0")}", :branch => "omg" G expect(the_bundle).to include_gems "foo 1.0.omg" - bundle "info foo" + bundle! "info foo" expect(out).to include("foo (1.0 #{@git.ref_for("omg", 6)}") end it "doesn't print the branch when tied to a ref" do sha = revision_for(lib_path("foo-1.0")) - install_gemfile <<-G + install_gemfile! <<-G gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{sha}" G - bundle "info foo" + bundle! "info foo" expect(out).to include("foo (1.0 #{sha[0..6]})") end it "handles when a version is a '-' prerelease" do @git = build_git("foo", "1.0.0-beta.1", :path => lib_path("foo")) - install_gemfile <<-G + install_gemfile! <<-G gem "foo", "1.0.0-beta.1", :git => "#{lib_path("foo")}" G expect(the_bundle).to include_gems "foo 1.0.0.pre.beta.1" @@ -117,21 +134,21 @@ RSpec.describe "bundle info" do end context "with a valid regexp for gem name" do - it "presents alternatives" do - install_gemfile <<-G + it "presents alternatives", :readline do + install_gemfile! <<-G source "#{file_uri_for(gem_repo1)}" gem "rack" gem "rack-obama" G - bundle "info rac" + bundle! "info rac" expect(out).to eq "1 : rack\n2 : rack-obama\n0 : - exit -\n>" end end context "with an invalid regexp for gem name" do it "does not find the gem" do - install_gemfile <<-G + install_gemfile! <<-G source "#{file_uri_for(gem_repo1)}" gem "rails" G diff --git a/spec/bundler/commands/init_spec.rb b/spec/bundler/commands/init_spec.rb index 7960ce85bd..ed52187115 100644 --- a/spec/bundler/commands/init_spec.rb +++ b/spec/bundler/commands/init_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "bundle init" do it "generates a Gemfile" do bundle! :init expect(out).to include("Writing new Gemfile") - expect(bundled_app("Gemfile")).to be_file + expect(bundled_app_gemfile).to be_file end context "when a Gemfile already exists" do @@ -15,7 +15,7 @@ RSpec.describe "bundle init" do end it "does not change existing Gemfiles" do - expect { bundle :init }.not_to change { File.read(bundled_app("Gemfile")) } + expect { bundle :init }.not_to change { File.read(bundled_app_gemfile) } end it "notifies the user that an existing Gemfile already exists" do @@ -32,9 +32,7 @@ RSpec.describe "bundle init" do FileUtils.mkdir bundled_app(subdir) - Dir.chdir bundled_app(subdir) do - bundle! :init - end + bundle! :init, :dir => bundled_app(subdir) expect(out).to include("Writing new Gemfile") expect(bundled_app("#{subdir}/Gemfile")).to be_file @@ -50,9 +48,7 @@ RSpec.describe "bundle init" do mode = File.stat(bundled_app(subdir)).mode ^ 0o222 FileUtils.chmod mode, bundled_app(subdir) - Dir.chdir bundled_app(subdir) do - bundle :init - end + bundle :init, :dir => bundled_app(subdir) expect(err).to include("directory is not writable") expect(Dir[bundled_app("#{subdir}/*")]).to be_empty @@ -75,7 +71,7 @@ RSpec.describe "bundle init" do bundle :init, :gemspec => spec_file - gemfile = bundled_app("Gemfile").read + gemfile = bundled_app_gemfile.read expect(gemfile).to match(%r{source 'https://rubygems.org'}) expect(gemfile.scan(/gem "rack", "= 1.0.1"/).size).to eq(1) expect(gemfile.scan(/gem "rspec", "= 1.2"/).size).to eq(1) @@ -133,9 +129,7 @@ RSpec.describe "bundle init" do FileUtils.mkdir bundled_app(subdir) - Dir.chdir bundled_app(subdir) do - bundle! :init - end + bundle! :init, :dir => bundled_app(subdir) expect(out).to include("Writing new gems.rb") expect(bundled_app("#{subdir}/gems.rb")).to be_file diff --git a/spec/bundler/commands/inject_spec.rb b/spec/bundler/commands/inject_spec.rb index 01c1f91877..78355edab3 100644 --- a/spec/bundler/commands/inject_spec.rb +++ b/spec/bundler/commands/inject_spec.rb @@ -10,9 +10,9 @@ RSpec.describe "bundle inject", :bundler => "< 3" do context "without a lockfile" do it "locks with the injected gems" do - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist bundle "inject 'rack-obama' '> 0'" - expect(bundled_app("Gemfile.lock").read).to match(/rack-obama/) + expect(bundled_app_lock.read).to match(/rack-obama/) end end @@ -22,15 +22,15 @@ RSpec.describe "bundle inject", :bundler => "< 3" do end it "adds the injected gems to the Gemfile" do - expect(bundled_app("Gemfile").read).not_to match(/rack-obama/) + expect(bundled_app_gemfile.read).not_to match(/rack-obama/) bundle "inject 'rack-obama' '> 0'" - expect(bundled_app("Gemfile").read).to match(/rack-obama/) + expect(bundled_app_gemfile.read).to match(/rack-obama/) end it "locks with the injected gems" do - expect(bundled_app("Gemfile.lock").read).not_to match(/rack-obama/) + expect(bundled_app_lock.read).not_to match(/rack-obama/) bundle "inject 'rack-obama' '> 0'" - expect(bundled_app("Gemfile.lock").read).to match(/rack-obama/) + expect(bundled_app_lock.read).to match(/rack-obama/) end end @@ -54,7 +54,7 @@ Usage: "bundle inject GEM VERSION" context "with source option" do it "add gem with source option in gemfile" do bundle "inject 'foo' '>0' --source #{file_uri_for(gem_repo1)}" - gemfile = bundled_app("Gemfile").read + gemfile = bundled_app_gemfile.read str = "gem \"foo\", \"> 0\", :source => \"#{file_uri_for(gem_repo1)}\"" expect(gemfile).to include str end @@ -63,14 +63,14 @@ Usage: "bundle inject GEM VERSION" context "with group option" do it "add gem with group option in gemfile" do bundle "inject 'rack-obama' '>0' --group=development" - gemfile = bundled_app("Gemfile").read + gemfile = bundled_app_gemfile.read str = "gem \"rack-obama\", \"> 0\", :group => :development" expect(gemfile).to include str end it "add gem with multiple groups in gemfile" do bundle "inject 'rack-obama' '>0' --group=development,test" - gemfile = bundled_app("Gemfile").read + gemfile = bundled_app_gemfile.read str = "gem \"rack-obama\", \"> 0\", :groups => [:development, :test]" expect(gemfile).to include str end @@ -88,13 +88,13 @@ Usage: "bundle inject GEM VERSION" it "injects anyway" do bundle "inject 'rack-obama' '> 0'" - expect(bundled_app("Gemfile").read).to match(/rack-obama/) + expect(bundled_app_gemfile.read).to match(/rack-obama/) end it "locks with the injected gems" do - expect(bundled_app("Gemfile.lock").read).not_to match(/rack-obama/) + expect(bundled_app_lock.read).not_to match(/rack-obama/) bundle "inject 'rack-obama' '> 0'" - expect(bundled_app("Gemfile.lock").read).to match(/rack-obama/) + expect(bundled_app_lock.read).to match(/rack-obama/) end it "restores frozen afterwards" do @@ -111,7 +111,7 @@ Usage: "bundle inject GEM VERSION" bundle "inject 'rack' '> 0'" expect(err).to match(/trying to install in deployment mode after changing/) - expect(bundled_app("Gemfile.lock").read).not_to match(/rack-obama/) + expect(bundled_app_lock.read).not_to match(/rack-obama/) end end end diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index b57d81b10a..87f34c1563 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -17,7 +17,7 @@ RSpec.describe "bundle install with gem sources" do G expect(err).to include('StandardError, "FAIL"') - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist end it "creates a Gemfile.lock" do @@ -26,7 +26,7 @@ RSpec.describe "bundle install with gem sources" do gem "rack" G - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "does not create ./.bundle by default", :bundler => "< 3" do @@ -66,13 +66,13 @@ RSpec.describe "bundle install with gem sources" do gem 'rack' G - lockfile = File.read(bundled_app("Gemfile.lock")) + lockfile = File.read(bundled_app_lock) install_gemfile <<-G raise StandardError, "FAIL" G - expect(File.read(bundled_app("Gemfile.lock"))).to eq(lockfile) + expect(File.read(bundled_app_lock)).to eq(lockfile) end it "does not touch the lockfile if nothing changed" do @@ -81,7 +81,7 @@ RSpec.describe "bundle install with gem sources" do gem "rack" G - expect { run "1" }.not_to change { File.mtime(bundled_app("Gemfile.lock")) } + expect { run "1" }.not_to change { File.mtime(bundled_app_lock) } end it "fetches gems" do @@ -176,7 +176,7 @@ RSpec.describe "bundle install with gem sources" do end it "does not reinstall any gem that is already available locally" do - system_gems "activesupport-2.3.2", :path => :bundle_path + system_gems "activesupport-2.3.2", :path => default_bundle_path build_repo2 do build_gem "activesupport", "2.3.2" do |s| @@ -218,6 +218,8 @@ RSpec.describe "bundle install with gem sources" do describe "with a gem that installs multiple platforms" do it "installs gems for the local platform as first choice" do + skip "version is 1.0, not 1.0.0" if Gem.win_platform? + install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "platform_specific" @@ -318,7 +320,7 @@ RSpec.describe "bundle install with gem sources" do install_gemfile <<-G G - expect(File.exist?(bundled_app("Gemfile.lock"))).to eq(true) + expect(File.exist?(bundled_app_lock)).to eq(true) end context "throws a warning if a gem is added twice in Gemfile" do @@ -372,6 +374,8 @@ RSpec.describe "bundle install with gem sources" do end it "gracefully handles error when rubygems server is unavailable" do + skip "networking issue" if Gem.win_platform? + install_gemfile <<-G, :artifice => nil source "#{file_uri_for(gem_repo1)}" source "http://0.0.0.0:9384" do @@ -500,23 +504,20 @@ RSpec.describe "bundle install with gem sources" do end describe "when Bundler root contains regex chars" do - before do + it "doesn't blow up" do root_dir = tmp("foo[]bar") FileUtils.mkdir_p(root_dir) - in_app_root_custom(root_dir) - end - it "doesn't blow up" do build_lib "foo" gemfile = <<-G gem 'foo', :path => "#{lib_path("foo-1.0")}" G - File.open("Gemfile", "w") do |file| + File.open("#{root_dir}/Gemfile", "w") do |file| file.puts gemfile end - bundle :install + bundle :install, :dir => root_dir expect(exitstatus).to eq(0) if exitstatus end @@ -536,7 +537,7 @@ RSpec.describe "bundle install with gem sources" do end end - describe "when bundle path does not have write access" do + describe "when bundle path does not have write access", :permissions do before do FileUtils.mkdir_p(bundled_app("vendor")) gemfile <<-G diff --git a/spec/bundler/commands/list_spec.rb b/spec/bundler/commands/list_spec.rb index 71d2136d38..60efd38cb7 100644 --- a/spec/bundler/commands/list_spec.rb +++ b/spec/bundler/commands/list_spec.rb @@ -24,6 +24,7 @@ RSpec.describe "bundle list" do gem "rack" gem "rspec", :group => [:test] + gem "rails", :group => [:production] G end @@ -32,6 +33,7 @@ RSpec.describe "bundle list" do bundle! "list --without-group test" expect(out).to include(" * rack (1.0.0)") + expect(out).to include(" * rails (2.3.2)") expect(out).not_to include(" * rspec (1.2.7)") end end @@ -43,6 +45,16 @@ RSpec.describe "bundle list" do expect(err).to eq "`random` group could not be found." end end + + context "when multiple groups" do + it "prints the gems not in the specified groups" do + bundle! "list --without-group test production" + + expect(out).to include(" * rack (1.0.0)") + expect(out).not_to include(" * rails (2.3.2)") + expect(out).not_to include(" * rspec (1.2.7)") + end + end end describe "with only-group option" do @@ -52,6 +64,7 @@ RSpec.describe "bundle list" do gem "rack" gem "rspec", :group => [:test] + gem "rails", :group => [:production] G end @@ -71,6 +84,16 @@ RSpec.describe "bundle list" do expect(err).to eq "`random` group could not be found." end end + + context "when multiple groups" do + it "prints the gems in the specified groups" do + bundle! "list --only-group default production" + + expect(out).to include(" * rack (1.0.0)") + expect(out).to include(" * rails (2.3.2)") + expect(out).not_to include(" * rspec (1.2.7)") + end + end end context "with name-only option" do diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb index 1d9813a835..466f4b739d 100644 --- a/spec/bundler/commands/lock_spec.rb +++ b/spec/bundler/commands/lock_spec.rb @@ -38,8 +38,8 @@ RSpec.describe "bundle lock" do actionpack (= 2.3.2) activerecord (= 2.3.2) activeresource (= 2.3.2) - rake (= 12.3.2) - rake (12.3.2) + rake (= 13.0.1) + rake (13.0.1) with_license (1.0) PLATFORMS @@ -133,7 +133,7 @@ RSpec.describe "bundle lock" do end it "update specific gems using --update" do - lockfile @lockfile.gsub("2.3.2", "2.3.1").gsub("12.3.2", "10.0.1") + lockfile @lockfile.gsub("2.3.2", "2.3.1").gsub("13.0.1", "10.0.1") bundle "lock --update rails rake" @@ -195,6 +195,8 @@ RSpec.describe "bundle lock" do gem 'foo' gem 'qux' G + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end it "single gem updates dependent gem to minor" do @@ -213,12 +215,15 @@ RSpec.describe "bundle lock" do it "supports adding new platforms" do bundle! "lock --add-platform java x86-mingw32" + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) lockfile = Bundler::LockfileParser.new(read_lockfile) expect(lockfile.platforms).to match_array(local_platforms.unshift(java, mingw).uniq) end it "supports adding the `ruby` platform" do bundle! "lock --add-platform ruby" + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) lockfile = Bundler::LockfileParser.new(read_lockfile) expect(lockfile.platforms).to match_array(local_platforms.unshift("ruby").uniq) end @@ -231,6 +236,7 @@ RSpec.describe "bundle lock" do it "allows removing platforms" do bundle! "lock --add-platform java x86-mingw32" + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) lockfile = Bundler::LockfileParser.new(read_lockfile) expect(lockfile.platforms).to match_array(local_platforms.unshift(java, mingw).uniq) @@ -245,7 +251,7 @@ RSpec.describe "bundle lock" do expect(err).to include("Removing all platforms from the bundle is not allowed") end - # from https://github.com/bundler/bundler/issues/4896 + # from https://github.com/rubygems/bundler/issues/4896 it "properly adds platforms when platform requirements come from different dependencies" do build_repo4 do build_gem "ffi", "1.9.14" diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb index 708b41f623..62ffaedcc0 100644 --- a/spec/bundler/commands/newgem_spec.rb +++ b/spec/bundler/commands/newgem_spec.rb @@ -17,7 +17,6 @@ RSpec.describe "bundle gem" do let(:require_path) { "mygem" } before do - global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false" git_config_content = <<-EOF [user] name = "Bundler User" @@ -64,7 +63,7 @@ RSpec.describe "bundle gem" do bundle! "gem #{gem_name} #{flags}" end - it "generates a gem skeleton with a .git folder" do + it "generates a gem skeleton with a .git folder", :readline do gem_skeleton_assertions expect(bundled_app("#{gem_name}/.git")).to exist end @@ -82,7 +81,7 @@ RSpec.describe "bundle gem" do end end - context "when passing --no-git" do + context "when passing --no-git", :readline do before do bundle! "gem #{gem_name} --no-git" end @@ -148,7 +147,54 @@ RSpec.describe "bundle gem" do end end - context "README.md" do + shared_examples_for "--rubocop flag" do + before do + bundle! "gem #{gem_name} --rubocop" + end + + it "generates a gem skeleton with rubocop" do + gem_skeleton_assertions + expect(bundled_app("test-gem/Rakefile")).to read_as( + include('require "rubocop/rake_task"'). + and(include("RuboCop::RakeTask.new"). + and(match(/:default.+:rubocop/))) + ) + end + + it "includes rubocop in generated Gemfile" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) + builder.dependencies + rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" } + expect(rubocop_dep).not_to be_nil + end + end + + shared_examples_for "--no-rubocop flag" do + define_negated_matcher :exclude, :include + + before do + bundle! "gem #{gem_name} --no-rubocop" + end + + it "generates a gem skeleton without rubocop" do + gem_skeleton_assertions + expect(bundled_app("test-gem/Rakefile")).to read_as(exclude("rubocop")) + expect(bundled_app("test-gem/#{gem_name}.gemspec")).to read_as(exclude("rubocop")) + end + + it "does not include rubocop in generated Gemfile" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) + builder.dependencies + rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" } + expect(rubocop_dep).to be_nil + end + end + + context "README.md", :readline do context "git config github.user present" do before do bundle! "gem #{gem_name}" @@ -163,7 +209,7 @@ RSpec.describe "bundle gem" do context "git config github.user is absent" do before do sys_exec("git config --unset github.user") - bundle "gem #{gem_name}" + bundle! "gem #{gem_name}" end it "contribute URL set to [USERNAME]" do @@ -173,18 +219,18 @@ RSpec.describe "bundle gem" do end end - it "creates a new git repository" do - bundle "gem #{gem_name}" + it "creates a new git repository", :readline do + bundle! "gem #{gem_name}" expect(bundled_app("#{gem_name}/.git")).to exist end - context "when git is not available" do + context "when git is not available", :readline do # This spec cannot have `git` available in the test env before do load_paths = [lib_dir, spec_dir] load_path_str = "-I#{load_paths.join(File::PATH_SEPARATOR)}" - sys_exec "#{Gem.ruby} #{load_path_str} #{bindir.join("bundle")} gem #{gem_name}", "PATH" => "" + sys_exec! "#{Gem.ruby} #{load_path_str} #{bindir.join("bundle")} gem #{gem_name}", :env => { "PATH" => "" } end it "creates the gem without the need for git" do @@ -200,25 +246,24 @@ RSpec.describe "bundle gem" do end end - it "generates a valid gemspec" do + it "generates a valid gemspec", :readline do bundle! "gem newgem --bin" prepare_gemspec(bundled_app("newgem", "newgem.gemspec")) - Dir.chdir(bundled_app("newgem")) do - gems = ["rake-12.3.2"] - system_gems gems, :path => :bundle_path - bundle! "exec rake build" - end + gems = ["rake-13.0.1"] + path = Bundler.feature_flag.default_install_uses_path? ? local_gem_path(:base => bundled_app("newgem")) : system_gem_path + system_gems gems, :path => path + bundle! "exec rake build", :dir => bundled_app("newgem") expect(last_command.stdboth).not_to include("ERROR") end - context "gem naming with relative paths" do + context "gem naming with relative paths", :readline do it "resolves ." do create_temporary_dir("tmp") - bundle "gem ." + bundle! "gem .", :dir => bundled_app("tmp") expect(bundled_app("tmp/lib/tmp.rb")).to exist end @@ -226,7 +271,7 @@ RSpec.describe "bundle gem" do it "resolves .." do create_temporary_dir("temp/empty_dir") - bundle "gem .." + bundle! "gem ..", :dir => bundled_app("temp/empty_dir") expect(bundled_app("temp/lib/temp.rb")).to exist end @@ -234,14 +279,13 @@ RSpec.describe "bundle gem" do it "resolves relative directory" do create_temporary_dir("tmp/empty/tmp") - bundle "gem ../../empty" + bundle! "gem ../../empty", :dir => bundled_app("tmp/empty/tmp") expect(bundled_app("tmp/empty/lib/empty.rb")).to exist end def create_temporary_dir(dir) - FileUtils.mkdir_p(dir) - Dir.chdir(dir) + FileUtils.mkdir_p(bundled_app(dir)) end end @@ -278,9 +322,9 @@ RSpec.describe "bundle gem" do context "git config user.{name,email} is not set" do before do - `git config --unset user.name` - `git config --unset user.email` - bundle "gem #{gem_name}" + sys_exec("git config --unset user.name", :dir => bundled_app) + sys_exec("git config --unset user.email", :dir => bundled_app) + bundle! "gem #{gem_name}" end it_should_behave_like "git config is absent" @@ -316,7 +360,7 @@ RSpec.describe "bundle gem" do it "runs rake without problems" do bundle! "gem #{gem_name}" - system_gems ["rake-12.3.2"] + system_gems ["rake-13.0.1"] rakefile = strip_whitespace <<-RAKEFILE task :default do @@ -327,15 +371,13 @@ RSpec.describe "bundle gem" do file.puts rakefile end - Dir.chdir(bundled_app(gem_name)) do - sys_exec(rake) - expect(out).to include("SUCCESS") - end + sys_exec(rake, :dir => bundled_app(gem_name)) + expect(out).to include("SUCCESS") end context "--exe parameter set" do before do - bundle "gem #{gem_name} --exe" + bundle! "gem #{gem_name} --exe" end it "builds exe skeleton" do @@ -349,7 +391,7 @@ RSpec.describe "bundle gem" do context "--bin parameter set" do before do - bundle "gem #{gem_name} --bin" + bundle! "gem #{gem_name} --bin" end it "builds exe skeleton" do @@ -363,7 +405,7 @@ RSpec.describe "bundle gem" do context "no --test parameter" do before do - bundle "gem #{gem_name}" + bundle! "gem #{gem_name}" end it "doesn't create any spec/test file" do @@ -371,13 +413,13 @@ RSpec.describe "bundle gem" do expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to_not exist expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to_not exist expect(bundled_app("#{gem_name}/test/#{require_path}.rb")).to_not exist - expect(bundled_app("#{gem_name}/test/minitest_helper.rb")).to_not exist + expect(bundled_app("#{gem_name}/test/test_helper.rb")).to_not exist end end context "--test parameter set to rspec" do before do - bundle "gem #{gem_name} --test=rspec" + bundle! "gem #{gem_name} --test=rspec" end it "builds spec skeleton" do @@ -387,13 +429,12 @@ RSpec.describe "bundle gem" do end it "depends on a specific version of rspec in generated Gemfile" do - Dir.chdir(bundled_app(gem_name)) do - builder = Bundler::Dsl.new - builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) - builder.dependencies - rspec_dep = builder.dependencies.find {|d| d.name == "rspec" } - expect(rspec_dep).to be_specific - end + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) + builder.dependencies + rspec_dep = builder.dependencies.find {|d| d.name == "rspec" } + expect(rspec_dep).to be_specific end it "requires the main file" do @@ -408,7 +449,7 @@ RSpec.describe "bundle gem" do context "gem.test setting set to rspec" do before do bundle "config set gem.test rspec" - bundle "gem #{gem_name}" + bundle! "gem #{gem_name}" end it "builds spec skeleton" do @@ -421,7 +462,7 @@ RSpec.describe "bundle gem" do context "gem.test setting set to rspec and --test is set to minitest" do before do bundle "config set gem.test rspec" - bundle "gem #{gem_name} --test=minitest" + bundle! "gem #{gem_name} --test=minitest" end it "builds spec skeleton" do @@ -436,13 +477,12 @@ RSpec.describe "bundle gem" do end it "depends on a specific version of minitest" do - Dir.chdir(bundled_app(gem_name)) do - builder = Bundler::Dsl.new - builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) - builder.dependencies - minitest_dep = builder.dependencies.find {|d| d.name == "minitest" } - expect(minitest_dep).to be_specific - end + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) + builder.dependencies + minitest_dep = builder.dependencies.find {|d| d.name == "minitest" } + expect(minitest_dep).to be_specific end it "builds spec skeleton" do @@ -454,7 +494,7 @@ RSpec.describe "bundle gem" do expect(bundled_app("#{gem_name}/test/test_helper.rb").read).to include(%(require "#{require_path}")) end - it "requires 'minitest_helper'" do + it "requires 'test_helper'" do expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include(%(require "test_helper")) end @@ -466,6 +506,62 @@ RSpec.describe "bundle gem" do context "gem.test setting set to minitest" do before do bundle "config set gem.test minitest" + bundle! "gem #{gem_name}" + end + + it "creates a default rake task to run the test suite" do + rakefile = strip_whitespace <<-RAKEFILE + require "bundler/gem_tasks" + require "rake/testtask" + + Rake::TestTask.new(:test) do |t| + t.libs << "test" + t.libs << "lib" + t.test_files = FileList["test/**/*_test.rb"] + end + + task :default => :test + RAKEFILE + + expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile) + end + end + + context "--test parameter set to test-unit" do + before do + bundle "gem #{gem_name} --test=test-unit" + end + + it "depends on a specific version of test-unit" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) + builder.dependencies + test_unit_dep = builder.dependencies.find {|d| d.name == "test-unit" } + expect(test_unit_dep).to be_specific + end + + it "builds spec skeleton" do + expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb")).to exist + expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist + end + + it "requires the main file" do + expect(bundled_app("#{gem_name}/test/test_helper.rb").read).to include(%(require "#{require_path}")) + end + + it "requires 'test_helper'" do + expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include(%(require "test_helper")) + end + + it "creates a default test which fails" do + expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include("assert_equal(\"expected\", \"actual\")") + end + end + + context "gem.test setting set to test-unit" do + before do + bundle "config set gem.test test-unit" bundle "gem #{gem_name}" end @@ -489,12 +585,12 @@ RSpec.describe "bundle gem" do context "--test with no arguments" do before do - bundle "gem #{gem_name} --test" + bundle! "gem #{gem_name} --test" end it "defaults to rspec" do expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist - expect(bundled_app("#{gem_name}/test/minitest_helper.rb")).to_not exist + expect(bundled_app("#{gem_name}/test/test_helper.rb")).to_not exist end it "creates a .travis.yml file to test the library against the current Ruby version on Travis CI" do @@ -505,56 +601,75 @@ RSpec.describe "bundle gem" do context "--edit option" do it "opens the generated gemspec in the user's text editor" do output = bundle "gem #{gem_name} --edit=echo" - gemspec_path = File.join(Dir.pwd, gem_name, "#{gem_name}.gemspec") + gemspec_path = File.join(bundled_app, gem_name, "#{gem_name}.gemspec") expect(output).to include("echo \"#{gemspec_path}\"") end end end - context "testing --mit and --coc options against bundle config settings" do + context "testing --mit and --coc options against bundle config settings", :readline do let(:gem_name) { "test-gem" } let(:require_path) { "test/gem" } context "with mit option in bundle config settings set to true" do before do - global_config "BUNDLE_GEM__MIT" => "true", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false" + global_config "BUNDLE_GEM__MIT" => "true" end it_behaves_like "--mit flag" it_behaves_like "--no-mit flag" end context "with mit option in bundle config settings set to false" do + before do + global_config "BUNDLE_GEM__MIT" => "false" + end it_behaves_like "--mit flag" it_behaves_like "--no-mit flag" end context "with coc option in bundle config settings set to true" do before do - global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "true" + global_config "BUNDLE_GEM__COC" => "true" end it_behaves_like "--coc flag" it_behaves_like "--no-coc flag" end context "with coc option in bundle config settings set to false" do + before do + global_config "BUNDLE_GEM__COC" => "false" + end it_behaves_like "--coc flag" it_behaves_like "--no-coc flag" end + + context "with rubocop option in bundle config settings set to true" do + before do + global_config "BUNDLE_GEM__RUBOCOP" => "true" + end + it_behaves_like "--rubocop flag" + it_behaves_like "--no-rubocop flag" + end + + context "with rubocop option in bundle config settings set to false" do + before do + global_config "BUNDLE_GEM__RUBOCOP" => "false" + end + it_behaves_like "--rubocop flag" + it_behaves_like "--no-rubocop flag" + end end - context "gem naming with underscore" do + context "gem naming with underscore", :readline do let(:gem_name) { "test_gem" } let(:require_path) { "test_gem" } let(:flags) { nil } - before do - bundle! ["gem", gem_name, flags].compact.join(" ") - end - it "does not nest constants" do + bundle! ["gem", gem_name, flags].compact.join(" ") expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/module TestGem/) expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(/module TestGem/) end @@ -564,6 +679,10 @@ RSpec.describe "bundle gem" do context "--ext parameter set" do let(:flags) { "--ext" } + before do + bundle! ["gem", gem_name, flags].compact.join(" ") + end + it "builds ext skeleton" do expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb")).to exist expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.h")).to exist @@ -585,7 +704,7 @@ RSpec.describe "bundle gem" do ext.lib_dir = "lib/#{gem_name}" end - task :default => [:clobber, :compile, :spec] + task :default => [:clobber, :compile] RAKEFILE expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile) @@ -593,16 +712,13 @@ RSpec.describe "bundle gem" do end end - context "gem naming with dashed" do + context "gem naming with dashed", :readline do let(:gem_name) { "test-gem" } let(:require_path) { "test/gem" } - before do - bundle! "gem #{gem_name}" - end - it "nests constants so they work" do + bundle! "gem #{gem_name}" expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/module Test\n module Gem/) expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(/module Test\n module Gem/) end @@ -611,7 +727,7 @@ RSpec.describe "bundle gem" do end describe "uncommon gem names" do - it "can deal with two dashes" do + it "can deal with two dashes", :readline do bundle! "gem a--a" expect(bundled_app("a--a/a--a.gemspec")).to exist @@ -641,7 +757,7 @@ Usage: "bundle gem NAME [OPTIONS]" end end - describe "#ensure_safe_gem_name" do + describe "#ensure_safe_gem_name", :readline do before do bundle "gem #{subject}" end @@ -667,11 +783,11 @@ Usage: "bundle gem NAME [OPTIONS]" end end - context "on first run" do + context "on first run", :readline do it "asks about test framework" do global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__COC" => "false" - bundle "gem foobar" do |input, _, _| + bundle! "gem foobar" do |input, _, _| input.puts "rspec" end @@ -694,7 +810,7 @@ Usage: "bundle gem NAME [OPTIONS]" bundle "config list" - bundle "gem foobar" do |input, _, _| + bundle! "gem foobar" do |input, _, _| input.puts "yes" end @@ -704,7 +820,7 @@ Usage: "bundle gem NAME [OPTIONS]" it "asks about CoC" do global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false" - bundle "gem foobar" do |input, _, _| + bundle! "gem foobar" do |input, _, _| input.puts "yes" end @@ -712,18 +828,18 @@ Usage: "bundle gem NAME [OPTIONS]" end end - context "on conflicts with a previously created file" do + context "on conflicts with a previously created file", :readline do it "should fail gracefully" do - FileUtils.touch("conflict-foobar") + FileUtils.touch(bundled_app("conflict-foobar")) bundle "gem conflict-foobar" expect(err).to include("Errno::ENOTDIR") expect(exitstatus).to eql(32) if exitstatus end end - context "on conflicts with a previously created directory" do + context "on conflicts with a previously created directory", :readline do it "should succeed" do - FileUtils.mkdir_p("conflict-foobar/Gemfile") + FileUtils.mkdir_p(bundled_app("conflict-foobar/Gemfile")) bundle! "gem conflict-foobar" expect(out).to include("file_clash conflict-foobar/Gemfile"). and include "Initializing git repo in #{bundled_app("conflict-foobar")}" diff --git a/spec/bundler/commands/open_spec.rb b/spec/bundler/commands/open_spec.rb index 8fae4af5b4..31dc0315ac 100644 --- a/spec/bundler/commands/open_spec.rb +++ b/spec/bundler/commands/open_spec.rb @@ -58,7 +58,7 @@ RSpec.describe "bundle open" do expect(out).to include("bundler_editor #{default_bundle_path("gems", "activerecord-2.3.2")}") end - it "select the gem from many match gems" do + it "select the gem from many match gems", :readline do env = { "EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor" } bundle "open active", :env => env do |input, _, _| input.puts "2" @@ -67,7 +67,7 @@ RSpec.describe "bundle open" do expect(out).to match(/bundler_editor #{default_bundle_path('gems', 'activerecord-2.3.2')}\z/) end - it "allows selecting exit from many match gems" do + it "allows selecting exit from many match gems", :readline do env = { "EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor" } bundle! "open active", :env => env do |input, _, _| input.puts "0" diff --git a/spec/bundler/commands/outdated_spec.rb b/spec/bundler/commands/outdated_spec.rb index df911eaffd..2fa3e26865 100644 --- a/spec/bundler/commands/outdated_spec.rb +++ b/spec/bundler/commands/outdated_spec.rb @@ -29,13 +29,35 @@ RSpec.describe "bundle outdated" do bundle "outdated" - expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5)") - expect(out).to include("weakling (newest 0.2, installed 0.0.3, requested ~> 0.0.1)") - expect(out).to include("foo (newest 1.0") + expected_output = <<~TABLE.gsub("x", "\\\h").tr(".", "\.").strip + Gem Current Latest Requested Groups + activesupport 2.3.5 3.0 = 2.3.5 default + foo 1.0 xxxxxxx 1.0 xxxxxxx >= 0 default + weakling 0.0.3 0.2 ~> 0.0.1 default + zebra 1.0 xxxxxxx 1.0 xxxxxxx >= 0 default + TABLE - # Gem names are one per-line, between "*" and their parenthesized version. - gem_list = out.split("\n").map {|g| g[/\* (.*) \(/, 1] }.compact - expect(gem_list).to eq(gem_list.sort) + expect(out).to match(Regexp.new(expected_output)) + end + + it "excludes header row from the sorting" do + update_repo2 do + build_gem "AAA", %w[1.0.0 2.0.0] + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "AAA", "1.0.0" + G + + bundle "outdated" + + expected_output = <<~TABLE + Gem Current Latest Requested Groups + AAA 1.0.0 2.0.0 = 1.0.0 default + TABLE + + expect(out).to include(expected_output.strip) end it "returns non zero exit status if outdated gems present" do @@ -69,9 +91,48 @@ RSpec.describe "bundle outdated" do update_repo2 { build_gem "activesupport", "3.0" } update_repo2 { build_gem "terranova", "9" } + bundle "outdated" + + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + activesupport 2.3.5 3.0 = 2.3.5 development, test + terranova 8 9 = 8 default + TABLE + + expect(out).to end_with(expected_output) + end + end + + describe "with --verbose option" do + it "shows the location of the latest version's gemspec if installed" do + bundle! "config set clean false" + + update_repo2 { build_gem "activesupport", "3.0" } + update_repo2 { build_gem "terranova", "9" } + + install_gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + + gem "terranova", '9' + gem 'activesupport', '2.3.5' + G + + gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + + gem "terranova", '8' + gem 'activesupport', '2.3.5' + G + 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\"") + + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups Path + activesupport 2.3.5 3.0 = 2.3.5 default + terranova 8 9 = 8 default #{default_bundle_path("specifications/terranova-9.gemspec")} + TABLE + + expect(out).to end_with(expected_output) end end @@ -89,7 +150,7 @@ RSpec.describe "bundle outdated" do G end - def test_group_option(group = nil, gems_list_size = 1) + def test_group_option(group) update_repo2 do build_gem "activesupport", "3.0" build_gem "terranova", "9" @@ -97,49 +158,79 @@ RSpec.describe "bundle outdated" do end bundle "outdated --group #{group}" - - # Gem names are one per-line, between "*" and their parenthesized version. - gem_list = out.split("\n").map {|g| g[/\* (.*) \(/, 1] }.compact - expect(gem_list).to eq(gem_list.sort) - expect(gem_list.size).to eq gems_list_size end - it "not outdated gems" do + it "works when the bundle is up to date" do bundle "outdated --group" - expect(out).to include("Bundle up to date!") + expect(out).to end_with("Bundle up to date!") end 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("terranova (") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + terranova 8 9 = 8 default + TABLE - expect(out).not_to include("===== Groups \"development, test\" =====") - expect(out).not_to include("activesupport") - expect(out).not_to include("duradura") + expect(out).to end_with(expected_output) end it "returns a sorted list of outdated gems from one group => 'development'" do - test_group_option("development", 2) + test_group_option("development") - expect(out).not_to include("===== Group \"default\" =====") - expect(out).not_to include("terranova (") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + activesupport 2.3.5 3.0 = 2.3.5 development, test + duradura 7.0 8.0 = 7.0 development, test + TABLE - expect(out).to include("===== Groups \"development, test\" =====") - expect(out).to include("activesupport") - expect(out).to include("duradura") + expect(out).to end_with(expected_output) end it "returns a sorted list of outdated gems from one group => 'test'" do - test_group_option("test", 2) + test_group_option("test") - expect(out).not_to include("===== Group \"default\" =====") - expect(out).not_to include("terranova (") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + activesupport 2.3.5 3.0 = 2.3.5 development, test + duradura 7.0 8.0 = 7.0 development, test + TABLE - expect(out).to include("===== Groups \"development, test\" =====") - expect(out).to include("activesupport") - expect(out).to include("duradura") + expect(out).to end_with(expected_output) + end + end + + describe "with --groups option and outdated transitive dependencies" do + before do + update_repo2 do + build_gem "bar", %w[2.0.0] + + build_gem "bar_dependant", "7.0" do |s| + s.add_dependency "bar", "~> 2.0" + end + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + + gem "bar_dependant", '7.0' + G + + update_repo2 do + build_gem "bar", %w[3.0.0] + end + end + + it "returns a sorted list of outdated gems" do + bundle "outdated --groups" + + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + bar 2.0.0 3.0.0 + TABLE + + expect(out).to end_with(expected_output) end end @@ -159,7 +250,7 @@ RSpec.describe "bundle outdated" do it "not outdated gems" do bundle "outdated --groups" - expect(out).to include("Bundle up to date!") + expect(out).to end_with("Bundle up to date!") end it "returns a sorted list of outdated gems by groups" do @@ -170,15 +261,15 @@ RSpec.describe "bundle outdated" do end bundle "outdated --groups" - expect(out).to include("===== Group \"default\" =====") - expect(out).to include("terranova (newest 9, installed 8, requested = 8)") - 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)") - expect(out).not_to include("weakling (") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + activesupport 2.3.5 3.0 = 2.3.5 development, test + duradura 7.0 8.0 = 7.0 development, test + terranova 8 9 = 8 default + TABLE - # TODO: check gems order inside the group + expect(out).to end_with(expected_output) end end @@ -197,7 +288,12 @@ RSpec.describe "bundle outdated" do bundle "outdated --local" - expect(out).to include("activesupport (newest 2.3.5, installed 2.3.4, requested = 2.3.4)") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + activesupport 2.3.4 2.3.5 = 2.3.4 default + TABLE + + expect(out).to end_with(expected_output) end it "doesn't hit repo2" do @@ -253,8 +349,13 @@ RSpec.describe "bundle outdated" do end bundle "outdated foo" - expect(out).not_to include("activesupport (newest") - expect(out).to include("foo (newest 1.0") + + expected_output = <<~TABLE.gsub("x", "\\\h").tr(".", "\.").strip + Gem Current Latest Requested Groups + foo 1.0 xxxxxxx 1.0 xxxxxxx >= 0 default + TABLE + + expect(out).to match(Regexp.new(expected_output)) end end @@ -266,7 +367,8 @@ RSpec.describe "bundle outdated" do end bundle "outdated" - expect(out).not_to include("activesupport (3.0.0.beta > 2.3.5)") + + expect(out).to end_with("Bundle up to date!") end end @@ -277,7 +379,13 @@ RSpec.describe "bundle outdated" do end bundle "outdated --pre" - expect(out).to include("activesupport (newest 3.0.0.beta, installed 2.3.5, requested = 2.3.5)") + + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + activesupport 2.3.5 3.0.0.beta = 2.3.5 default + TABLE + + expect(out).to end_with(expected_output) end end @@ -294,7 +402,13 @@ RSpec.describe "bundle outdated" do G bundle "outdated" - expect(out).to include("(newest 3.0.0.beta.2, installed 3.0.0.beta.1, requested = 3.0.0.beta.1)") + + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + activesupport 3.0.0.beta.1 3.0.0.beta.2 = 3.0.0.beta.1 default + TABLE + + expect(out).to end_with(expected_output) end end end @@ -309,8 +423,12 @@ RSpec.describe "bundle outdated" do bundle :outdated, filter_strict_option => true - expect(out).to_not include("activesupport (newest") - expect(out).to include("(newest 0.0.5, installed 0.0.3, requested ~> 0.0.1)") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + weakling 0.0.3 0.0.5 ~> 0.0.1 default + TABLE + + expect(out).to end_with(expected_output) end it "only reports gem dependencies when they can actually be updated" do @@ -321,7 +439,7 @@ RSpec.describe "bundle outdated" do bundle :outdated, filter_strict_option => true - expect(out).to_not include("rack (1.2") + expect(out).to end_with("Bundle up to date!") end describe "and filter options" do @@ -339,8 +457,12 @@ RSpec.describe "bundle outdated" do bundle :outdated, filter_strict_option => true, "filter-patch" => true - expect(out).to_not include("activesupport (newest") - expect(out).to include("(newest 0.0.5, installed 0.0.3") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + weakling 0.0.3 0.0.5 >= 0.0.1 default + TABLE + + expect(out).to end_with(expected_output) end it "only reports gems that match requirement and minor filter level" do @@ -357,8 +479,12 @@ RSpec.describe "bundle outdated" do bundle :outdated, filter_strict_option => true, "filter-minor" => true - expect(out).to_not include("activesupport (newest") - expect(out).to include("(newest 0.1.5, installed 0.0.3") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + weakling 0.0.3 0.1.5 >= 0.0.1 default + TABLE + + expect(out).to end_with(expected_output) end it "only reports gems that match requirement and major filter level" do @@ -375,8 +501,12 @@ RSpec.describe "bundle outdated" do bundle :outdated, filter_strict_option => true, "filter-major" => true - expect(out).to_not include("activesupport (newest") - expect(out).to include("(newest 1.1.5, installed 0.0.3") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + weakling 0.0.3 1.1.5 >= 0.0.1 default + TABLE + + expect(out).to end_with(expected_output) end end end @@ -460,7 +590,7 @@ RSpec.describe "bundle outdated" do it "reports that no updates are available" do bundle "outdated" - expect(out).to include("Bundle up to date!") + expect(out).to end_with("Bundle up to date!") end end @@ -472,31 +602,33 @@ RSpec.describe "bundle outdated" do G bundle "outdated" - expect(out).to include("Bundle up to date!") + expect(out).to end_with("Bundle up to date!") end - it "reports that updates are available if the JRuby platform is used" do - simulate_ruby_engine "jruby", "1.6.7" do - simulate_platform "jruby" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "laduradura", '= 5.15.2', :platforms => [:ruby, :jruby] - G + it "reports that updates are available if the JRuby platform is used", :jruby do + install_gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "laduradura", '= 5.15.2', :platforms => [:ruby, :jruby] + G - bundle "outdated" - expect(out).to include("Outdated gems included in the bundle:") - expect(out).to include("laduradura (newest 5.15.3, installed 5.15.2, requested = 5.15.2)") - end - end + bundle "outdated" + + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + laduradura 5.15.2 5.15.3 = 5.15.2 default + TABLE + + expect(out).to end_with(expected_output) end end shared_examples_for "version update is detected" do it "reports that a gem has a newer version" do subject - expect(out).to include("Outdated gems included in the bundle:") - expect(out).to include("activesupport (newest") - expect(out).to_not include("ERROR REPORT TEMPLATE") + + outdated_gems = out.split("\n").drop_while {|l| !l.start_with?("Gem") }[1..-1] + + expect(outdated_gems.size).to be > 0 end end @@ -551,10 +683,7 @@ RSpec.describe "bundle outdated" do shared_examples_for "no version updates are detected" do it "does not detect any version updates" do subject - expect(out).to include("updates to display.") - expect(out).to_not include("ERROR REPORT TEMPLATE") - expect(out).to_not include("activesupport (newest") - expect(out).to_not include("weakling (newest") + expect(out).to end_with("updates to display.") end end @@ -658,45 +787,51 @@ RSpec.describe "bundle outdated" do # establish a lockfile set to 1.0.0 install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" - gem 'patch', '1.0.0' - gem 'minor', '1.0.0' - gem 'major', '1.0.0' + source "#{file_uri_for(gem_repo4)}" + gem 'patch', '1.0.0' + gem 'minor', '1.0.0' + gem 'major', '1.0.0' G # remove 1.4.3 requirement and bar altogether # to setup update specs below gemfile <<-G - source "#{file_uri_for(gem_repo4)}" - gem 'patch' - gem 'minor' - gem 'major' + source "#{file_uri_for(gem_repo4)}" + gem 'patch' + gem 'minor' + gem 'major' G end it "shows nothing when patching and filtering to minor" do bundle "outdated --patch --filter-minor" - expect(out).to include("No minor updates to display.") - expect(out).not_to include("patch (newest") - expect(out).not_to include("minor (newest") - expect(out).not_to include("major (newest") + expect(out).to end_with("No minor updates to display.") end it "shows all gems when patching and filtering to patch" do bundle "outdated --patch --filter-patch" - expect(out).to include("patch (newest 1.0.1") - expect(out).to include("minor (newest 1.0.1") - expect(out).to include("major (newest 1.0.1") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + major 1.0.0 1.0.1 >= 0 default + minor 1.0.0 1.0.1 >= 0 default + patch 1.0.0 1.0.1 >= 0 default + TABLE + + expect(out).to end_with(expected_output) end it "shows minor and major when updating to minor and filtering to patch and minor" do bundle "outdated --minor --filter-minor" - expect(out).not_to include("patch (newest") - expect(out).to include("minor (newest 1.1.0") - expect(out).to include("major (newest 1.1.0") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + major 1.0.0 1.1.0 >= 0 default + minor 1.0.0 1.1.0 >= 0 default + TABLE + + expect(out).to end_with(expected_output) end it "shows minor when updating to major and filtering to minor with parseable" do @@ -744,9 +879,13 @@ RSpec.describe "bundle outdated" do it "shows gems with update-strict updating to patch and filtering to patch" do bundle "outdated --patch --update-strict --filter-patch" - expect(out).to include("foo (newest 1.4.4") - expect(out).to include("bar (newest 2.0.5") - expect(out).not_to include("qux (newest") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + bar 2.0.3 2.0.5 + foo 1.4.3 1.4.4 >= 0 default + TABLE + + expect(out).to end_with(expected_output) end end end @@ -773,8 +912,12 @@ RSpec.describe "bundle outdated" do bundle "outdated --only-explicit" - expect(out).to include("weakling (newest 0.3") - expect(out).not_to include("bar (newest 2.2") + expected_output = <<~TABLE.strip + Gem Current Latest Requested Groups + weakling 0.2 0.3 >= 0 default + TABLE + + expect(out).to end_with(expected_output) end end end diff --git a/spec/bundler/commands/pristine_spec.rb b/spec/bundler/commands/pristine_spec.rb index cc7f760d74..15336137b6 100644 --- a/spec/bundler/commands/pristine_spec.rb +++ b/spec/bundler/commands/pristine_spec.rb @@ -22,12 +22,14 @@ RSpec.describe "bundle pristine", :ruby_repo do source "#{file_uri_for(gem_repo2)}" gem "weakling" gem "very_simple_binary" - gem "foo", :git => "#{lib_path("foo")}" + gem "foo", :git => "#{lib_path("foo")}", :branch => "master" gem "git_with_ext", :git => "#{lib_path("git_with_ext")}" gem "bar", :path => "#{lib_path("bar")}" gemspec G + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end context "when sourced from RubyGems" do @@ -81,6 +83,19 @@ RSpec.describe "bundle pristine", :ruby_repo do bundle! "pristine" expect(changes_txt).not_to be_file end + + it "displays warning and ignores changes when a local config exists" do + spec = Bundler.definition.specs["foo"].first + bundle "config set local.#{spec.name} #{lib_path(spec.name)}" + + changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt") + FileUtils.touch(changes_txt) + expect(changes_txt).to be_file + + bundle "pristine" + expect(changes_txt).to be_file + expect(err).to include("Cannot pristine #{spec.name} (#{spec.version}#{spec.git_version}). Gem is locally overriden.") + end end context "when sourced from gemspec" do diff --git a/spec/bundler/commands/remove_spec.rb b/spec/bundler/commands/remove_spec.rb index 402faaf1f3..ef313928e2 100644 --- a/spec/bundler/commands/remove_spec.rb +++ b/spec/bundler/commands/remove_spec.rb @@ -54,7 +54,7 @@ RSpec.describe "bundle remove" do bundle "remove rack" - expect(err).to include("`rack` is not specified in #{bundled_app("Gemfile")} so it could not be removed.") + expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") end end end @@ -91,7 +91,7 @@ RSpec.describe "bundle remove" do bundle "remove rails rack minitest" - expect(err).to include("`rack` is not specified in #{bundled_app("Gemfile")} so it could not be removed.") + expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") gemfile_should_be <<-G source "#{file_uri_for(gem_repo1)}" @@ -436,7 +436,7 @@ RSpec.describe "bundle remove" do bundle "remove rack" - expect(err).to include("`rack` is not specified in #{bundled_app("Gemfile")} so it could not be removed.") + expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") end end diff --git a/spec/bundler/commands/show_spec.rb b/spec/bundler/commands/show_spec.rb index 61b8f73e7f..de3c41f172 100644 --- a/spec/bundler/commands/show_spec.rb +++ b/spec/bundler/commands/show_spec.rb @@ -3,35 +3,35 @@ RSpec.describe "bundle show", :bundler => "< 3" do context "with a standard Gemfile" do before :each do - install_gemfile <<-G + install_gemfile! <<-G source "#{file_uri_for(gem_repo1)}" gem "rails" G end it "creates a Gemfile.lock if one did not exist" do - FileUtils.rm("Gemfile.lock") + FileUtils.rm(bundled_app_lock) - bundle "show" + bundle! "show" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "creates a Gemfile.lock when invoked with a gem name" do - FileUtils.rm("Gemfile.lock") + FileUtils.rm(bundled_app_lock) - bundle "show rails" + bundle! "show rails" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "prints path if gem exists in bundle" do - bundle "show rails" + bundle! "show rails" expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) end it "prints path if gem exists in bundle (with --paths option)" do - bundle "show rails --paths" + bundle! "show rails --paths" expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) end @@ -45,7 +45,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do end it "prints the path to the running bundler" do - bundle "show bundler" + bundle! "show bundler" expect(out).to eq(root.to_s) end @@ -55,9 +55,9 @@ RSpec.describe "bundle show", :bundler => "< 3" do end it "prints path of all gems in bundle sorted by name" do - bundle "show --paths" + bundle! "show --paths" - expect(out).to include(default_bundle_path("gems", "rake-12.3.2").to_s) + expect(out).to include(default_bundle_path("gems", "rake-13.0.1").to_s) expect(out).to include(default_bundle_path("gems", "rails-2.3.2").to_s) # Gem names are the last component of their path. @@ -66,7 +66,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do end it "prints summary of gems" do - bundle "show --verbose" + bundle! "show --verbose" expect(out).to include <<~MSG * actionmailer (2.3.2) @@ -77,7 +77,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do end it "includes bundler in the summary of gems" do - bundle "show --verbose" + bundle! "show --verbose" expect(out).to include <<~MSG * bundler (#{Bundler::VERSION}) @@ -94,12 +94,12 @@ RSpec.describe "bundle show", :bundler => "< 3" do end it "prints out git info" do - install_gemfile <<-G + install_gemfile! <<-G gem "foo", :git => "#{lib_path("foo-1.0")}" G expect(the_bundle).to include_gems "foo 1.0" - bundle :show + bundle! :show expect(out).to include("foo (1.0 #{@git.ref_for("master", 6)}") end @@ -109,28 +109,28 @@ RSpec.describe "bundle show", :bundler => "< 3" do end @revision = revision_for(lib_path("foo-1.0"))[0...6] - install_gemfile <<-G + install_gemfile! <<-G gem "foo", :git => "#{lib_path("foo-1.0")}", :branch => "omg" G expect(the_bundle).to include_gems "foo 1.0.omg" - bundle :show + bundle! :show expect(out).to include("foo (1.0 #{@git.ref_for("omg", 6)}") end it "doesn't print the branch when tied to a ref" do sha = revision_for(lib_path("foo-1.0")) - install_gemfile <<-G + install_gemfile! <<-G gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{sha}" G - bundle :show + bundle! :show expect(out).to include("foo (1.0 #{sha[0..6]})") end it "handles when a version is a '-' prerelease" do @git = build_git("foo", "1.0.0-beta.1", :path => lib_path("foo")) - install_gemfile <<-G + install_gemfile! <<-G gem "foo", "1.0.0-beta.1", :git => "#{lib_path("foo")}" G expect(the_bundle).to include_gems "foo 1.0.0.pre.beta.1" @@ -143,13 +143,12 @@ RSpec.describe "bundle show", :bundler => "< 3" do context "in a fresh gem in a blank git repo" do before :each do build_git "foo", :path => lib_path("foo") - in_app_root_custom lib_path("foo") - File.open("Gemfile", "w") {|f| f.puts "gemspec" } - sys_exec "rm -rf .git && git init" + File.open(lib_path("foo/Gemfile"), "w") {|f| f.puts "gemspec" } + sys_exec "rm -rf .git && git init", :dir => lib_path("foo") end it "does not output git errors" do - bundle :show + bundle :show, :dir => lib_path("foo") expect(err_without_deprecations).to be_empty end end @@ -161,26 +160,26 @@ RSpec.describe "bundle show", :bundler => "< 3" do G bundle "config set auto_install 1" - bundle :show + bundle! :show expect(out).to include("Installing foo 1.0") end context "with a valid regexp for gem name" do - it "presents alternatives" do - install_gemfile <<-G + it "presents alternatives", :readline do + install_gemfile! <<-G source "#{file_uri_for(gem_repo1)}" gem "rack" gem "rack-obama" G - bundle "show rac" + bundle! "show rac" expect(out).to eq "1 : rack\n2 : rack-obama\n0 : - exit -\n>" end end context "with an invalid regexp for gem name" do it "does not find the gem" do - install_gemfile <<-G + install_gemfile! <<-G source "#{file_uri_for(gem_repo1)}" gem "rails" G @@ -193,7 +192,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do end context "--outdated option" do - # Regression test for https://github.com/bundler/bundler/issues/5375 + # Regression test for https://github.com/rubygems/bundler/issues/5375 before do build_repo2 end diff --git a/spec/bundler/commands/update_spec.rb b/spec/bundler/commands/update_spec.rb index e4449312eb..f8b8800de4 100644 --- a/spec/bundler/commands/update_spec.rb +++ b/spec/bundler/commands/update_spec.rb @@ -31,7 +31,7 @@ RSpec.describe "bundle update" do exit! G bundle "update" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end end @@ -54,7 +54,7 @@ RSpec.describe "bundle update" do exit! G bundle "update", :all => true - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end end @@ -681,8 +681,7 @@ RSpec.describe "bundle update" do G bundle! "update", :all => true - out.gsub!(/RubyGems [\d\.]+ is not threadsafe.*\n?/, "") - expect(out).to include "Resolving dependencies...\nBundle updated!" + expect(out).to match(/Resolving dependencies\.\.\.\.*\nBundle updated!/) update_repo4 do build_gem "foo", "2.0" @@ -690,13 +689,7 @@ RSpec.describe "bundle update" do bundle! "update", :all => true out.sub!("Removing foo (1.0)\n", "") - out.gsub!(/RubyGems [\d\.]+ is not threadsafe.*\n?/, "") - expect(out).to include strip_whitespace(<<-EOS).strip - Resolving dependencies... - Fetching foo 2.0 (was 1.0) - Installing foo 2.0 (was 1.0) - Bundle updated - EOS + expect(out).to match(/Resolving dependencies\.\.\.\.*\nFetching foo 2\.0 \(was 1\.0\)\nInstalling foo 2\.0 \(was 1\.0\)\nBundle updated/) end end @@ -831,6 +824,7 @@ RSpec.describe "bundle update --bundler" do source "#{file_uri_for(gem_repo4)}" gem "rack" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2') FileUtils.rm_r gem_repo4 diff --git a/spec/bundler/install/allow_offline_install_spec.rb b/spec/bundler/install/allow_offline_install_spec.rb index 8af88b7efe..7813a3426d 100644 --- a/spec/bundler/install/allow_offline_install_spec.rb +++ b/spec/bundler/install/allow_offline_install_spec.rb @@ -26,7 +26,7 @@ RSpec.describe "bundle install with :allow_offline_install" do context "with cached data locally" do it "will install from the compact index" do - system_gems ["rack-1.0.0"], :path => :bundle_path + system_gems ["rack-1.0.0"], :path => default_bundle_path bundle! "config set clean false" install_gemfile! <<-G, :artifice => "compact_index" @@ -70,6 +70,8 @@ RSpec.describe "bundle install with :allow_offline_install" do end it "will install from a cached git repo" do + skip "doesn't print errors" if Gem.win_platform? + git = build_git "a", "1.0.0", :path => lib_path("a") update_git("a", :path => git.path, :branch => "new_branch") install_gemfile! <<-G diff --git a/spec/bundler/install/bundler_spec.rb b/spec/bundler/install/bundler_spec.rb index 6ea15d13b5..25cc12160c 100644 --- a/spec/bundler/install/bundler_spec.rb +++ b/spec/bundler/install/bundler_spec.rb @@ -133,27 +133,29 @@ RSpec.describe "bundle install" do it "can install dependencies with newer bundler version with system gems" do bundle! "config set path.system true" - install_gemfile! <<-G + + system_gems "bundler-99999999.99.1" + + install_gemfile! <<-G, :system_bundler => true source "#{file_uri_for(gem_repo2)}" gem "rails", "3.0" G - simulate_bundler_version "99999999.99.1" - - bundle! "check" + bundle! "check", :system_bundler => true expect(out).to include("The Gemfile's dependencies are satisfied") end it "can install dependencies with newer bundler version with a local path" do bundle! "config set path .bundle" - install_gemfile! <<-G + + system_gems "bundler-99999999.99.1" + + install_gemfile! <<-G, :system_bundler => true source "#{file_uri_for(gem_repo2)}" gem "rails", "3.0" G - simulate_bundler_version "99999999.99.1" - - bundle! "check" + bundle! "check", :system_bundler => true expect(out).to include("The Gemfile's dependencies are satisfied") end diff --git a/spec/bundler/install/deploy_spec.rb b/spec/bundler/install/deploy_spec.rb index f92a531bf5..121b99fd8c 100644 --- a/spec/bundler/install/deploy_spec.rb +++ b/spec/bundler/install/deploy_spec.rb @@ -43,13 +43,12 @@ RSpec.describe "install with --deployment or --frozen" do it "still works if you are not in the app directory and specify --gemfile" do bundle! "install" - Dir.chdir tmp do - simulate_new_machine - bundle! :install, - forgotten_command_line_options(:gemfile => "#{tmp}/bundled_app/Gemfile", - :deployment => true, - :path => "vendor/bundle") - end + simulate_new_machine + bundle! :install, + forgotten_command_line_options(:gemfile => "#{tmp}/bundled_app/Gemfile", + :deployment => true, + :path => "vendor/bundle", + :dir => tmp) expect(the_bundle).to include_gems "rack 1.0" end @@ -65,6 +64,8 @@ RSpec.describe "install with --deployment or --frozen" do end it "works when you bundle exec bundle" do + skip "doesn't find bundle" if Gem.win_platform? + bundle! :install bundle "install --deployment" bundle! "exec bundle check" @@ -332,6 +333,8 @@ RSpec.describe "install with --deployment or --frozen" do end it "explodes if you unpin a source" do + skip "some of monorepo issues" if Gem.win_platform? + build_git "rack" install_gemfile <<-G @@ -352,6 +355,8 @@ RSpec.describe "install with --deployment or --frozen" do end it "explodes if you unpin a source, leaving it pinned somewhere else" do + skip "some of monorepo issues" if Gem.win_platform? + build_lib "foo", :path => lib_path("rack/foo") build_git "rack", :path => lib_path("rack") diff --git a/spec/bundler/install/gemfile/eval_gemfile_spec.rb b/spec/bundler/install/gemfile/eval_gemfile_spec.rb index 7df94aaff5..69341250c3 100644 --- a/spec/bundler/install/gemfile/eval_gemfile_spec.rb +++ b/spec/bundler/install/gemfile/eval_gemfile_spec.rb @@ -28,8 +28,8 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do context "eval-ed Gemfile has relative-path gems" do before do - build_lib("a", :path => "gems/a") - create_file "nested/Gemfile-nested", <<-G + build_lib("a", :path => bundled_app("gems/a")) + create_file bundled_app("nested/Gemfile-nested"), <<-G gem "a", :path => "../gems/a" G diff --git a/spec/bundler/install/gemfile/gemspec_spec.rb b/spec/bundler/install/gemfile/gemspec_spec.rb index 26a6235166..b42587c65f 100644 --- a/spec/bundler/install/gemfile/gemspec_spec.rb +++ b/spec/bundler/install/gemfile/gemspec_spec.rb @@ -117,21 +117,19 @@ RSpec.describe "bundle install from an existing gemspec" do build_lib("foo", :path => tmp.join("foo")) do |s| s.write("Gemfile", "source '#{file_uri_for(gem_repo1)}'\ngemspec") s.add_dependency "actionpack", "=2.3.2" - s.add_development_dependency "rake", "=12.3.2" + s.add_development_dependency "rake", "=13.0.1" end - Dir.chdir(tmp.join("foo")) do - bundle "install" - # This should really be able to rely on $stderr, but, it's not written - # right, so we can't. In fact, this is a bug negation test, and so it'll - # ghost pass in future, and will only catch a regression if the message - # doesn't change. Exit codes should be used correctly (they can be more - # than just 0 and 1). - output = bundle("install --deployment") - expect(output).not_to match(/You have added to the Gemfile/) - expect(output).not_to match(/You have deleted from the Gemfile/) - expect(output).not_to match(/install in deployment mode after changing/) - end + bundle "install", :dir => tmp.join("foo") + # This should really be able to rely on $stderr, but, it's not written + # right, so we can't. In fact, this is a bug negation test, and so it'll + # ghost pass in future, and will only catch a regression if the message + # doesn't change. Exit codes should be used correctly (they can be more + # than just 0 and 1). + output = bundle("install --deployment", :dir => tmp.join("foo")) + expect(output).not_to match(/You have added to the Gemfile/) + expect(output).not_to match(/You have deleted from the Gemfile/) + expect(output).not_to match(/install in deployment mode after changing/) end it "should match a lockfile without needing to re-resolve" do @@ -169,15 +167,12 @@ RSpec.describe "bundle install from an existing gemspec" do expect(out.scan(message).size).to eq(1) end - it "should match a lockfile on non-ruby platforms with a transitive platform dependency" do - simulate_platform java - simulate_ruby_engine "jruby" - + it "should match a lockfile on non-ruby platforms with a transitive platform dependency", :jruby do build_lib("foo", :path => tmp.join("foo")) do |s| s.add_dependency "platform_specific" end - system_gems "platform_specific-1.0-java", :path => :bundle_path, :keep_path => true + system_gems "platform_specific-1.0-java", :path => default_bundle_path, :keep_path => true install_gemfile! <<-G gemspec :path => '#{tmp.join("foo")}' @@ -201,7 +196,7 @@ RSpec.describe "bundle install from an existing gemspec" do it "allows the gemspec to activate other gems" do ENV["BUNDLE_PATH__SYSTEM"] = "true" - # see https://github.com/bundler/bundler/issues/5409 + # see https://github.com/rubygems/bundler/issues/5409 # # issue was caused by rubygems having an unresolved gem during a require, # so emulate that @@ -333,6 +328,8 @@ RSpec.describe "bundle install from an existing gemspec" do let(:platform) { "ruby" } before do + skip "not installing for some reason" if Gem.win_platform? + build_lib("foo", :path => tmp.join("foo")) do |s| s.add_dependency "rack", "=1.0.0" end @@ -365,13 +362,11 @@ RSpec.describe "bundle install from an existing gemspec" do L end - context "using JRuby with explicit platform" do - let(:platform) { "java" } - + context "using JRuby with explicit platform", :jruby do before do create_file( - tmp.join("foo", "foo-#{platform}.gemspec"), - build_spec("foo", "1.0", platform) do + tmp.join("foo", "foo-java.gemspec"), + build_spec("foo", "1.0", "java") do dep "rack", "=1.0.0" @spec.authors = "authors" @spec.summary = "summary" @@ -380,27 +375,17 @@ RSpec.describe "bundle install from an existing gemspec" do end it "should install" do - simulate_ruby_engine "jruby" do - simulate_platform "java" do - results = bundle "install", :artifice => "endpoint" - expect(results).to include("Installing rack 1.0.0") - expect(the_bundle).to include_gems "rack 1.0.0" - end - end + results = bundle "install", :artifice => "endpoint" + expect(results).to include("Installing rack 1.0.0") + expect(the_bundle).to include_gems "rack 1.0.0" end end - context "using JRuby" do - let(:platform) { "java" } - + context "using JRuby", :jruby do it "should install" do - simulate_ruby_engine "jruby" do - simulate_platform "java" do - results = bundle "install", :artifice => "endpoint" - expect(results).to include("Installing rack 1.0.0") - expect(the_bundle).to include_gems "rack 1.0.0" - end - end + results = bundle "install", :artifice => "endpoint" + expect(results).to include("Installing rack 1.0.0") + expect(the_bundle).to include_gems "rack 1.0.0" end end @@ -425,7 +410,7 @@ RSpec.describe "bundle install from an existing gemspec" do end end - build_lib "foo", :path => "." do |s| + build_lib "foo", :path => bundled_app do |s| if platform_specific_type == :runtime s.add_runtime_dependency dependency elsif platform_specific_type == :development diff --git a/spec/bundler/install/gemfile/git_spec.rb b/spec/bundler/install/gemfile/git_spec.rb index 00f8e96625..fd5cde4fb1 100644 --- a/spec/bundler/install/gemfile/git_spec.rb +++ b/spec/bundler/install/gemfile/git_spec.rb @@ -57,22 +57,18 @@ RSpec.describe "bundle install with git sources" do it "does not update the git source implicitly" do update_git "foo" - in_app_root2 do - install_gemfile bundled_app2("Gemfile"), <<-G - git "#{lib_path("foo-1.0")}" do - gem 'foo' - end - G - end + install_gemfile bundled_app2("Gemfile"), <<-G, :dir => bundled_app2 + git "#{lib_path("foo-1.0")}" do + gem 'foo' + end + G - in_app_root do - run <<-RUBY - require 'foo' - puts "fail" if defined?(FOO_PREV_REF) - RUBY + run <<-RUBY + require 'foo' + puts "fail" if defined?(FOO_PREV_REF) + RUBY - expect(out).to be_empty - end + expect(out).to be_empty end it "sets up git gem executables on the path" do @@ -129,19 +125,19 @@ RSpec.describe "bundle install with git sources" do it "still works after moving the application directory" do bundle "install --path vendor/bundle" + FileUtils.mv bundled_app, tmp("bundled_app.bck") - Dir.chdir tmp("bundled_app.bck") - expect(the_bundle).to include_gems "foo 1.0" + expect(the_bundle).to include_gems "foo 1.0", :dir => tmp("bundled_app.bck") end it "can still install after moving the application directory" do bundle "install --path vendor/bundle" + FileUtils.mv bundled_app, tmp("bundled_app.bck") update_git "foo", "1.1", :path => lib_path("foo-1.0") - Dir.chdir tmp("bundled_app.bck") gemfile tmp("bundled_app.bck/Gemfile"), <<-G source "#{file_uri_for(gem_repo1)}" git "#{lib_path("foo-1.0")}" do @@ -151,9 +147,9 @@ RSpec.describe "bundle install with git sources" do gem "rack", "1.0" G - bundle "update foo" + bundle "update foo", :dir => tmp("bundled_app.bck") - expect(the_bundle).to include_gems "foo 1.1", "rack 1.0" + expect(the_bundle).to include_gems "foo 1.1", "rack 1.0", :dir => tmp("bundled_app.bck") end end @@ -220,9 +216,7 @@ RSpec.describe "bundle install with git sources" do s.write("lib/foo.rb", "raise 'FAIL'") end - Dir.chdir(lib_path("foo-1.0")) do - `git update-ref -m "Bundler Spec!" refs/bundler/1 master~1` - end + sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 master~1", :dir => lib_path("foo-1.0")) # want to ensure we don't fallback to HEAD update_git "foo", :path => lib_path("foo-1.0"), :branch => "rando" do |s| @@ -256,9 +250,7 @@ RSpec.describe "bundle install with git sources" do s.write("lib/foo.rb", "raise 'FAIL'") end - Dir.chdir(lib_path("foo-1.0")) do - `git update-ref -m "Bundler Spec!" refs/bundler/1 master~1` - end + sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 master~1", :dir => lib_path("foo-1.0")) # want to ensure we don't fallback to HEAD update_git "foo", :path => lib_path("foo-1.0"), :branch => "rando" do |s| @@ -281,9 +273,7 @@ RSpec.describe "bundle install with git sources" do end it "does not download random non-head refs" do - Dir.chdir(lib_path("foo-1.0")) do - sys_exec!('git update-ref -m "Bundler Spec!" refs/bundler/1 master~1') - end + sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 master~1", :dir => lib_path("foo-1.0")) bundle! "config set global_gem_cache true" @@ -296,9 +286,7 @@ RSpec.describe "bundle install with git sources" do # ensure we also git fetch after cloning bundle! :update, :all => true - Dir.chdir(Dir[home(".bundle/cache/git/foo-*")].first) do - sys_exec("git ls-remote .") - end + sys_exec("git ls-remote .", :dir => Dir[home(".bundle/cache/git/foo-*")].first) expect(out).not_to include("refs/bundler/1") end @@ -307,11 +295,10 @@ RSpec.describe "bundle install with git sources" do describe "when specifying a branch" do let(:branch) { "branch" } let(:repo) { build_git("foo").path } - before(:each) do - update_git("foo", :path => repo, :branch => branch) - end it "works" do + update_git("foo", :path => repo, :branch => branch) + install_gemfile <<-G git "#{repo}", :branch => #{branch.dump} do gem "foo" @@ -324,6 +311,10 @@ RSpec.describe "bundle install with git sources" do context "when the branch starts with a `#`" do let(:branch) { "#149/redirect-url-fragment" } it "works" do + skip "git does not accept this" if Gem.win_platform? + + update_git("foo", :path => repo, :branch => branch) + install_gemfile <<-G git "#{repo}", :branch => #{branch.dump} do gem "foo" @@ -337,6 +328,10 @@ RSpec.describe "bundle install with git sources" do context "when the branch includes quotes" do let(:branch) { %('") } it "works" do + skip "git does not accept this" if Gem.win_platform? + + update_git("foo", :path => repo, :branch => branch) + install_gemfile <<-G git "#{repo}", :branch => #{branch.dump} do gem "foo" @@ -351,11 +346,10 @@ RSpec.describe "bundle install with git sources" do describe "when specifying a tag" do let(:tag) { "tag" } let(:repo) { build_git("foo").path } - before(:each) do - update_git("foo", :path => repo, :tag => tag) - end it "works" do + update_git("foo", :path => repo, :tag => tag) + install_gemfile <<-G git "#{repo}", :tag => #{tag.dump} do gem "foo" @@ -368,6 +362,10 @@ RSpec.describe "bundle install with git sources" do context "when the tag starts with a `#`" do let(:tag) { "#149/redirect-url-fragment" } it "works" do + skip "git does not accept this" if Gem.win_platform? + + update_git("foo", :path => repo, :tag => tag) + install_gemfile <<-G git "#{repo}", :tag => #{tag.dump} do gem "foo" @@ -381,6 +379,10 @@ RSpec.describe "bundle install with git sources" do context "when the tag includes quotes" do let(:tag) { %('") } it "works" do + skip "git does not accept this" if Gem.win_platform? + + update_git("foo", :path => repo, :tag => tag) + install_gemfile <<-G git "#{repo}", :tag => #{tag.dump} do gem "foo" @@ -463,7 +465,7 @@ RSpec.describe "bundle install with git sources" do gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "master" G - lockfile0 = File.read(bundled_app("Gemfile.lock")) + lockfile0 = File.read(bundled_app_lock) FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) update_git "rack", "0.8", :path => lib_path("local-rack") do |s| @@ -473,7 +475,7 @@ RSpec.describe "bundle install with git sources" do bundle %(config set local.rack #{lib_path("local-rack")}) run "require 'rack'" - lockfile1 = File.read(bundled_app("Gemfile.lock")) + lockfile1 = File.read(bundled_app_lock) expect(lockfile1).not_to eq(lockfile0) end @@ -485,7 +487,7 @@ RSpec.describe "bundle install with git sources" do gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "master" G - lockfile0 = File.read(bundled_app("Gemfile.lock")) + lockfile0 = File.read(bundled_app_lock) FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) update_git "rack", "0.8", :path => lib_path("local-rack") @@ -493,7 +495,7 @@ RSpec.describe "bundle install with git sources" do bundle %(config set local.rack #{lib_path("local-rack")}) bundle :install - lockfile1 = File.read(bundled_app("Gemfile.lock")) + lockfile1 = File.read(bundled_app_lock) expect(lockfile1).not_to eq(lockfile0) end @@ -621,6 +623,8 @@ RSpec.describe "bundle install with git sources" do end it "installs dependencies from git even if a newer gem is available elsewhere" do + skip "override is not winning" if Gem.win_platform? + system_gems "rack-1.0.0" build_lib "rack", "1.0", :path => lib_path("nested/bar") do |s| @@ -817,9 +821,7 @@ RSpec.describe "bundle install with git sources" do bundle "update", :all => true expect(the_bundle).to include_gems "forced 1.1" - Dir.chdir(lib_path("forced-1.0")) do - `git reset --hard HEAD^` - end + sys_exec("git reset --hard HEAD^", :dir => lib_path("forced-1.0")) bundle "update", :all => true expect(the_bundle).to include_gems "forced 1.0" @@ -830,10 +832,8 @@ RSpec.describe "bundle install with git sources" do build_git "has_submodule", "1.0" do |s| s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", :dir => lib_path("has_submodule-1.0") + sys_exec "git commit -m \"submodulator\"", :dir => lib_path("has_submodule-1.0") install_gemfile <<-G git "#{lib_path("has_submodule-1.0")}" do @@ -850,10 +850,8 @@ RSpec.describe "bundle install with git sources" do build_git "has_submodule", "1.0" do |s| s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", :dir => lib_path("has_submodule-1.0") + sys_exec "git commit -m \"submodulator\"", :dir => lib_path("has_submodule-1.0") install_gemfile <<-G git "#{lib_path("has_submodule-1.0")}", :submodules => true do @@ -916,6 +914,8 @@ RSpec.describe "bundle install with git sources" do end it "prints a friendly error if a file blocks the git repo" do + skip "drive letter is not detected correctly in error message" if Gem.win_platform? + build_git "foo" FileUtils.mkdir_p(default_bundle_path) @@ -943,7 +943,7 @@ RSpec.describe "bundle install with git sources" do gem "bar", :git => "#{lib_path("nested")}" G - expect(File.read(bundled_app("Gemfile.lock")).scan("GIT").size).to eq(1) + expect(File.read(bundled_app_lock).scan("GIT").size).to eq(1) end describe "switching sources" do @@ -1003,8 +1003,8 @@ RSpec.describe "bundle install with git sources" do update_git "valim" new_revision = revision_for(lib_path("valim-1.0")) - old_lockfile = File.read(bundled_app("Gemfile.lock")) - lockfile(bundled_app("Gemfile.lock"), old_lockfile.gsub(/revision: #{old_revision}/, "revision: #{new_revision}")) + old_lockfile = File.read(bundled_app_lock) + lockfile(bundled_app_lock, old_lockfile.gsub(/revision: #{old_revision}/, "revision: #{new_revision}")) bundle "install" @@ -1150,16 +1150,15 @@ RSpec.describe "bundle install with git sources" do end 2.times do |i| - Dir.chdir(git_reader.path) do - File.open("ext/foo.c", "w") do |file| - file.write <<-C - #include "ruby.h" - VALUE foo() { return INT2FIX(#{i}); } - void Init_foo() { rb_define_global_function("foo", &foo, 0); } - C - end - `git commit -m "commit for iteration #{i}" ext/foo.c` + File.open(git_reader.path.join("ext/foo.c"), "w") do |file| + file.write <<-C + #include "ruby.h" + VALUE foo() { return INT2FIX(#{i}); } + void Init_foo() { rb_define_global_function("foo", &foo, 0); } + C end + sys_exec("git commit -m \"commit for iteration #{i}\" ext/foo.c", :dir => git_reader.path) + git_commit_sha = git_reader.ref_for("HEAD") install_gemfile <<-G @@ -1311,9 +1310,10 @@ In Gemfile: puts FOO R + installed_time = out + update_git("foo", :branch => "branch2") - installed_time = out expect(installed_time).to match(/\A\d+\.\d+\z/) install_gemfile <<-G diff --git a/spec/bundler/install/gemfile/install_if.rb b/spec/bundler/install/gemfile/install_if_spec.rb index 468a2e9052..786e0e9258 100644 --- a/spec/bundler/install/gemfile/install_if.rb +++ b/spec/bundler/install/gemfile/install_if_spec.rb @@ -29,7 +29,7 @@ RSpec.describe "bundle install with install_if conditionals" do rack PLATFORMS - ruby + #{lockfile_platforms} DEPENDENCIES activesupport (= 2.3.5) diff --git a/spec/bundler/install/gemfile/path_spec.rb b/spec/bundler/install/gemfile/path_spec.rb index e53636da09..a733c02512 100644 --- a/spec/bundler/install/gemfile/path_spec.rb +++ b/spec/bundler/install/gemfile/path_spec.rb @@ -37,7 +37,7 @@ RSpec.describe "bundle install with explicit source paths" do it "supports relative paths" do build_lib "foo" - relative_path = lib_path("foo-1.0").relative_path_from(Pathname.new(Dir.pwd)) + relative_path = lib_path("foo-1.0").relative_path_from(bundled_app) install_gemfile <<-G gem 'foo', :path => "#{relative_path}" @@ -59,6 +59,8 @@ RSpec.describe "bundle install with explicit source paths" do end it "expands paths raise error with not existing user's home dir" do + skip "problems with ~ expansion" if Gem.win_platform? + build_lib "foo" username = "some_unexisting_user" relative_path = lib_path("foo-1.0").relative_path_from(Pathname.new("/home/#{username}").expand_path) @@ -77,10 +79,7 @@ RSpec.describe "bundle install with explicit source paths" do gem 'foo', :path => "./foo-1.0" G - bundled_app("subdir").mkpath - Dir.chdir(bundled_app("subdir")) do - expect(the_bundle).to include_gems("foo 1.0") - end + expect(the_bundle).to include_gems("foo 1.0", :dir => bundled_app("subdir").mkpath) end it "sorts paths consistently on install and update when they start with ./" do @@ -119,12 +118,10 @@ RSpec.describe "bundle install with explicit source paths" do #{Bundler::VERSION} L - Dir.chdir(lib_path("demo")) do - bundle :install - expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) - bundle :update, :all => true - expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) - end + bundle :install, :dir => lib_path("demo") + expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) + bundle :update, :all => true, :dir => lib_path("demo") + expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) end it "expands paths when comparing locked paths to Gemfile paths" do @@ -139,6 +136,8 @@ RSpec.describe "bundle install with explicit source paths" do end it "installs dependencies from the path even if a newer gem is available elsewhere" do + skip "override is not winning" if Gem.win_platform? + system_gems "rack-1.0.0" build_lib "rack", "1.0", :path => lib_path("nested/bar") do |s| @@ -227,7 +226,6 @@ RSpec.describe "bundle install with explicit source paths" do gem "foo", :path => "#{lib_path("foo-1.0")}" G - expect(err).to_not include("ERROR REPORT") expect(err).to_not include("Your Gemfile has no gem server sources.") expect(err).to match(/is not valid. Please fix this gemspec./) expect(err).to match(/The validation error was 'missing value for attribute version'/) @@ -246,11 +244,9 @@ RSpec.describe "bundle install with explicit source paths" do File.open(lib_path("foo/Gemfile"), "w") {|f| f.puts gemfile } - Dir.chdir(lib_path("foo")) do - bundle "install" - expect(the_bundle).to include_gems "foo 1.0" - expect(the_bundle).to include_gems "rack 1.0" - end + bundle "install", :dir => lib_path("foo") + expect(the_bundle).to include_gems "foo 1.0", :dir => lib_path("foo") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("foo") end it "supports gemspec syntax with an alternative path" do @@ -272,19 +268,17 @@ RSpec.describe "bundle install with explicit source paths" do s.add_dependency "rack", ">= 1.0" end - Dir.chdir lib_path("foo") - - install_gemfile lib_path("foo/Gemfile"), <<-G + install_gemfile lib_path("foo/Gemfile"), <<-G, :dir => lib_path("foo") source "#{file_uri_for(gem_repo1)}" gemspec G build_gem "rack", "1.0.1", :to_system => true - bundle "install" + bundle "install", :dir => lib_path("foo") - expect(the_bundle).to include_gems "foo 1.0" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "foo 1.0", :dir => lib_path("foo") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("foo") end it "doesn't automatically unlock dependencies when using the gemspec syntax and the gem has development dependencies" do @@ -293,19 +287,17 @@ RSpec.describe "bundle install with explicit source paths" do s.add_development_dependency "activesupport" end - Dir.chdir lib_path("foo") - - install_gemfile lib_path("foo/Gemfile"), <<-G + install_gemfile lib_path("foo/Gemfile"), <<-G, :dir => lib_path("foo") source "#{file_uri_for(gem_repo1)}" gemspec G build_gem "rack", "1.0.1", :to_system => true - bundle "install" + bundle "install", :dir => lib_path("foo") - expect(the_bundle).to include_gems "foo 1.0" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "foo 1.0", :dir => lib_path("foo") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("foo") end it "raises if there are multiple gemspecs" do @@ -423,7 +415,7 @@ RSpec.describe "bundle install with explicit source paths" do remote: http://rubygems.org L - in_app_root { FileUtils.mkdir_p("vendor/bar") } + FileUtils.mkdir_p(bundled_app("vendor/bar")) install_gemfile <<-G gem "bar", "1.0.0", path: "vendor/bar", require: "bar/nyard" @@ -645,6 +637,8 @@ RSpec.describe "bundle install with explicit source paths" do describe "when there are both a gemspec and remote gems" do it "doesn't query rubygems for local gemspec name" do + skip "platform issues" if Gem.win_platform? + build_lib "private_lib", "2.2", :path => lib_path("private_lib") gemfile = <<-G source "http://localgemserver.test" @@ -653,13 +647,11 @@ RSpec.describe "bundle install with explicit source paths" do G File.open(lib_path("private_lib/Gemfile"), "w") {|f| f.puts gemfile } - Dir.chdir(lib_path("private_lib")) do - bundle :install, :env => { "DEBUG" => "1" }, :artifice => "endpoint" - expect(out).to match(%r{^HTTP GET http://localgemserver\.test/api/v1/dependencies\?gems=rack$}) - expect(out).not_to match(/^HTTP GET.*private_lib/) - expect(the_bundle).to include_gems "private_lib 2.2" - expect(the_bundle).to include_gems "rack 1.0" - end + bundle :install, :env => { "DEBUG" => "1" }, :artifice => "endpoint", :dir => lib_path("private_lib") + expect(out).to match(%r{^HTTP GET http://localgemserver\.test/api/v1/dependencies\?gems=rack$}) + expect(out).not_to match(/^HTTP GET.*private_lib/) + expect(the_bundle).to include_gems "private_lib 2.2", :dir => lib_path("private_lib") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("private_lib") end end diff --git a/spec/bundler/install/gemfile/platform_spec.rb b/spec/bundler/install/gemfile/platform_spec.rb index c096531398..e33cb29ef8 100644 --- a/spec/bundler/install/gemfile/platform_spec.rb +++ b/spec/bundler/install/gemfile/platform_spec.rb @@ -274,6 +274,8 @@ end RSpec.describe "bundle install with platform conditionals" do it "installs gems tagged w/ the current platforms" do + skip "platform issues" if Gem.win_platform? + install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -299,6 +301,8 @@ RSpec.describe "bundle install with platform conditionals" do end it "installs gems tagged w/ the current platforms inline" do + skip "platform issues" if Gem.win_platform? + install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "nokogiri", :platforms => :#{local_tag} @@ -317,6 +321,8 @@ RSpec.describe "bundle install with platform conditionals" do end it "installs gems tagged w/ the current platform inline" do + skip "platform issues" if Gem.win_platform? + install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "nokogiri", :platform => :#{local_tag} @@ -347,7 +353,6 @@ RSpec.describe "bundle install with platform conditionals" do it "does not attempt to install gems from :rbx when using --local" do simulate_platform "ruby" - simulate_ruby_engine "ruby" gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -360,7 +365,6 @@ RSpec.describe "bundle install with platform conditionals" do it "does not attempt to install gems from other rubies when using --local" do simulate_platform "ruby" - simulate_ruby_engine "ruby" other_ruby_version_tag = RUBY_VERSION =~ /^1\.8/ ? :ruby_19 : :ruby_18 gemfile <<-G @@ -372,9 +376,8 @@ RSpec.describe "bundle install with platform conditionals" do expect(out).not_to match(/Could not find gem 'some_gem/) end - it "prints a helpful warning when a dependency is unused on any platform" do + it "resolves all platforms by default and without warning messages" do simulate_platform "ruby" - simulate_ruby_engine "ruby" gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -384,28 +387,27 @@ RSpec.describe "bundle install with platform conditionals" do bundle! "install" - expect(err).to include <<-O.strip -The dependency #{Gem::Dependency.new("rack", ">= 0")} will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. - O - end - - context "when disable_platform_warnings is true" do - before { bundle! "config set disable_platform_warnings true" } + expect(err).to be_empty - it "does not print the warning when a dependency is unused on any platform" do - simulate_platform "ruby" - simulate_ruby_engine "ruby" - - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + lockfile_should_be <<-L + GEM + remote: #{file_uri_for(gem_repo1)}/ + specs: + rack (1.0.0) - gem "rack", :platform => [:mingw, :mswin, :x64_mingw, :jruby] - G + PLATFORMS + java + ruby + x64-mingw32 + x86-mingw32 + x86-mswin32 - bundle! "install" + DEPENDENCIES + rack - expect(out).not_to match(/The dependency (.*) will be unused/) - end + BUNDLED WITH + #{Bundler::VERSION} + L end end diff --git a/spec/bundler/install/gemfile/ruby_spec.rb b/spec/bundler/install/gemfile/ruby_spec.rb index d1e9fc7e05..aab269b325 100644 --- a/spec/bundler/install/gemfile/ruby_spec.rb +++ b/spec/bundler/install/gemfile/ruby_spec.rb @@ -2,10 +2,10 @@ RSpec.describe "ruby requirement" do def locked_ruby_version - Bundler::RubyVersion.from_string(Bundler::LockfileParser.new(lockfile).ruby_version) + Bundler::RubyVersion.from_string(Bundler::LockfileParser.new(File.read(bundled_app_lock)).ruby_version) end - # As discovered by https://github.com/bundler/bundler/issues/4147, there is + # As discovered by https://github.com/rubygems/bundler/issues/4147, there is # no test coverage to ensure that adding a gem is possible with a ruby # requirement. This test verifies the fix, committed in bfbad5c5. it "allows adding gems" do @@ -51,6 +51,7 @@ RSpec.describe "ruby requirement" do gem "rack" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) simulate_ruby_version "5100" @@ -72,6 +73,7 @@ RSpec.describe "ruby requirement" do gem "rack" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) simulate_ruby_version "5100" diff --git a/spec/bundler/install/gemfile/sources_spec.rb b/spec/bundler/install/gemfile/sources_spec.rb index 61943ef2e5..6e29d786f1 100644 --- a/spec/bundler/install/gemfile/sources_spec.rb +++ b/spec/bundler/install/gemfile/sources_spec.rb @@ -285,7 +285,7 @@ RSpec.describe "bundle install with gems on multiple sources" do expect(err).not_to include("Warning: the gem 'rack' was found in multiple sources.") expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0") - # In https://github.com/bundler/bundler/issues/3585 this failed + # In https://github.com/rubygems/bundler/issues/3585 this failed # when there is already a lock file, and the gems are missing, so try again system_gems [] bundle :install @@ -402,7 +402,7 @@ RSpec.describe "bundle install with gems on multiple sources" do context "with an existing lockfile" do before do - system_gems "rack-0.9.1", "rack-1.0.0", :path => :bundle_path + system_gems "rack-0.9.1", "rack-1.0.0", :path => default_bundle_path lockfile <<-L GEM @@ -426,7 +426,7 @@ RSpec.describe "bundle install with gems on multiple sources" do G end - # Reproduction of https://github.com/bundler/bundler/issues/3298 + # Reproduction of https://github.com/rubygems/bundler/issues/3298 it "does not unlock the installed gem on exec" do expect(the_bundle).to include_gems("rack 0.9.1") end diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb index 24b602589f..a1cc6b3551 100644 --- a/spec/bundler/install/gemfile/specific_platform_spec.rb +++ b/spec/bundler/install/gemfile/specific_platform_spec.rb @@ -58,6 +58,7 @@ RSpec.describe "bundle install with specific_platform enabled" do it "locks to both the specific darwin platform and ruby" do install_gemfile!(google_protobuf) + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(the_bundle.locked_gems.platforms).to eq([pl("ruby"), pl("x86_64-darwin-15")]) expect(the_bundle).to include_gem("google-protobuf 3.0.0.alpha.5.0.5.1 universal-darwin") expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[ @@ -78,6 +79,7 @@ RSpec.describe "bundle install with specific_platform enabled" do source "#{file_uri_for(gem_repo2)}" gem "facter" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(the_bundle.locked_gems.platforms).to eq([pl("ruby"), pl("x86_64-darwin-15")]) expect(the_bundle).to include_gems("facter 2.4.6 universal-darwin", "CFPropertyList 1.0") @@ -87,6 +89,10 @@ RSpec.describe "bundle install with specific_platform enabled" do end context "when adding a platform via lock --add_platform" do + before do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + end + it "adds the foreign platform" do install_gemfile!(google_protobuf) bundle! "lock --add-platform=#{x64_mingw}" diff --git a/spec/bundler/install/gemfile_spec.rb b/spec/bundler/install/gemfile_spec.rb index dd08939cb0..4988bfea47 100644 --- a/spec/bundler/install/gemfile_spec.rb +++ b/spec/bundler/install/gemfile_spec.rb @@ -44,20 +44,14 @@ RSpec.describe "bundle install" do end it "uses the gemfile while in a subdirectory" do bundled_app("subdir").mkpath - Dir.chdir(bundled_app("subdir")) do - bundle "install" - bundle "list" + bundle "install", :dir => bundled_app("subdir") + bundle "list", :dir => bundled_app("subdir") - expect(out).to include("rack (1.0.0)") - end + expect(out).to include("rack (1.0.0)") end end context "with deprecated features" do - before :each do - in_app_root - end - it "reports that lib is an invalid option" do gemfile <<-G gem "rack", :lib => "rack" @@ -68,32 +62,24 @@ RSpec.describe "bundle install" do end end - context "with engine specified in symbol" do + context "with engine specified in symbol", :jruby do it "does not raise any error parsing Gemfile" do - simulate_ruby_version "2.3.0" do - simulate_ruby_engine "jruby", "9.1.2.0" do - install_gemfile! <<-G - source "#{file_uri_for(gem_repo1)}" - ruby "2.3.0", :engine => :jruby, :engine_version => "9.1.2.0" - G - - expect(out).to match(/Bundle complete!/) - end - end + install_gemfile! <<-G + source "#{file_uri_for(gem_repo1)}" + ruby "#{RUBY_VERSION}", :engine => :jruby, :engine_version => "#{RUBY_ENGINE_VERSION}" + G + + expect(out).to match(/Bundle complete!/) end it "installation succeeds" do - simulate_ruby_version "2.3.0" do - simulate_ruby_engine "jruby", "9.1.2.0" do - install_gemfile! <<-G - source "#{file_uri_for(gem_repo1)}" - ruby "2.3.0", :engine => :jruby, :engine_version => "9.1.2.0" - gem "rack" - G - - expect(the_bundle).to include_gems "rack 1.0.0" - end - end + install_gemfile! <<-G + source "#{file_uri_for(gem_repo1)}" + ruby "#{RUBY_VERSION}", :engine => :jruby, :engine_version => "#{RUBY_ENGINE_VERSION}" + gem "rack" + G + + expect(the_bundle).to include_gems "rack 1.0.0" end end diff --git a/spec/bundler/install/gems/compact_index_spec.rb b/spec/bundler/install/gems/compact_index_spec.rb index a294b83d1c..2452d82667 100644 --- a/spec/bundler/install/gems/compact_index_spec.rb +++ b/spec/bundler/install/gems/compact_index_spec.rb @@ -404,22 +404,19 @@ The checksum of /versions does not match the checksum provided by the server! So s.add_dependency "foo" end build_gem "missing" - # need to hit the limit - 1.upto(Bundler::Source::Rubygems::API_REQUEST_LIMIT) do |i| - build_gem "gem#{i}" - end FileUtils.rm_rf Dir[gem_repo2("gems/foo-*.gem")] end - gemfile <<-G + api_request_limit = low_api_request_limit_for(gem_repo2) + + install_gemfile! <<-G, :artifice => "compact_index_extra_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s } source "#{source_uri}" source "#{source_uri}/extra" do gem "back_deps" end G - bundle! :install, :artifice => "compact_index_extra_missing" expect(the_bundle).to include_gems "back_deps 1.0" end @@ -429,15 +426,13 @@ The checksum of /versions does not match the checksum provided by the server! So s.add_dependency "foo" end build_gem "missing" - # need to hit the limit - 1.upto(Bundler::Source::Rubygems::API_REQUEST_LIMIT) do |i| - build_gem "gem#{i}" - end FileUtils.rm_rf Dir[gem_repo4("gems/foo-*.gem")] end - install_gemfile! <<-G, :artifice => "compact_index_extra_api_missing" + api_request_limit = low_api_request_limit_for(gem_repo4) + + install_gemfile! <<-G, :artifice => "compact_index_extra_api_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s } source "#{source_uri}" source "#{source_uri}/extra" do gem "back_deps" @@ -523,6 +518,8 @@ The checksum of /versions does not match the checksum provided by the server! So end it "installs the binstubs", :bundler => "< 3" do + skip "exec format error" if Gem.win_platform? + gemfile <<-G source "#{source_uri}" gem "rack" @@ -581,7 +578,7 @@ The checksum of /versions does not match the checksum provided by the server! So let(:user) { "user" } let(:password) { "pass" } let(:basic_auth_source_uri) do - uri = URI.parse(source_uri) + uri = Bundler::URI.parse(source_uri) uri.user = user uri.password = password @@ -736,7 +733,7 @@ The checksum of /versions does not match the checksum provided by the server! So gem "rack" G - bundle :install, :env => { "RUBYOPT" => "-I#{bundled_app("broken_ssl")}" } + bundle :install, :env => { "RUBYOPT" => opt_add("-I#{bundled_app("broken_ssl")}", ENV["RUBYOPT"]) } expect(err).to include("OpenSSL") end end @@ -762,27 +759,29 @@ The checksum of /versions does not match the checksum provided by the server! So end context ".gemrc with sources is present" do - before do + it "uses other sources declared in the Gemfile" do File.open(home(".gemrc"), "w") do |file| file.puts({ :sources => ["https://rubygems.org"] }.to_yaml) end - end - after do - home(".gemrc").rmtree - end + begin + gemfile <<-G + source "#{source_uri}" + gem 'rack' + G - it "uses other sources declared in the Gemfile" do - gemfile <<-G - source "#{source_uri}" - gem 'rack' - G + bundle! :install, :artifice => "compact_index_forbidden" - bundle! :install, :artifice => "compact_index_forbidden" + expect(exitstatus).to eq(0) if exitstatus + ensure + home(".gemrc").rmtree + end end end it "performs partial update with a non-empty range" do + skip "HTTP_RANGE not set" if Gem.win_platform? + gemfile <<-G source "#{source_uri}" gem 'rack', '0.9.1' @@ -885,7 +884,7 @@ The checksum of /versions does not match the checksum provided by the server! So end it "raises when the checksum is the wrong length" do - install_gemfile <<-G, :artifice => "compact_index_wrong_gem_checksum", :env => { "BUNDLER_SPEC_RACK_CHECKSUM" => "checksum!" } + install_gemfile <<-G, :artifice => "compact_index_wrong_gem_checksum", :env => { "BUNDLER_SPEC_RACK_CHECKSUM" => "checksum!", "DEBUG" => "1" }, :verbose => true source "#{source_uri}" gem "rack" G @@ -915,7 +914,7 @@ The checksum of /versions does not match the checksum provided by the server! So source "#{source_uri}" gem "rails" G - deps = [Gem::Dependency.new("rake", "= 12.3.2"), + deps = [Gem::Dependency.new("rake", "= 13.0.1"), Gem::Dependency.new("actionpack", "= 2.3.2"), Gem::Dependency.new("activerecord", "= 2.3.2"), Gem::Dependency.new("actionmailer", "= 2.3.2"), @@ -933,7 +932,7 @@ Either installing with `--full-index` or running `bundle update rails` should fi gem "activemerchant" end G - gem_command! :uninstall, "activemerchant" + gem_command! "uninstall activemerchant" bundle! "update rails", :artifice => "compact_index" expect(lockfile.scan(/activemerchant \(/).size).to eq(1) end diff --git a/spec/bundler/install/gems/dependency_api_spec.rb b/spec/bundler/install/gems/dependency_api_spec.rb index a8713eb445..863966a0e1 100644 --- a/spec/bundler/install/gems/dependency_api_spec.rb +++ b/spec/bundler/install/gems/dependency_api_spec.rb @@ -378,21 +378,18 @@ RSpec.describe "gemcutter's dependency API" do s.add_dependency "foo" end build_gem "missing" - # need to hit the limit - 1.upto(Bundler::Source::Rubygems::API_REQUEST_LIMIT) do |i| - build_gem "gem#{i}" - end FileUtils.rm_rf Dir[gem_repo2("gems/foo-*.gem")] end - gemfile <<-G + api_request_limit = low_api_request_limit_for(gem_repo2) + + install_gemfile! <<-G, :artifice => "endpoint_extra_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s } source "#{source_uri}" source "#{source_uri}/extra" gem "back_deps" G - bundle :install, :artifice => "endpoint_extra_missing" expect(the_bundle).to include_gems "back_deps 1.0" end @@ -402,22 +399,19 @@ RSpec.describe "gemcutter's dependency API" do s.add_dependency "foo" end build_gem "missing" - # need to hit the limit - 1.upto(Bundler::Source::Rubygems::API_REQUEST_LIMIT) do |i| - build_gem "gem#{i}" - end FileUtils.rm_rf Dir[gem_repo2("gems/foo-*.gem")] end - gemfile <<-G + api_request_limit = low_api_request_limit_for(gem_repo2) + + install_gemfile! <<-G, :artifice => "endpoint_extra_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s } source "#{source_uri}" source "#{source_uri}/extra" do gem "back_deps" end G - bundle :install, :artifice => "endpoint_extra_missing" expect(the_bundle).to include_gems "back_deps 1.0" end @@ -497,6 +491,8 @@ RSpec.describe "gemcutter's dependency API" do end it "installs the binstubs", :bundler => "< 3" do + skip "exec format error" if Gem.win_platform? + gemfile <<-G source "#{source_uri}" gem "rack" @@ -555,7 +551,7 @@ RSpec.describe "gemcutter's dependency API" do let(:user) { "user" } let(:password) { "pass" } let(:basic_auth_source_uri) do - uri = URI.parse(source_uri) + uri = Bundler::URI.parse(source_uri) uri.user = user uri.password = password @@ -710,7 +706,7 @@ RSpec.describe "gemcutter's dependency API" do gem "rack" G - bundle :install, :env => { "RUBYOPT" => "-I#{bundled_app("broken_ssl")}" } + bundle :install, :env => { "RUBYOPT" => opt_add("-I#{bundled_app("broken_ssl")}", ENV["RUBYOPT"]) } expect(err).to include("OpenSSL") end end @@ -736,25 +732,23 @@ RSpec.describe "gemcutter's dependency API" do end context ".gemrc with sources is present" do - before do + it "uses other sources declared in the Gemfile" do File.open(home(".gemrc"), "w") do |file| file.puts({ :sources => ["https://rubygems.org"] }.to_yaml) end - end - after do - home(".gemrc").rmtree - end - - it "uses other sources declared in the Gemfile" do - gemfile <<-G - source "#{source_uri}" - gem 'rack' - G + begin + gemfile <<-G + source "#{source_uri}" + gem 'rack' + G - bundle "install", :artifice => "endpoint_marshal_fail" + bundle "install", :artifice => "endpoint_marshal_fail" - expect(exitstatus).to eq(0) if exitstatus + expect(exitstatus).to eq(0) if exitstatus + ensure + home(".gemrc").rmtree + end end end end diff --git a/spec/bundler/install/gems/flex_spec.rb b/spec/bundler/install/gems/flex_spec.rb index 865bc7b72a..77891acc24 100644 --- a/spec/bundler/install/gems/flex_spec.rb +++ b/spec/bundler/install/gems/flex_spec.rb @@ -233,7 +233,7 @@ RSpec.describe "bundle flex_install" do it "does something" do expect do bundle "install" - end.not_to change { File.read(bundled_app("Gemfile.lock")) } + end.not_to change { File.read(bundled_app_lock) } expect(err).to include("rack = 0.9.1") expect(err).to include("locked at 1.0.0") diff --git a/spec/bundler/install/gems/native_extensions_spec.rb b/spec/bundler/install/gems/native_extensions_spec.rb index 3e59a3cebd..a057d0d152 100644 --- a/spec/bundler/install/gems/native_extensions_spec.rb +++ b/spec/bundler/install/gems/native_extensions_spec.rb @@ -38,9 +38,8 @@ RSpec.describe "installing a gem with native extensions", :ruby_repo do G bundle "config set build.c_extension --with-c_extension=hello" - bundle "install" + bundle! "install" - expect(out).not_to include("extconf.rb failed") expect(out).to include("Installing c_extension 1.0 with native extensions") run "Bundler.require; puts CExtension.new.its_true" @@ -82,12 +81,64 @@ RSpec.describe "installing a gem with native extensions", :ruby_repo do gem "c_extension", :git => #{lib_path("c_extension-1.0").to_s.dump} G - expect(out).not_to include("extconf.rb failed") + expect(err).to_not include("warning: conflicting chdir during another chdir block") run! "Bundler.require; puts CExtension.new.its_true" expect(out).to eq("true") end + it "installs correctly from git when multiple gems with extensions share one repository" do + build_repo2 do + ["one", "two"].each do |n| + build_lib "c_extension_#{n}", "1.0", :path => lib_path("gems/c_extension_#{n}") do |s| + s.extensions = ["ext/extconf.rb"] + s.write "ext/extconf.rb", <<-E + require "mkmf" + name = "c_extension_bundle_#{n}" + dir_config(name) + raise "OMG" unless with_config("c_extension_#{n}") == "#{n}" + create_makefile(name) + E + + s.write "ext/c_extension_#{n}.c", <<-C + #include "ruby.h" + + VALUE c_extension_#{n}_value(VALUE self) { + return rb_str_new_cstr("#{n}"); + } + + void Init_c_extension_bundle_#{n}() { + VALUE c_Extension = rb_define_class("CExtension_#{n}", rb_cObject); + rb_define_method(c_Extension, "value", c_extension_#{n}_value, 0); + } + C + + s.write "lib/c_extension_#{n}.rb", <<-C + require "c_extension_bundle_#{n}" + C + end + end + build_git "gems", :path => lib_path("gems"), :gemspec => false + end + + bundle! "config set build.c_extension_one --with-c_extension_one=one" + bundle! "config set build.c_extension_two --with-c_extension_two=two" + + # 1st time, require only one gem -- only one of the extensions gets built. + install_gemfile! <<-G + gem "c_extension_one", :git => #{lib_path("gems").to_s.dump} + G + + # 2nd time, require both gems -- we need both extensions to be built now. + install_gemfile! <<-G + gem "c_extension_one", :git => #{lib_path("gems").to_s.dump} + gem "c_extension_two", :git => #{lib_path("gems").to_s.dump} + G + + run! "Bundler.require; puts CExtension_one.new.value; puts CExtension_two.new.value" + expect(out).to eq("one\ntwo") + end + it "install with multiple build flags" do build_git "c_extension" do |s| s.extensions = ["ext/extconf.rb"] @@ -123,8 +174,6 @@ RSpec.describe "installing a gem with native extensions", :ruby_repo do gem "c_extension", :git => #{lib_path("c_extension-1.0").to_s.dump} G - expect(out).not_to include("extconf.rb failed") - run! "Bundler.require; puts CExtension.new.its_true" expect(out).to eq("true") end diff --git a/spec/bundler/install/gems/resolving_spec.rb b/spec/bundler/install/gems/resolving_spec.rb index 52511ff67f..315d615604 100644 --- a/spec/bundler/install/gems/resolving_spec.rb +++ b/spec/bundler/install/gems/resolving_spec.rb @@ -19,6 +19,8 @@ RSpec.describe "bundle install with install-time dependencies" do end it "installs gems with a dependency with no type" do + skip "incorrect data check error" if Gem.win_platform? + build_repo2 path = "#{gem_repo2}/#{Gem::MARSHAL_SPEC_DIR}/actionpack-2.3.2.gemspec.rz" @@ -67,6 +69,20 @@ RSpec.describe "bundle install with install-time dependencies" do expect(the_bundle).to include_gems "net_a 1.0", "net_b 1.0", "net_c 1.0", "net_d 1.0", "net_e 1.0" end + context "with ENV['BUNDLER_DEBUG_RESOLVER'] set" do + it "produces debug output" do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "net_c" + gem "net_e" + G + + bundle :install, :env => { "BUNDLER_DEBUG_RESOLVER" => "1" } + + expect(err).to include("BUNDLER: Starting resolution") + end + end + context "with ENV['DEBUG_RESOLVER'] set" do it "produces debug output" do gemfile <<-G @@ -77,7 +93,7 @@ RSpec.describe "bundle install with install-time dependencies" do bundle :install, :env => { "DEBUG_RESOLVER" => "1" } - expect(err).to include("Creating possibility state for net_c") + expect(err).to include("BUNDLER: Starting resolution") end end @@ -92,8 +108,8 @@ RSpec.describe "bundle install with install-time dependencies" do bundle :install, :env => { "DEBUG_RESOLVER_TREE" => "1" } expect(err).to include(" net_b"). - and include("Starting resolution"). - and include("Finished resolution"). + and include("BUNDLER: Starting resolution"). + and include("BUNDLER: Finished resolution"). and include("Attempting to activate") end end @@ -101,6 +117,10 @@ RSpec.describe "bundle install with install-time dependencies" do describe "when a required ruby version" do context "allows only an older version" do + before do + skip "gem not found" if Gem.win_platform? + end + it "installs the older version" do build_repo2 do build_gem "rack", "9001.0.0" do |s| @@ -137,6 +157,31 @@ RSpec.describe "bundle install with install-time dependencies" do expect(out).to_not include("rack-9001.0.0 requires ruby version > 9000") expect(the_bundle).to include_gems("rack 1.2") end + + it "installs the older not platform specific version" do + build_repo4 do + build_gem "rack", "9001.0.0" do |s| + s.required_ruby_version = "> 9000" + end + build_gem "rack", "1.2" do |s| + s.platform = mingw + s.required_ruby_version = "> 9000" + end + build_gem "rack", "1.2" + end + + simulate_platform mingw do + install_gemfile <<-G, :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } + ruby "#{RUBY_VERSION}" + source "http://localgemserver.test/" + gem 'rack' + G + end + + expect(out).to_not include("rack-9001.0.0 requires ruby version > 9000") + expect(out).to_not include("rack-1.2-#{Bundler.local_platform} requires ruby version > 9000") + expect(the_bundle).to include_gems("rack 1.2") + end end context "allows no gems" do @@ -150,9 +195,18 @@ RSpec.describe "bundle install with install-time dependencies" do let(:ruby_requirement) { %("#{RUBY_VERSION}") } let(:error_message_requirement) { "~> #{RUBY_VERSION}.0" } + let(:error_message_platform) do + if Bundler.feature_flag.specific_platform? + " #{Bundler.local_platform}" + else + "" + end + end shared_examples_for "ruby version conflicts" do it "raises an error during resolution" do + skip "ruby requirement includes platform and it shouldn't" if Gem.win_platform? + install_gemfile <<-G, :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } source "http://localgemserver.test/" ruby #{ruby_requirement} @@ -164,9 +218,9 @@ RSpec.describe "bundle install with install-time dependencies" do nice_error = strip_whitespace(<<-E).strip Bundler found conflicting requirements for the Ruby\0 version: In Gemfile: - Ruby\0 (#{error_message_requirement}) + Ruby\0 (#{error_message_requirement})#{error_message_platform} - require_ruby was resolved to 1.0, which depends on + require_ruby#{error_message_platform} was resolved to 1.0, which depends on Ruby\0 (> 9000) Ruby\0 (> 9000), which is required by gem 'require_ruby', is not available in the local ruby installation @@ -179,7 +233,7 @@ RSpec.describe "bundle install with install-time dependencies" do describe "with a < requirement" do let(:ruby_requirement) { %("< 5000") } - let(:error_message_requirement) { "< 5000" } + let(:error_message_requirement) { Gem::Requirement.new(["< 5000", "= #{Bundler::RubyVersion.system.to_gem_version_with_patchlevel}"]).to_s } it_behaves_like "ruby version conflicts" end @@ -187,7 +241,7 @@ RSpec.describe "bundle install with install-time dependencies" do describe "with a compound requirement" do let(:reqs) { ["> 0.1", "< 5000"] } let(:ruby_requirement) { reqs.map(&:dump).join(", ") } - let(:error_message_requirement) { Gem::Requirement.new(reqs).to_s } + let(:error_message_requirement) { Gem::Requirement.new(reqs + ["= #{Bundler::RubyVersion.system.to_gem_version_with_patchlevel}"]).to_s } it_behaves_like "ruby version conflicts" end diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index f1d5c8b505..521499a5df 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -21,15 +21,18 @@ RSpec.shared_examples "bundle install --standalone" do testrb << "\nrequire \"#{k}\"" testrb << "\nputs #{k.upcase}" end - Dir.chdir(bundled_app) do - ruby testrb, :no_lib => true - end + ruby testrb, :no_lib => true expect(out).to eq(expected_gems.values.join("\n")) end it "works on a different system" do - FileUtils.mv(bundled_app, "#{bundled_app}2") + begin + FileUtils.mv(bundled_app, "#{bundled_app}2") + rescue Errno::ENOTEMPTY + puts "Couldn't rename test app since the target folder has these files: #{Dir.glob("#{bundled_app}2/*")}" + raise + end testrb = String.new <<-RUBY $:.unshift File.expand_path("bundle") @@ -40,9 +43,7 @@ RSpec.shared_examples "bundle install --standalone" do testrb << "\nrequire \"#{k}\"" testrb << "\nputs #{k.upcase}" end - Dir.chdir("#{bundled_app}2") do - ruby testrb, :no_lib => true - end + ruby testrb, :no_lib => true, :dir => "#{bundled_app}2" expect(out).to eq(expected_gems.values.join("\n")) end @@ -54,7 +55,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{file_uri_for(gem_repo1)}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) end let(:expected_gems) do @@ -69,7 +70,7 @@ RSpec.shared_examples "bundle install --standalone" do describe "with gems with native extension", :ruby_repo do before do - install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) source "#{file_uri_for(gem_repo1)}" gem "very_simple_binary" G @@ -102,7 +103,7 @@ RSpec.shared_examples "bundle install --standalone" do end G end - install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) gem "bar", :git => "#{lib_path("bar-1.0")}" G end @@ -122,7 +123,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rails" gem "devise", :git => "#{lib_path("devise-1.0")}" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) end let(:expected_gems) do @@ -149,7 +150,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rack-test" end G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) end let(:expected_gems) do @@ -162,88 +163,63 @@ RSpec.shared_examples "bundle install --standalone" do include_examples "common functionality" it "allows creating a standalone file with limited groups" do - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => "default") + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => "default", :dir => cwd) - Dir.chdir(bundled_app) do - load_error_ruby <<-RUBY, "spec", :no_lib => true - $:.unshift File.expand_path("bundle") - require "bundler/setup" + load_error_ruby <<-RUBY, "spec", :no_lib => true + $:.unshift File.expand_path("bundle") + require "bundler/setup" - require "actionpack" - puts ACTIONPACK - require "spec" - RUBY - end + require "actionpack" + puts ACTIONPACK + require "spec" + RUBY expect(out).to eq("2.3.2") expect(err).to eq("ZOMG LOAD ERROR") end it "allows --without to limit the groups used in a standalone" do - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle"), :without => "test").merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle"), :without => "test").merge(:standalone => true, :dir => cwd) - Dir.chdir(bundled_app) do - load_error_ruby <<-RUBY, "spec", :no_lib => true - $:.unshift File.expand_path("bundle") - require "bundler/setup" + load_error_ruby <<-RUBY, "spec", :no_lib => true + $:.unshift File.expand_path("bundle") + require "bundler/setup" - require "actionpack" - puts ACTIONPACK - require "spec" - RUBY - end + require "actionpack" + puts ACTIONPACK + require "spec" + RUBY expect(out).to eq("2.3.2") expect(err).to eq("ZOMG LOAD ERROR") end - it "allows --path to change the location of the standalone bundle", :bundler => "< 3" do - bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true) + it "allows --path to change the location of the standalone bundle" do + bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true, :dir => cwd) - Dir.chdir(bundled_app) do - ruby <<-RUBY, :no_lib => true - $:.unshift File.expand_path("path/to/bundle") - require "bundler/setup" + ruby <<-RUBY, :no_lib => true + $:.unshift File.expand_path("path/to/bundle") + require "bundler/setup" - require "actionpack" - puts ACTIONPACK - RUBY - end + require "actionpack" + puts ACTIONPACK + RUBY expect(out).to eq("2.3.2") end - it "allows --path to change the location of the standalone bundle", :bundler => "3" do - bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true) - path = File.expand_path("path/to/bundle") - - Dir.chdir(bundled_app) do - ruby <<-RUBY, :no_lib => true - $:.unshift File.expand_path(#{path.dump}) - require "bundler/setup" - - require "actionpack" - puts ACTIONPACK - RUBY - end + it "allows remembered --without to limit the groups used in a standalone" do + bundle! :install, forgotten_command_line_options(:without => "test").merge(:dir => cwd) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) - expect(out).to eq("2.3.2") - end + load_error_ruby <<-RUBY, "spec", :no_lib => true + $:.unshift File.expand_path("bundle") + require "bundler/setup" - it "allows remembered --without to limit the groups used in a standalone" do - bundle! :install, forgotten_command_line_options(:without => "test") - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) - - Dir.chdir(bundled_app) do - load_error_ruby <<-RUBY, "spec", :no_lib => true - $:.unshift File.expand_path("bundle") - require "bundler/setup" - - require "actionpack" - puts ACTIONPACK - require "spec" - RUBY - end + require "actionpack" + puts ACTIONPACK + require "spec" + RUBY expect(out).to eq("2.3.2") expect(err).to eq("ZOMG LOAD ERROR") @@ -259,7 +235,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{source_uri}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :artifice => "endpoint") + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :artifice => "endpoint", :dir => cwd) end let(:expected_gems) do @@ -279,7 +255,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{file_uri_for(gem_repo1)}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :binstubs => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :binstubs => true, :dir => cwd) end let(:expected_gems) do @@ -292,21 +268,21 @@ RSpec.shared_examples "bundle install --standalone" do include_examples "common functionality" it "creates stubs that use the standalone load path" do - Dir.chdir(bundled_app) do - expect(`bin/rails -v`.chomp).to eql "2.3.2" - end + skip "exec format error" if Gem.win_platform? + + expect(sys_exec("bin/rails -v").chomp).to eql "2.3.2" end it "creates stubs that can be executed from anywhere" do + skip "exec format error" if Gem.win_platform? + require "tmpdir" - Dir.chdir(Dir.tmpdir) do - sys_exec!(%(#{bundled_app("bin/rails")} -v)) - expect(out).to eq("2.3.2") - end + sys_exec!(%(#{bundled_app("bin/rails")} -v), :dir => Dir.tmpdir) + expect(out).to eq("2.3.2") end it "creates stubs that can be symlinked" do - pending "File.symlink is unsupported on Windows" if Bundler::WINDOWS + skip "symlinks unsupported" if Gem.win_platform? symlink_dir = tmp("symlink") FileUtils.mkdir_p(symlink_dir) @@ -325,13 +301,13 @@ RSpec.shared_examples "bundle install --standalone" do end RSpec.describe "bundle install --standalone" do + let(:cwd) { bundled_app } + include_examples("bundle install --standalone") end RSpec.describe "bundle install --standalone run in a subdirectory" do - before do - Dir.chdir(bundled_app("bob").tap(&:mkpath)) - end + let(:cwd) { bundled_app("bob").tap(&:mkpath) } include_examples("bundle install --standalone") end diff --git a/spec/bundler/install/gems/sudo_spec.rb b/spec/bundler/install/gems/sudo_spec.rb index 170ffaca03..3e4c1ad1c1 100644 --- a/spec/bundler/install/gems/sudo_spec.rb +++ b/spec/bundler/install/gems/sudo_spec.rb @@ -166,7 +166,7 @@ RSpec.describe "when using sudo", :sudo => true do end it "warns against that" do - bundle :install, :sudo => true + bundle :install, :sudo => :preserve_env expect(err).to include(warning) end @@ -179,7 +179,7 @@ RSpec.describe "when using sudo", :sudo => true do context "when silence_root_warning = false" do it "warns against that" do - bundle :install, :sudo => true, :env => { "BUNDLE_SILENCE_ROOT_WARNING" => "false" } + bundle :install, :sudo => :preserve_env, :env => { "BUNDLE_SILENCE_ROOT_WARNING" => "false" } expect(err).to include(warning) end end diff --git a/spec/bundler/install/gems/win32_spec.rb b/spec/bundler/install/gems/win32_spec.rb index 01edcca803..972a455bee 100644 --- a/spec/bundler/install/gems/win32_spec.rb +++ b/spec/bundler/install/gems/win32_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "bundle install with win32-generated lockfile" do it "should read lockfile" do - File.open(bundled_app("Gemfile.lock"), "wb") do |f| + File.open(bundled_app_lock, "wb") do |f| f << "GEM\r\n" f << " remote: #{file_uri_for(gem_repo1)}/\r\n" f << " specs:\r\n" diff --git a/spec/bundler/install/gemspecs_spec.rb b/spec/bundler/install/gemspecs_spec.rb index 4c00caa60c..048987af9b 100644 --- a/spec/bundler/install/gemspecs_spec.rb +++ b/spec/bundler/install/gemspecs_spec.rb @@ -28,6 +28,8 @@ RSpec.describe "bundle install" do end it "should use gemspecs in the system cache when available" do + skip "weird incompatible marshal file format error" if Gem.win_platform? + gemfile <<-G source "http://localtestserver.gem" gem 'rack' diff --git a/spec/bundler/install/git_spec.rb b/spec/bundler/install/git_spec.rb index cc8bf70b03..1b32991fa8 100644 --- a/spec/bundler/install/git_spec.rb +++ b/spec/bundler/install/git_spec.rb @@ -5,16 +5,17 @@ RSpec.describe "bundle install" do it "displays the revision hash of the gem repository", :bundler => "< 3" do build_git "foo", "1.0", :path => lib_path("foo") - install_gemfile <<-G - gem "foo", :git => "#{lib_path("foo")}" + install_gemfile! <<-G + gem "foo", :git => "#{file_uri_for(lib_path("foo"))}" G - bundle! :install - expect(out).to include("Using foo 1.0 from #{lib_path("foo")} (at master@#{revision_for(lib_path("foo"))[0..6]})") + expect(out).to include("Using foo 1.0 from #{file_uri_for(lib_path("foo"))} (at master@#{revision_for(lib_path("foo"))[0..6]})") expect(the_bundle).to include_gems "foo 1.0", :source => "git@#{lib_path("foo")}" end it "displays the ref of the gem repository when using branch~num as a ref", :bundler => "< 3" do + skip "maybe branch~num notation doesn't work on Windows' git" if Gem.win_platform? + build_git "foo", "1.0", :path => lib_path("foo") rev = revision_for(lib_path("foo"))[0..6] update_git "foo", "2.0", :path => lib_path("foo"), :gemspec => true @@ -22,17 +23,16 @@ RSpec.describe "bundle install" do update_git "foo", "3.0", :path => lib_path("foo"), :gemspec => true install_gemfile! <<-G - gem "foo", :git => "#{lib_path("foo")}", :ref => "master~2" + gem "foo", :git => "#{file_uri_for(lib_path("foo"))}", :ref => "master~2" G - bundle! :install - expect(out).to include("Using foo 1.0 from #{lib_path("foo")} (at master~2@#{rev})") + expect(out).to include("Using foo 1.0 from #{file_uri_for(lib_path("foo"))} (at master~2@#{rev})") expect(the_bundle).to include_gems "foo 1.0", :source => "git@#{lib_path("foo")}" update_git "foo", "4.0", :path => lib_path("foo"), :gemspec => true bundle! :update, :all => true - expect(out).to include("Using foo 2.0 (was 1.0) from #{lib_path("foo")} (at master~2@#{rev2})") + expect(out).to include("Using foo 2.0 (was 1.0) from #{file_uri_for(lib_path("foo"))} (at master~2@#{rev2})") expect(the_bundle).to include_gems "foo 2.0", :source => "git@#{lib_path("foo")}" end @@ -69,10 +69,10 @@ RSpec.describe "bundle install" do build_git "gems", :path => lib_path("gems"), :gemspec => false end - install_gemfile <<-G + install_gemfile! <<-G source "#{file_uri_for(gem_repo2)}" - gem "foo", :git => "#{lib_path("gems")}", :glob => "foo/*.gemspec" - gem "zebra", :git => "#{lib_path("gems")}", :glob => "zebra/*.gemspec" + gem "foo", :git => "#{file_uri_for(lib_path("gems"))}", :glob => "foo/*.gemspec" + gem "zebra", :git => "#{file_uri_for(lib_path("gems"))}", :glob => "zebra/*.gemspec" G bundle "info foo" diff --git a/spec/bundler/install/global_cache_spec.rb b/spec/bundler/install/global_cache_spec.rb index 023e52b060..de7b511a1d 100644 --- a/spec/bundler/install/global_cache_spec.rb +++ b/spec/bundler/install/global_cache_spec.rb @@ -161,34 +161,34 @@ RSpec.describe "global gem caching" do expect(source_global_cache("rack-1.0.0.gem")).to exist expect(source_global_cache("activesupport-2.3.5.gem")).to exist - Dir.chdir bundled_app2 do - create_file bundled_app2("gems.rb"), <<-G - source "#{source}" - gem "activesupport" - G - - # Neither gem is installed and both are in the global cache - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(the_bundle).not_to include_gems "activesupport 2.3.5" - expect(source_global_cache("rack-1.0.0.gem")).to exist - expect(source_global_cache("activesupport-2.3.5.gem")).to exist - - # Install using the global cache instead of by downloading the .gem - # from the server - bundle! :install, :artifice => "compact_index_no_gem" - - # activesupport is installed and both are in the global cache - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(the_bundle).to include_gems "activesupport 2.3.5" - expect(source_global_cache("rack-1.0.0.gem")).to exist - expect(source_global_cache("activesupport-2.3.5.gem")).to exist - end + create_file bundled_app2("gems.rb"), <<-G + source "#{source}" + gem "activesupport" + G + + # Neither gem is installed and both are in the global cache + expect(the_bundle).not_to include_gems "rack 1.0.0", :dir => bundled_app2 + expect(the_bundle).not_to include_gems "activesupport 2.3.5", :dir => bundled_app2 + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("activesupport-2.3.5.gem")).to exist + + # Install using the global cache instead of by downloading the .gem + # from the server + bundle! :install, :artifice => "compact_index_no_gem", :dir => bundled_app2 + + # activesupport is installed and both are in the global cache + expect(the_bundle).not_to include_gems "rack 1.0.0", :dir => bundled_app2 + expect(the_bundle).to include_gems "activesupport 2.3.5", :dir => bundled_app2 + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("activesupport-2.3.5.gem")).to exist end end end describe "extension caching", :ruby_repo do it "works" do + skip "gets incorrect ref in path" if Gem.win_platform? + build_git "very_simple_git_binary", &:add_c_extension build_lib "very_simple_path_binary", &:add_c_extension revision = revision_for(lib_path("very_simple_git_binary-1.0"))[0, 12] diff --git a/spec/bundler/install/path_spec.rb b/spec/bundler/install/path_spec.rb index 5240c5820c..bed28ed3e2 100644 --- a/spec/bundler/install/path_spec.rb +++ b/spec/bundler/install/path_spec.rb @@ -22,10 +22,8 @@ RSpec.describe "bundle install" do dir = bundled_app("bun++dle") dir.mkpath - Dir.chdir(dir) do - bundle! :install, forgotten_command_line_options(:path => dir.join("vendor/bundle")) - expect(out).to include("installed into `./vendor/bundle`") - end + bundle! :install, forgotten_command_line_options(:path => dir.join("vendor/bundle")).merge(:dir => dir) + expect(out).to include("installed into `./vendor/bundle`") dir.rmtree end @@ -54,30 +52,24 @@ RSpec.describe "bundle install" do before { bundle! "config set path_relative_to_cwd true" } it "installs the bundle relatively to current working directory", :bundler => "< 3" do - Dir.chdir(bundled_app.parent) do - bundle! "install --gemfile='#{bundled_app}/Gemfile' --path vendor/bundle" - expect(out).to include("installed into `./vendor/bundle`") - expect(bundled_app("../vendor/bundle")).to be_directory - end + bundle! "install --gemfile='#{bundled_app}/Gemfile' --path vendor/bundle", :dir => bundled_app.parent + expect(out).to include("installed into `./vendor/bundle`") + expect(bundled_app("../vendor/bundle")).to be_directory expect(the_bundle).to include_gems "rack 1.0.0" end it "installs the standalone bundle relative to the cwd" do - Dir.chdir(bundled_app.parent) do - bundle! :install, :gemfile => bundled_app("Gemfile"), :standalone => true - expect(out).to include("installed into `./bundled_app/bundle`") - expect(bundled_app("bundle")).to be_directory - expect(bundled_app("bundle/ruby")).to be_directory - end + bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true, :dir => bundled_app.parent + expect(out).to include("installed into `./bundled_app/bundle`") + expect(bundled_app("bundle")).to be_directory + expect(bundled_app("bundle/ruby")).to be_directory bundle! "config unset path" - Dir.chdir(bundled_app("subdir").tap(&:mkpath)) do - bundle! :install, :gemfile => bundled_app("Gemfile"), :standalone => true - expect(out).to include("installed into `../bundle`") - expect(bundled_app("bundle")).to be_directory - expect(bundled_app("bundle/ruby")).to be_directory - end + bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true, :dir => bundled_app("subdir").tap(&:mkpath) + expect(out).to include("installed into `../bundle`") + expect(bundled_app("bundle")).to be_directory + expect(bundled_app("bundle/ruby")).to be_directory end end end @@ -137,9 +129,7 @@ RSpec.describe "bundle install" do set_bundle_path(type, "vendor") FileUtils.mkdir_p bundled_app("lol") - Dir.chdir(bundled_app("lol")) do - bundle! :install - end + bundle! :install, :dir => bundled_app("lol") expect(bundled_app("vendor", Bundler.ruby_scope, "gems/rack-1.0.0")).to be_directory expect(the_bundle).to include_gems "rack 1.0.0" @@ -203,9 +193,7 @@ RSpec.describe "bundle install" do describe "to a file" do before do - in_app_root do - FileUtils.touch "bundle" - end + FileUtils.touch bundled_app("bundle") end it "reports the file exists" do diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb index ddab4831a5..c4d06bd96e 100644 --- a/spec/bundler/lock/lockfile_spec.rb +++ b/spec/bundler/lock/lockfile_spec.rb @@ -746,8 +746,8 @@ RSpec.describe "the lockfile format" do actionpack (= 2.3.2) activerecord (= 2.3.2) activeresource (= 2.3.2) - rake (= 12.3.2) - rake (12.3.2) + rake (= 13.0.1) + rake (13.0.1) PLATFORMS #{lockfile_platforms} @@ -1209,7 +1209,7 @@ RSpec.describe "the lockfile format" do gem "rack", "1.1" G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist expect(err).to include "rack (= 1.0) and rack (= 1.1)" end @@ -1220,7 +1220,7 @@ RSpec.describe "the lockfile format" do gem "rack", :git => "git://hubz.com" G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist expect(err).to include "rack (>= 0) should come from an unspecified source and git://hubz.com (at master)" end @@ -1376,7 +1376,7 @@ RSpec.describe "the lockfile format" do describe "a line ending" do def set_lockfile_mtime_to_known_value time = Time.local(2000, 1, 1, 0, 0, 0) - File.utime(time, time, bundled_app("Gemfile.lock")) + File.utime(time, time, bundled_app_lock) end before(:each) do build_repo2 @@ -1389,7 +1389,7 @@ RSpec.describe "the lockfile format" do end it "generates Gemfile.lock with \\n line endings" do - expect(File.read(bundled_app("Gemfile.lock"))).not_to match("\r\n") + expect(File.read(bundled_app_lock)).not_to match("\r\n") expect(the_bundle).to include_gems "rack 1.0" end @@ -1397,19 +1397,21 @@ RSpec.describe "the lockfile format" do it "preserves Gemfile.lock \\n line endings" do update_repo2 - expect { bundle "update", :all => true }.to change { File.mtime(bundled_app("Gemfile.lock")) } - expect(File.read(bundled_app("Gemfile.lock"))).not_to match("\r\n") + expect { bundle "update", :all => true }.to change { File.mtime(bundled_app_lock) } + expect(File.read(bundled_app_lock)).not_to match("\r\n") expect(the_bundle).to include_gems "rack 1.2" end it "preserves Gemfile.lock \\n\\r line endings" do + skip "needs to be adapted" if Gem.win_platform? + update_repo2 - win_lock = File.read(bundled_app("Gemfile.lock")).gsub(/\n/, "\r\n") - File.open(bundled_app("Gemfile.lock"), "wb") {|f| f.puts(win_lock) } + win_lock = File.read(bundled_app_lock).gsub(/\n/, "\r\n") + File.open(bundled_app_lock, "wb") {|f| f.puts(win_lock) } set_lockfile_mtime_to_known_value - expect { bundle "update", :all => true }.to change { File.mtime(bundled_app("Gemfile.lock")) } - expect(File.read(bundled_app("Gemfile.lock"))).to match("\r\n") + expect { bundle "update", :all => true }.to change { File.mtime(bundled_app_lock) } + expect(File.read(bundled_app_lock)).to match("\r\n") expect(the_bundle).to include_gems "rack 1.2" end end @@ -1421,12 +1423,12 @@ RSpec.describe "the lockfile format" do require 'bundler' Bundler.setup RUBY - end.not_to change { File.mtime(bundled_app("Gemfile.lock")) } + end.not_to change { File.mtime(bundled_app_lock) } end it "preserves Gemfile.lock \\n\\r line endings" do - win_lock = File.read(bundled_app("Gemfile.lock")).gsub(/\n/, "\r\n") - File.open(bundled_app("Gemfile.lock"), "wb") {|f| f.puts(win_lock) } + win_lock = File.read(bundled_app_lock).gsub(/\n/, "\r\n") + File.open(bundled_app_lock, "wb") {|f| f.puts(win_lock) } set_lockfile_mtime_to_known_value expect do @@ -1434,7 +1436,7 @@ RSpec.describe "the lockfile format" do require 'bundler' Bundler.setup RUBY - end.not_to change { File.mtime(bundled_app("Gemfile.lock")) } + end.not_to change { File.mtime(bundled_app_lock) } end end end diff --git a/spec/bundler/other/major_deprecation_spec.rb b/spec/bundler/other/major_deprecation_spec.rb index df2fdd263a..17bf923d84 100644 --- a/spec/bundler/other/major_deprecation_spec.rb +++ b/spec/bundler/other/major_deprecation_spec.rb @@ -121,6 +121,28 @@ RSpec.describe "major deprecations" do pending "should fail with a helpful error", :bundler => "3" end + context "bundle check --path=" do + before do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + + bundle "check --path=vendor/bundle" + end + + it "should print a deprecation warning", :bundler => "2" do + expect(deprecations).to include( + "The `--path` flag is deprecated because it relies on being " \ + "remembered across bundler invocations, which bundler will no " \ + "longer do in future versions. Instead please use `bundle config set " \ + "path 'vendor/bundle'`, and stop using this flag" + ) + end + + pending "should fail with a helpful error", :bundler => "3" + end + describe "bundle config" do describe "old list interface" do before do diff --git a/spec/bundler/other/platform_spec.rb b/spec/bundler/other/platform_spec.rb index 7fb4a7404f..4d5be3f784 100644 --- a/spec/bundler/other/platform_spec.rb +++ b/spec/bundler/other/platform_spec.rb @@ -298,20 +298,18 @@ G #{ruby_version_correct} G - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end - it "installs fine with any engine" do - simulate_ruby_engine "jruby" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + it "installs fine with any engine", :jruby do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" - #{ruby_version_correct_engineless} - G + #{ruby_version_correct_engineless} + G - expect(bundled_app("Gemfile.lock")).to exist - end + expect(bundled_app_lock).to exist end it "installs fine when the patchlevel matches" do @@ -322,7 +320,7 @@ G #{ruby_version_correct_patchlevel} G - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "doesn't install when the ruby version doesn't match" do @@ -333,7 +331,7 @@ G #{ruby_version_incorrect} G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_ruby_version_incorrect end @@ -345,22 +343,20 @@ G #{engine_incorrect} G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_engine_incorrect end - it "doesn't install when engine version doesn't match" do - simulate_ruby_engine "jruby" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + it "doesn't install when engine version doesn't match", :jruby do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" - #{engine_version_incorrect} - G + #{engine_version_incorrect} + G - expect(bundled_app("Gemfile.lock")).not_to exist - should_be_engine_version_incorrect - end + expect(bundled_app_lock).not_to exist + should_be_engine_version_incorrect end it "doesn't install when patchlevel doesn't match" do @@ -371,7 +367,7 @@ G #{patchlevel_incorrect} G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_patchlevel_incorrect end end @@ -392,27 +388,25 @@ G bundle :check expect(exitstatus).to eq(0) if exitstatus - expect(out).to eq("Resolving dependencies...\nThe Gemfile's dependencies are satisfied") + expect(out).to match(/\AResolving dependencies\.\.\.\.*\nThe Gemfile's dependencies are satisfied\z/) end - it "checks fine with any engine" do - simulate_ruby_engine "jruby" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G + it "checks fine with any engine", :jruby do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" - #{ruby_version_correct_engineless} - G + #{ruby_version_correct_engineless} + G - bundle :check - expect(exitstatus).to eq(0) if exitstatus - expect(out).to eq("Resolving dependencies...\nThe Gemfile's dependencies are satisfied") - end + bundle :check + expect(exitstatus).to eq(0) if exitstatus + expect(out).to match(/\AResolving dependencies\.\.\.\.*\nThe Gemfile's dependencies are satisfied\z/) end it "fails when ruby version doesn't match" do @@ -449,23 +443,21 @@ G should_be_engine_incorrect end - it "fails when engine version doesn't match" do - simulate_ruby_engine "ruby" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G + it "fails when engine version doesn't match", :jruby do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" - #{engine_version_incorrect} - G + #{engine_version_incorrect} + G - bundle :check - should_be_engine_version_incorrect - end + bundle :check + should_be_engine_version_incorrect end it "fails when patchlevel doesn't match" do @@ -513,22 +505,20 @@ G expect(the_bundle).to include_gems "rack 1.2", "rack-obama 1.0", "activesupport 3.0" end - it "updates fine with any engine" do - simulate_ruby_engine "jruby" do - gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "activesupport" - gem "rack-obama" - - #{ruby_version_correct_engineless} - G - update_repo2 do - build_gem "activesupport", "3.0" - end + it "updates fine with any engine", :jruby do + gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "activesupport" + gem "rack-obama" - bundle "update", :all => true - expect(the_bundle).to include_gems "rack 1.2", "rack-obama 1.0", "activesupport 3.0" + #{ruby_version_correct_engineless} + G + update_repo2 do + build_gem "activesupport", "3.0" end + + bundle "update", :all => true + expect(the_bundle).to include_gems "rack 1.2", "rack-obama 1.0", "activesupport 3.0" end it "fails when ruby version doesn't match" do @@ -547,7 +537,7 @@ G should_be_ruby_version_incorrect end - it "fails when ruby engine doesn't match" do + it "fails when ruby engine doesn't match", :jruby do gemfile <<-G source "#{file_uri_for(gem_repo2)}" gem "activesupport" @@ -563,22 +553,20 @@ G should_be_engine_incorrect end - it "fails when ruby engine version doesn't match" do - simulate_ruby_engine "jruby" do - gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "activesupport" - gem "rack-obama" - - #{engine_version_incorrect} - G - update_repo2 do - build_gem "activesupport", "3.0" - end + it "fails when ruby engine version doesn't match", :jruby do + gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "activesupport" + gem "rack-obama" - bundle :update, :all => true - should_be_engine_version_incorrect + #{engine_version_incorrect} + G + update_repo2 do + build_gem "activesupport", "3.0" end + + bundle :update, :all => true + should_be_engine_version_incorrect end it "fails when patchlevel doesn't match" do @@ -617,18 +605,16 @@ G expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) end - it "prints path if ruby version is correct for any engine" do - simulate_ruby_engine "jruby" do - install_gemfile! <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rails" + it "prints path if ruby version is correct for any engine", :jruby do + install_gemfile! <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rails" - #{ruby_version_correct_engineless} - G + #{ruby_version_correct_engineless} + G - bundle "info rails --path" - expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) - end + bundle "info rails --path" + expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) end it "fails if ruby version doesn't match", :bundler => "< 3" do @@ -655,18 +641,16 @@ G should_be_engine_incorrect end - it "fails if engine version doesn't match", :bundler => "< 3" do - simulate_ruby_engine "jruby" do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rails" + it "fails if engine version doesn't match", :bundler => "< 3", :jruby => true do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rails" - #{engine_version_incorrect} - G + #{engine_version_incorrect} + G - bundle "show rails" - should_be_engine_version_incorrect - end + bundle "show rails" + should_be_engine_version_incorrect end it "fails when patchlevel doesn't match", :bundler => "< 3" do @@ -704,18 +688,16 @@ G expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist end - it "copies the .gem file to vendor/cache when ruby version matches for any engine" do - simulate_ruby_engine "jruby" do - install_gemfile! <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + it "copies the .gem file to vendor/cache when ruby version matches for any engine", :jruby do + install_gemfile! <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'rack' - #{ruby_version_correct_engineless} - G + #{ruby_version_correct_engineless} + G - bundle! :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - end + bundle! :cache + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist end it "fails if the ruby version doesn't match" do @@ -740,17 +722,15 @@ G should_be_engine_incorrect end - it "fails if the engine version doesn't match" do - simulate_ruby_engine "jruby" do - gemfile <<-G - gem 'rack' + it "fails if the engine version doesn't match", :jruby do + gemfile <<-G + gem 'rack' - #{engine_version_incorrect} - G + #{engine_version_incorrect} + G - bundle :cache - should_be_engine_version_incorrect - end + bundle :cache + should_be_engine_version_incorrect end it "fails when patchlevel doesn't match" do @@ -785,18 +765,16 @@ G expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist end - it "copies the .gem file to vendor/cache when ruby version matches any engine" do - simulate_ruby_engine "jruby" do - install_gemfile! <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + it "copies the .gem file to vendor/cache when ruby version matches any engine", :jruby do + install_gemfile! <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'rack' - #{ruby_version_correct_engineless} - G + #{ruby_version_correct_engineless} + G - bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - end + bundle :cache + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist end it "fails if the ruby version doesn't match" do @@ -821,17 +799,15 @@ G should_be_engine_incorrect end - it "fails if the engine version doesn't match" do - simulate_ruby_engine "jruby" do - gemfile <<-G - gem 'rack' + it "fails if the engine version doesn't match", :jruby do + gemfile <<-G + gem 'rack' - #{engine_version_incorrect} - G + #{engine_version_incorrect} + G - bundle :cache - should_be_engine_version_incorrect - end + bundle :cache + should_be_engine_version_incorrect end it "fails when patchlevel doesn't match" do @@ -850,7 +826,7 @@ G context "bundle exec" do before do ENV["BUNDLER_FORCE_TTY"] = "true" - system_gems "rack-1.0.0", "rack-0.9.1", :path => :bundle_path + system_gems "rack-1.0.0", "rack-0.9.1", :path => default_bundle_path end it "activates the correct gem when ruby version matches" do @@ -864,18 +840,16 @@ G expect(out).to include("0.9.1") end - it "activates the correct gem when ruby version matches any engine" do - simulate_ruby_engine "jruby" do - system_gems "rack-1.0.0", "rack-0.9.1", :path => :bundle_path - gemfile <<-G - gem "rack", "0.9.1" + it "activates the correct gem when ruby version matches any engine", :jruby do + system_gems "rack-1.0.0", "rack-0.9.1", :path => default_bundle_path + gemfile <<-G + gem "rack", "0.9.1" - #{ruby_version_correct_engineless} - G + #{ruby_version_correct_engineless} + G - bundle "exec rackup" - expect(out).to include("0.9.1") - end + bundle "exec rackup" + expect(out).to include("0.9.1") end it "fails when the ruby version doesn't match" do @@ -900,17 +874,15 @@ G should_be_engine_incorrect end - # it "fails when the engine version doesn't match" do - # simulate_ruby_engine "jruby" do - # gemfile <<-G - # gem "rack", "0.9.1" + # it "fails when the engine version doesn't match", :jruby do + # gemfile <<-G + # gem "rack", "0.9.1" # - # #{engine_version_incorrect} - # G + # #{engine_version_incorrect} + # G # - # bundle "exec rackup" - # should_be_engine_version_incorrect - # end + # bundle "exec rackup" + # should_be_engine_version_incorrect # end it "fails when patchlevel doesn't match" do @@ -936,7 +908,7 @@ G G end - it "starts IRB with the default group loaded when ruby version matches" do + it "starts IRB with the default group loaded when ruby version matches", :readline do gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "rack" @@ -953,24 +925,21 @@ G expect(out).to include("0.9.1") end - it "starts IRB with the default group loaded when ruby version matches any engine" do - skip "MRI cannot simulate JRuby" if RUBY_ENGINE == "ruby" - simulate_ruby_engine "jruby" do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + it "starts IRB with the default group loaded when ruby version matches", :readline, :jruby do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + gem "activesupport", :group => :test + gem "rack_middleware", :group => :development - #{ruby_version_correct_engineless} - G + #{ruby_version_correct_engineless} + G - bundle "console" do |input, _, _| - input.puts("puts RACK") - input.puts("exit") - end - expect(out).to include("0.9.1") + bundle "console" do |input, _, _| + input.puts("puts RACK") + input.puts("exit") end + expect(out).to include("0.9.1") end it "fails when ruby version doesn't match" do @@ -1001,20 +970,18 @@ G should_be_engine_incorrect end - it "fails when engine version doesn't match" do - simulate_ruby_engine "jruby" do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + it "fails when engine version doesn't match", :jruby do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + gem "activesupport", :group => :test + gem "rack_middleware", :group => :development - #{engine_version_incorrect} - G + #{engine_version_incorrect} + G - bundle "console" - should_be_engine_version_incorrect - end + bundle "console" + should_be_engine_version_incorrect end it "fails when patchlevel doesn't match" do @@ -1052,27 +1019,25 @@ G #{ruby_version_correct} G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) run "1" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end - it "makes a Gemfile.lock if setup succeeds for any engine" do - simulate_ruby_engine "jruby" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "yard" - gem "rack" + it "makes a Gemfile.lock if setup succeeds for any engine", :jruby do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "yard" + gem "rack" - #{ruby_version_correct_engineless} - G + #{ruby_version_correct_engineless} + G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) - run "1" - expect(bundled_app("Gemfile.lock")).to exist - end + run "1" + expect(bundled_app_lock).to exist end it "fails when ruby version doesn't match" do @@ -1084,13 +1049,11 @@ G #{ruby_version_incorrect} G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) - ruby <<-R - require 'bundler/setup' - R + ruby "require 'bundler/setup'" - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_ruby_version_incorrect end @@ -1103,35 +1066,29 @@ G #{engine_incorrect} G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) - ruby <<-R - require 'bundler/setup' - R + ruby "require 'bundler/setup'" - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_engine_incorrect end - it "fails when engine version doesn't match" do - simulate_ruby_engine "jruby" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "yard" - gem "rack" + it "fails when engine version doesn't match", :jruby do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "yard" + gem "rack" - #{engine_version_incorrect} - G + #{engine_version_incorrect} + G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) - ruby <<-R - require 'bundler/setup' - R + ruby "require 'bundler/setup'" - expect(bundled_app("Gemfile.lock")).not_to exist - should_be_engine_version_incorrect - end + expect(bundled_app_lock).not_to exist + should_be_engine_version_incorrect end it "fails when patchlevel doesn't match" do @@ -1143,13 +1100,11 @@ G #{patchlevel_incorrect} G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) - ruby <<-R - require 'bundler/setup' - R + ruby "require 'bundler/setup'" - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_patchlevel_incorrect end end @@ -1182,30 +1137,40 @@ G G bundle "outdated" - expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5") - expect(out).to include("foo (newest 1.0") + + expected_output = <<~TABLE.gsub("x", "\\\h").tr(".", "\.").strip + Gem Current Latest Requested Groups + activesupport 2.3.5 3.0 = 2.3.5 default + foo 1.0 xxxxxxx 1.0 xxxxxxx >= 0 default + TABLE + + expect(out).to match(Regexp.new(expected_output)) end - it "returns list of outdated gems when the ruby version matches for any engine" do - simulate_ruby_engine "jruby" do - bundle! :install - update_repo2 do - build_gem "activesupport", "3.0" - update_git "foo", :path => lib_path("foo") - end + it "returns list of outdated gems when the ruby version matches for any engine", :jruby do + bundle! :install + update_repo2 do + build_gem "activesupport", "3.0" + update_git "foo", :path => lib_path("foo") + end - gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "activesupport", "2.3.5" - gem "foo", :git => "#{lib_path("foo")}" + gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "activesupport", "2.3.5" + gem "foo", :git => "#{lib_path("foo")}" - #{ruby_version_correct_engineless} - G + #{ruby_version_correct_engineless} + G - bundle "outdated" - expect(out).to include("activesupport (newest 3.0, installed 2.3.5, requested = 2.3.5)") - expect(out).to include("foo (newest 1.0") - end + bundle "outdated" + + expected_output = <<~TABLE.gsub("x", "\\\h").tr(".", "\.").strip + Gem Current Latest Requested Groups + activesupport 2.3.5 3.0 = 2.3.5 default + foo 1.0 xxxxxxx 1.0 xxxxxxx >= 0 default + TABLE + + expect(out).to match(Regexp.new(expected_output)) end it "fails when the ruby version doesn't match" do @@ -1244,64 +1209,58 @@ G should_be_engine_incorrect end - it "fails when the engine version doesn't match" do - simulate_ruby_engine "jruby" do - update_repo2 do - build_gem "activesupport", "3.0" - update_git "foo", :path => lib_path("foo") - end + it "fails when the engine version doesn't match", :jruby do + update_repo2 do + build_gem "activesupport", "3.0" + update_git "foo", :path => lib_path("foo") + end - gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "activesupport", "2.3.5" - gem "foo", :git => "#{lib_path("foo")}" + gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "activesupport", "2.3.5" + gem "foo", :git => "#{lib_path("foo")}" - #{engine_version_incorrect} - G + #{engine_version_incorrect} + G - bundle "outdated" - should_be_engine_version_incorrect - end + bundle "outdated" + should_be_engine_version_incorrect end - it "fails when the patchlevel doesn't match" do - simulate_ruby_engine "jruby" do - update_repo2 do - build_gem "activesupport", "3.0" - update_git "foo", :path => lib_path("foo") - end + it "fails when the patchlevel doesn't match", :jruby do + update_repo2 do + build_gem "activesupport", "3.0" + update_git "foo", :path => lib_path("foo") + end - gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "activesupport", "2.3.5" - gem "foo", :git => "#{lib_path("foo")}" + gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "activesupport", "2.3.5" + gem "foo", :git => "#{lib_path("foo")}" - #{patchlevel_incorrect} - G + #{patchlevel_incorrect} + G - bundle "outdated" - should_be_patchlevel_incorrect - end + bundle "outdated" + should_be_patchlevel_incorrect end - it "fails when the patchlevel is a fixnum" do - simulate_ruby_engine "jruby" do - update_repo2 do - build_gem "activesupport", "3.0" - update_git "foo", :path => lib_path("foo") - end + it "fails when the patchlevel is a fixnum", :jruby do + update_repo2 do + build_gem "activesupport", "3.0" + update_git "foo", :path => lib_path("foo") + end - gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "activesupport", "2.3.5" - gem "foo", :git => "#{lib_path("foo")}" + gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "activesupport", "2.3.5" + gem "foo", :git => "#{lib_path("foo")}" - #{patchlevel_fixnum} - G + #{patchlevel_fixnum} + G - bundle "outdated" - should_be_patchlevel_fixnum - end + bundle "outdated" + should_be_patchlevel_fixnum end end end diff --git a/spec/bundler/plugins/install_spec.rb b/spec/bundler/plugins/install_spec.rb index 669ed09fb5..663363ca21 100644 --- a/spec/bundler/plugins/install_spec.rb +++ b/spec/bundler/plugins/install_spec.rb @@ -155,6 +155,10 @@ RSpec.describe "bundler plugin install" do end context "Gemfile eval" do + before do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + end + it "installs plugins listed in gemfile" do gemfile <<-G source '#{file_uri_for(gem_repo2)}' @@ -245,6 +249,7 @@ RSpec.describe "bundler plugin install" do describe "local plugin" do it "is installed when inside an app" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) gemfile "" bundle "plugin install foo --source #{file_uri_for(gem_repo2)}" @@ -287,21 +292,16 @@ RSpec.describe "bundler plugin install" do end # outside the app - Dir.chdir tmp - bundle "plugin install fubar --source #{file_uri_for(gem_repo2)}" + bundle "plugin install fubar --source #{file_uri_for(gem_repo2)}", :dir => tmp end it "inside the app takes precedence over global plugin" do - Dir.chdir bundled_app - bundle "shout" expect(out).to eq("local_one") end it "outside the app global plugin is used" do - Dir.chdir tmp - - bundle "shout" + bundle "shout", :dir => tmp expect(out).to eq("global_one") end end diff --git a/spec/bundler/plugins/source/example_spec.rb b/spec/bundler/plugins/source/example_spec.rb index f2151a5a73..aac506dc9a 100644 --- a/spec/bundler/plugins/source/example_spec.rb +++ b/spec/bundler/plugins/source/example_spec.rb @@ -215,6 +215,8 @@ RSpec.describe "real source plugins" do build_repo2 do build_plugin "bundler-source-gitp" do |s| s.write "plugins.rb", <<-RUBY + require "open3" + class SPlugin < Bundler::Plugin::API source "gitp" @@ -254,9 +256,7 @@ RSpec.describe "real source plugins" do mkdir_p(install_path.dirname) rm_rf(install_path) `git clone --no-checkout --quiet "\#{cache_path}" "\#{install_path}"` - Dir.chdir install_path do - `git reset --hard \#{revision}` - end + Open3.capture2e("git reset --hard \#{revision}", :chdir => install_path) spec_path = install_path.join("\#{spec.full_name}.gemspec") spec_path.open("wb") {|f| f.write spec.to_ruby } @@ -310,9 +310,8 @@ RSpec.describe "real source plugins" do cache_repo end - Dir.chdir cache_path do - `git rev-parse --verify \#{@ref}`.strip - end + output, _status = Open3.capture2e("git rev-parse --verify \#{@ref}", :chdir => cache_path) + output.strip end def base_name diff --git a/spec/bundler/plugins/source_spec.rb b/spec/bundler/plugins/source_spec.rb index c8deee96b1..14643e5c81 100644 --- a/spec/bundler/plugins/source_spec.rb +++ b/spec/bundler/plugins/source_spec.rb @@ -21,6 +21,7 @@ RSpec.describe "bundler source plugin" do end G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) plugin_should_be_installed("bundler-source-psource") end @@ -75,6 +76,7 @@ RSpec.describe "bundler source plugin" do end it "installs the explicit one" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) plugin_should_be_installed("another-psource") end @@ -100,6 +102,7 @@ RSpec.describe "bundler source plugin" do end it "installs the default one" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) plugin_should_be_installed("bundler-source-psource") end end diff --git a/spec/bundler/plugins/uninstall_spec.rb b/spec/bundler/plugins/uninstall_spec.rb new file mode 100644 index 0000000000..8180241911 --- /dev/null +++ b/spec/bundler/plugins/uninstall_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +RSpec.describe "bundler plugin uninstall" do + before do + build_repo2 do + build_plugin "foo" + build_plugin "kung-foo" + end + end + + it "shows proper error message when plugins are not specified" do + bundle "plugin uninstall" + expect(err).to include("No plugins to uninstall") + end + + it "uninstalls specified plugins" do + bundle "plugin install foo kung-foo --source #{file_uri_for(gem_repo2)}" + plugin_should_be_installed("foo") + plugin_should_be_installed("kung-foo") + + bundle "plugin uninstall foo" + expect(out).to include("Uninstalled plugin foo") + plugin_should_not_be_installed("foo") + plugin_should_be_installed("kung-foo") + end + + it "shows proper message when plugin is not installed" do + bundle "plugin uninstall foo" + expect(err).to include("Plugin foo is not installed") + plugin_should_not_be_installed("foo") + end + + describe "with --all" do + it "uninstalls all installed plugins" do + bundle "plugin install foo kung-foo --source #{file_uri_for(gem_repo2)}" + plugin_should_be_installed("foo") + plugin_should_be_installed("kung-foo") + + bundle "plugin uninstall --all" + plugin_should_not_be_installed("foo") + plugin_should_not_be_installed("kung-foo") + end + + it "shows proper no plugins installed message when no plugins installed" do + bundle "plugin uninstall --all" + expect(out).to include("No plugins installed") + end + end +end diff --git a/spec/bundler/quality_es_spec.rb b/spec/bundler/quality_es_spec.rb index 4238ac7452..90968e6270 100644 --- a/spec/bundler/quality_es_spec.rb +++ b/spec/bundler/quality_es_spec.rb @@ -40,12 +40,10 @@ RSpec.describe "La biblioteca si misma" do it "mantiene la calidad de lenguaje de la documentación" do included = /ronn/ error_messages = [] - Dir.chdir(root) do - `git ls-files -z -- man`.split("\x0").each do |filename| - next unless filename =~ included - error_messages << check_for_expendable_words(filename) - error_messages << check_for_specific_pronouns(filename) - end + man_tracked_files.each do |filename| + next unless filename =~ included + error_messages << check_for_expendable_words(filename) + error_messages << check_for_specific_pronouns(filename) end expect(error_messages.compact).to be_well_formed end @@ -53,12 +51,10 @@ RSpec.describe "La biblioteca si misma" do it "mantiene la calidad de lenguaje de oraciones usadas en el código fuente" do error_messages = [] exempt = /vendor/ - Dir.chdir(root) do - lib_tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_expendable_words(filename) - error_messages << check_for_specific_pronouns(filename) - end + lib_tracked_files.each do |filename| + next if filename =~ exempt + error_messages << check_for_expendable_words(filename) + error_messages << check_for_specific_pronouns(filename) end expect(error_messages.compact).to be_well_formed end diff --git a/spec/bundler/quality_spec.rb b/spec/bundler/quality_spec.rb index 09e59d88ae..177eb505a1 100644 --- a/spec/bundler/quality_spec.rb +++ b/spec/bundler/quality_spec.rb @@ -107,12 +107,10 @@ RSpec.describe "The library itself" do it "has no malformed whitespace" do exempt = /\.gitmodules|fixtures|vendor|LICENSE|vcr_cassettes|rbreadline\.diff|\.txt$/ error_messages = [] - Dir.chdir(root) do - tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_tab_characters(filename) - error_messages << check_for_extra_spaces(filename) - end + tracked_files.each do |filename| + next if filename =~ exempt + error_messages << check_for_tab_characters(filename) + error_messages << check_for_extra_spaces(filename) end expect(error_messages.compact).to be_well_formed end @@ -120,11 +118,9 @@ RSpec.describe "The library itself" do it "has no estraneous quotes" do exempt = /vendor|vcr_cassettes|LICENSE|rbreadline\.diff/ error_messages = [] - Dir.chdir(root) do - tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_straneous_quotes(filename) - end + tracked_files.each do |filename| + next if filename =~ exempt + error_messages << check_for_straneous_quotes(filename) end expect(error_messages.compact).to be_well_formed end @@ -132,11 +128,9 @@ RSpec.describe "The library itself" do it "does not include any leftover debugging or development mechanisms" do exempt = %r{quality_spec.rb|support/helpers|vcr_cassettes|\.md|\.ronn|\.txt|\.5|\.1} error_messages = [] - Dir.chdir(root) do - tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_debugging_mechanisms(filename) - end + tracked_files.each do |filename| + next if filename =~ exempt + error_messages << check_for_debugging_mechanisms(filename) end expect(error_messages.compact).to be_well_formed end @@ -144,11 +138,9 @@ RSpec.describe "The library itself" do it "does not include any unresolved merge conflicts" do error_messages = [] exempt = %r{lock/lockfile_spec|quality_spec|vcr_cassettes|\.ronn|lockfile_parser\.rb} - Dir.chdir(root) do - tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_git_merge_conflicts(filename) - end + tracked_files.each do |filename| + next if filename =~ exempt + error_messages << check_for_git_merge_conflicts(filename) end expect(error_messages.compact).to be_well_formed end @@ -156,32 +148,27 @@ RSpec.describe "The library itself" do it "maintains language quality of the documentation" do included = /ronn/ error_messages = [] - Dir.chdir(root) do - `git ls-files -z -- man`.split("\x0").each do |filename| - next unless filename =~ included - error_messages << check_for_expendable_words(filename) - error_messages << check_for_specific_pronouns(filename) - end + man_tracked_files.each do |filename| + next unless filename =~ included + error_messages << check_for_expendable_words(filename) + error_messages << check_for_specific_pronouns(filename) end expect(error_messages.compact).to be_well_formed end it "maintains language quality of sentences used in source code" do error_messages = [] - exempt = /vendor|vcr_cassettes/ - Dir.chdir(root) do - lib_tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_expendable_words(filename) - error_messages << check_for_specific_pronouns(filename) - end + exempt = /vendor|vcr_cassettes|CODE_OF_CONDUCT/ + lib_tracked_files.each do |filename| + next if filename =~ exempt + error_messages << check_for_expendable_words(filename) + error_messages << check_for_specific_pronouns(filename) end expect(error_messages.compact).to be_well_formed end it "documents all used settings" do exemptions = %w[ - auto_config_jobs deployment_means_frozen forget_cli_options gem.coc @@ -197,15 +184,13 @@ RSpec.describe "The library itself" do Bundler::Settings::NUMBER_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::NUMBER_KEYS" } Bundler::Settings::ARRAY_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::ARRAY_KEYS" } - Dir.chdir(root) do - key_pattern = /([a-z\._-]+)/i - lib_tracked_files.split("\x0").each do |filename| - each_line(filename) do |line, number| - line.scan(/Bundler\.settings\[:#{key_pattern}\]/).flatten.each {|s| all_settings[s] << "referenced at `#{filename}:#{number.succ}`" } - end + key_pattern = /([a-z\._-]+)/i + lib_tracked_files.each do |filename| + each_line(filename) do |line, number| + line.scan(/Bundler\.settings\[:#{key_pattern}\]/).flatten.each {|s| all_settings[s] << "referenced at `#{filename}:#{number.succ}`" } end - documented_settings = File.read("man/bundle-config.ronn")[/LIST OF AVAILABLE KEYS.*/m].scan(/^\* `#{key_pattern}`/).flatten end + documented_settings = File.read("man/bundle-config.ronn")[/LIST OF AVAILABLE KEYS.*/m].scan(/^\* `#{key_pattern}`/).flatten documented_settings.each do |s| all_settings.delete(s) @@ -231,54 +216,48 @@ RSpec.describe "The library itself" do end it "ships the correct set of files" do - Dir.chdir(root) do - git_list = shipped_files.split("\x0") + git_list = shipped_files - gem_list = Gem::Specification.load(gemspec.to_s).files + gem_list = Gem::Specification.load(gemspec.to_s).files - expect(git_list.to_set).to eq(gem_list.to_set) - end + expect(git_list.to_set).to eq(gem_list.to_set) end it "does not contain any warnings" do - Dir.chdir(root) do - exclusions = %w[ - lib/bundler/capistrano.rb - lib/bundler/deployment.rb - lib/bundler/gem_tasks.rb - lib/bundler/vlad.rb - lib/bundler/templates/gems.rb - ] - files_to_require = lib_tracked_files.split("\x0").grep(/\.rb$/) - exclusions - files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") } - files_to_require.map! {|f| f.chomp(".rb") } - sys_exec!("ruby -w -Ilib") do |input, _, _| - files_to_require.each do |f| - input.puts "require '#{f.sub(%r{\Alib/}, "")}'" - end + exclusions = %w[ + lib/bundler/capistrano.rb + lib/bundler/deployment.rb + lib/bundler/gem_tasks.rb + lib/bundler/vlad.rb + lib/bundler/templates/gems.rb + ] + files_to_require = lib_tracked_files.grep(/\.rb$/) - exclusions + files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") } + files_to_require.map! {|f| File.expand_path("../#{f}", __dir__) } + sys_exec!("ruby -w") do |input, _, _| + files_to_require.each do |f| + input.puts "require '#{f}'" end + end - warnings = last_command.stdboth.split("\n") - # ignore warnings around deprecated Object#=~ method in RubyGems - warnings.reject! {|w| w =~ %r{rubygems\/version.rb.*deprecated\ Object#=~} } + warnings = last_command.stdboth.split("\n") + # ignore warnings around deprecated Object#=~ method in RubyGems + warnings.reject! {|w| w =~ %r{rubygems\/version.rb.*deprecated\ Object#=~} } - expect(warnings).to be_well_formed - end + expect(warnings).to be_well_formed end it "does not use require internally, but require_relative" do - Dir.chdir(root) do - exempt = %r{templates/|vendor/} - all_bad_requires = [] - lib_tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - each_line(filename) do |line, number| - line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" } - end + exempt = %r{templates/|vendor/} + all_bad_requires = [] + lib_tracked_files.each do |filename| + next if filename =~ exempt + each_line(filename) do |line, number| + line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" } end - - expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}" end + + expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}" end private diff --git a/spec/bundler/realworld/edgecases_spec.rb b/spec/bundler/realworld/edgecases_spec.rb index a91e6a359e..48c37093b5 100644 --- a/spec/bundler/realworld/edgecases_spec.rb +++ b/spec/bundler/realworld/edgecases_spec.rb @@ -62,7 +62,7 @@ RSpec.describe "real world edgecases", :realworld => true, :sometimes => true do end it "is able to update a top-level dependency when there is a conflict on a shared transitive child" do - # from https://github.com/bundler/bundler/issues/5031 + # from https://github.com/rubygems/bundler/issues/5031 gemfile <<-G source "https://rubygems.org" @@ -194,7 +194,7 @@ RSpec.describe "real world edgecases", :realworld => true, :sometimes => true do expect(lockfile).to include(rubygems_version("paperclip", "~> 5.1.0")) end - # https://github.com/bundler/bundler/issues/1500 + # https://github.com/rubygems/bundler/issues/1500 it "does not fail install because of gem plugins" do realworld_system_gems("open_gem --version 1.4.2", "rake --version 0.9.2") gemfile <<-G diff --git a/spec/bundler/realworld/fixtures/warbler/.gitignore b/spec/bundler/realworld/fixtures/warbler/.gitignore new file mode 100644 index 0000000000..d392f0e82c --- /dev/null +++ b/spec/bundler/realworld/fixtures/warbler/.gitignore @@ -0,0 +1 @@ +*.jar diff --git a/spec/bundler/realworld/fixtures/warbler/Gemfile b/spec/bundler/realworld/fixtures/warbler/Gemfile new file mode 100644 index 0000000000..4fbf2d05a7 --- /dev/null +++ b/spec/bundler/realworld/fixtures/warbler/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "demo", :path => "./demo" +gem "jruby-jars", "~> 9.2" +gem "warbler", "~> 2.0" diff --git a/spec/bundler/realworld/fixtures/warbler/Gemfile.lock b/spec/bundler/realworld/fixtures/warbler/Gemfile.lock new file mode 100644 index 0000000000..6363b8bbd8 --- /dev/null +++ b/spec/bundler/realworld/fixtures/warbler/Gemfile.lock @@ -0,0 +1,29 @@ +PATH + remote: demo + specs: + demo (1.0) + +GEM + remote: https://rubygems.org/ + specs: + jruby-jars (9.2.9.0) + jruby-rack (1.1.21) + rake (13.0.1) + rubyzip (1.3.0) + warbler (2.0.5) + jruby-jars (>= 9.0.0.0) + jruby-rack (>= 1.1.1, < 1.3) + rake (>= 10.1.0) + rubyzip (~> 1.0, < 1.4) + +PLATFORMS + java + ruby + +DEPENDENCIES + demo! + jruby-jars (~> 9.2) + warbler (~> 2.0) + +BUNDLED WITH + 2.2.0.dev diff --git a/spec/bundler/realworld/fixtures/warbler/bin/warbler-example.rb b/spec/bundler/realworld/fixtures/warbler/bin/warbler-example.rb new file mode 100644 index 0000000000..25f614ecc2 --- /dev/null +++ b/spec/bundler/realworld/fixtures/warbler/bin/warbler-example.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +puts require "bundler/setup" diff --git a/spec/bundler/realworld/fixtures/warbler/demo/demo.gemspec b/spec/bundler/realworld/fixtures/warbler/demo/demo.gemspec new file mode 100644 index 0000000000..ed5a0dc080 --- /dev/null +++ b/spec/bundler/realworld/fixtures/warbler/demo/demo.gemspec @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +Gem::Specification.new do |spec| + spec.name = "demo" + spec.version = "1.0" + spec.author = "Somebody" + spec.summary = "A demo gem" + spec.license = "MIT" + spec.homepage = "https://example.org" +end diff --git a/spec/bundler/resolver/platform_spec.rb b/spec/bundler/resolver/platform_spec.rb index fee0cf1f1c..415c5458df 100644 --- a/spec/bundler/resolver/platform_spec.rb +++ b/spec/bundler/resolver/platform_spec.rb @@ -28,6 +28,98 @@ RSpec.describe "Resolving platform craziness" do end end + it "takes the latest ruby gem, even if an older platform specific version is available" do + @index = build_index do + gem "foo", "1.0.0" + gem "foo", "1.0.0", "x64-mingw32" + gem "foo", "1.1.0" + end + dep "foo" + platforms "x64-mingw32" + + should_resolve_as %w[foo-1.1.0] + end + + it "takes the ruby version if the platform version is incompatible" do + @index = build_index do + gem "bar", "1.0.0" + gem "foo", "1.0.0" + gem "foo", "1.0.0", "x64-mingw32" do + dep "bar", "< 1" + end + end + dep "foo" + platforms "x64-mingw32" + + should_resolve_as %w[foo-1.0.0] + end + + it "prefers the platform specific gem to the ruby version" do + @index = build_index do + gem "foo", "1.0.0" + gem "foo", "1.0.0", "x64-mingw32" + end + dep "foo" + platforms "x64-mingw32" + + should_resolve_as %w[foo-1.0.0-x64-mingw32] + end + + it "takes the latest ruby gem if the platform specific gem doesn't match the required_ruby_version" do + @index = build_index do + gem "foo", "1.0.0" + gem "foo", "1.0.0", "x64-mingw32" + gem "foo", "1.1.0" + gem "foo", "1.1.0", "x64-mingw32" do |s| + s.required_ruby_version = [">= 2.0", "< 2.4"] + end + gem "Ruby\0", "2.5.1" + end + dep "foo" + dep "Ruby\0", "2.5.1" + platforms "x64-mingw32" + + should_resolve_as %w[foo-1.1.0] + end + + it "takes the latest ruby gem with required_ruby_version if the platform specific gem doesn't match the required_ruby_version" do + @index = build_index do + gem "foo", "1.0.0" + gem "foo", "1.0.0", "x64-mingw32" + gem "foo", "1.1.0" do |s| + s.required_ruby_version = [">= 2.0"] + end + gem "foo", "1.1.0", "x64-mingw32" do |s| + s.required_ruby_version = [">= 2.0", "< 2.4"] + end + gem "Ruby\0", "2.5.1" + end + dep "foo" + dep "Ruby\0", "2.5.1" + platforms "x64-mingw32" + + should_resolve_as %w[foo-1.1.0] + end + + it "takes the latest ruby gem if the platform specific gem doesn't match the required_ruby_version with multiple platforms" do + @index = build_index do + gem "foo", "1.0.0" + gem "foo", "1.0.0", "x64-mingw32" + gem "foo", "1.1.0" do |s| + s.required_ruby_version = [">= 2.0"] + end + gem "foo", "1.1.0", "x64-mingw32" do |s| + s.required_ruby_version = [">= 2.0", "< 2.4"] + end + gem "Ruby\0", "2.5.1" + end + dep "foo" + dep "Ruby\0", "2.5.1" + platforms "x86_64-linux", "x64-mingw32" + + should_resolve_as %w[foo-1.1.0] + end + describe "with mingw32" do before :each do @index = build_index do @@ -90,11 +182,11 @@ RSpec.describe "Resolving platform craziness" do end end - it "reports on the conflict" do + it "takes the ruby version as fallback" do platforms "ruby", "java" dep "foo" - should_conflict_on "baz" + should_resolve_as %w[bar-1.0.0 baz-1.0.0 foo-1.0.0] end end end diff --git a/spec/bundler/runtime/executable_spec.rb b/spec/bundler/runtime/executable_spec.rb index 003be97cd6..e420594f52 100644 --- a/spec/bundler/runtime/executable_spec.rb +++ b/spec/bundler/runtime/executable_spec.rb @@ -9,6 +9,8 @@ RSpec.describe "Running bin/* commands" do end it "runs the bundled command when in the bundle" do + skip "exec format error" if Gem.win_platform? + bundle! "binstubs rack" build_gem "rack", "2.0", :to_system => true do |s| @@ -20,6 +22,8 @@ RSpec.describe "Running bin/* commands" do end it "allows the location of the gem stubs to be specified" do + skip "created in bin :/" if Gem.win_platform? + bundle! "binstubs rack", :path => "gbin" expect(bundled_app("bin")).not_to exist @@ -30,6 +34,8 @@ RSpec.describe "Running bin/* commands" do end it "allows absolute paths as a specification of where to install bin stubs" do + skip "exec format error" if Gem.win_platform? + bundle! "binstubs rack", :path => tmp("bin") gembin tmp("bin/rackup") @@ -38,28 +44,32 @@ RSpec.describe "Running bin/* commands" do it "uses the default ruby install name when shebang is not specified" do bundle! "binstubs rack" - expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env #{RbConfig::CONFIG["ruby_install_name"]}\n") + expect(File.open(bundled_app("bin/rackup")).gets).to eq("#!/usr/bin/env #{RbConfig::CONFIG["ruby_install_name"]}\n") end it "allows the name of the shebang executable to be specified" do + skip "not created with custom name :/" if Gem.win_platform? + bundle! "binstubs rack", :shebang => "ruby-foo" - expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env ruby-foo\n") + expect(File.open(bundled_app("bin/rackup")).gets).to eq("#!/usr/bin/env ruby-foo\n") end it "runs the bundled command when out of the bundle" do + skip "exec format error" if Gem.win_platform? + bundle! "binstubs rack" build_gem "rack", "2.0", :to_system => true do |s| s.executables = "rackup" end - Dir.chdir(tmp) do - gembin "rackup" - expect(out).to eq("1.0.0") - end + gembin "rackup", :dir => tmp + expect(out).to eq("1.0.0") end it "works with gems in path" do + skip "exec format error" if Gem.win_platform? + build_lib "rack", :path => lib_path("rack") do |s| s.executables = "rackup" end @@ -94,12 +104,16 @@ RSpec.describe "Running bin/* commands" do end it "does not generate bin stubs if the option was not specified" do + skip "generated :/" if Gem.win_platform? + bundle! "install" expect(bundled_app("bin/rackup")).not_to exist end it "allows you to stop installing binstubs", :bundler => "< 3" do + skip "delete permission error" if Gem.win_platform? + bundle! "install --binstubs bin/" bundled_app("bin/rackup").rmtree bundle! "install --binstubs \"\"" @@ -143,6 +157,8 @@ RSpec.describe "Running bin/* commands" do end it "use BUNDLE_GEMFILE gemfile for binstub" do + skip "exec format error" if Gem.win_platform? + # context with bin/bundler w/ default Gemfile bundle! "binstubs bundler" diff --git a/spec/bundler/runtime/gem_tasks_spec.rb b/spec/bundler/runtime/gem_tasks_spec.rb index 74270a2316..9d673bb9cc 100644 --- a/spec/bundler/runtime/gem_tasks_spec.rb +++ b/spec/bundler/runtime/gem_tasks_spec.rb @@ -29,7 +29,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do it "includes the relevant tasks" do with_gem_path_as(Spec::Path.base_system_gems.to_s) do - sys_exec "#{rake} -T", "RUBYOPT" => "-I#{lib_dir}" + sys_exec "#{rake} -T", :env => { "RUBYOPT" => opt_add("-I#{lib_dir}", ENV["RUBYOPT"]) } end expect(err).to be_empty @@ -47,7 +47,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do it "defines a working `rake install` task" do with_gem_path_as(Spec::Path.base_system_gems.to_s) do - sys_exec "#{rake} install", "RUBYOPT" => "-I#{lib_dir}" + sys_exec "#{rake} install", :env => { "RUBYOPT" => opt_add("-I#{lib_dir}", ENV["RUBYOPT"]) } end expect(err).to be_empty @@ -60,13 +60,11 @@ RSpec.describe "require 'bundler/gem_tasks'" do context "rake build when path has spaces" do before do spaced_bundled_app = tmp.join("bundled app") - FileUtils.mv bundled_app, spaced_bundled_app - Dir.chdir(spaced_bundled_app) + FileUtils.cp_r bundled_app, spaced_bundled_app + bundle! "exec rake build", :dir => spaced_bundled_app end it "still runs successfully" do - bundle! "exec rake build" - expect(err).to be_empty end end diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index cd762fe636..fb6c6e90ad 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -46,6 +46,8 @@ RSpec.describe "bundler/inline#gemfile" do end it "requires the gems" do + skip "gems not found" if Gem.win_platform? + script <<-RUBY gemfile do path "#{lib_path}" do @@ -95,6 +97,8 @@ RSpec.describe "bundler/inline#gemfile" do end it "lets me use my own ui object" do + skip "prints just one CONFIRMED" if Gem.win_platform? + script <<-RUBY, :artifice => "endpoint" require '#{lib_dir}/bundler' class MyBundlerUI < Bundler::UI::Silent @@ -229,16 +233,14 @@ RSpec.describe "bundler/inline#gemfile" do 1.13.6 G - in_app_root do - script <<-RUBY - gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" - end + script <<-RUBY + gemfile do + source "#{file_uri_for(gem_repo1)}" + gem "rack" + end - puts RACK - RUBY - end + puts RACK + RUBY expect(err).to be_empty expect(exitstatus).to be_zero if exitstatus @@ -261,16 +263,14 @@ RSpec.describe "bundler/inline#gemfile" do it "installs inline gems when BUNDLE_GEMFILE is set to an empty string" do ENV["BUNDLE_GEMFILE"] = "" - in_app_root do - script <<-RUBY - gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" - end + script <<-RUBY + gemfile do + source "#{file_uri_for(gem_repo1)}" + gem "rack" + end - puts RACK - RUBY - end + puts RACK + RUBY expect(err).to be_empty expect(exitstatus).to be_zero if exitstatus diff --git a/spec/bundler/runtime/load_spec.rb b/spec/bundler/runtime/load_spec.rb index 7de67e247c..a406fbaf49 100644 --- a/spec/bundler/runtime/load_spec.rb +++ b/spec/bundler/runtime/load_spec.rb @@ -7,6 +7,7 @@ RSpec.describe "Bundler.load" do source "#{file_uri_for(gem_repo1)}" gem "rack" G + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) end it "provides a list of the env dependencies" do @@ -32,6 +33,7 @@ RSpec.describe "Bundler.load" do gem "rack" G bundle! :install + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) end it "provides a list of the env dependencies" do @@ -101,7 +103,7 @@ RSpec.describe "Bundler.load" do source "#{file_uri_for(gem_repo1)}" gem "activerecord" G - + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) Bundler.load.specs.each do |spec| expect(spec.to_yaml).not_to match(/^\s+source:/) expect(spec.to_yaml).not_to match(/^\s+groups:/) diff --git a/spec/bundler/runtime/platform_spec.rb b/spec/bundler/runtime/platform_spec.rb index f7e93eacf1..70c7594395 100644 --- a/spec/bundler/runtime/platform_spec.rb +++ b/spec/bundler/runtime/platform_spec.rb @@ -113,11 +113,12 @@ RSpec.describe "Bundler.setup with multi platform stuff" do bundle! "install" expect(the_bundle).to include_gems "platform_specific 1.0 RUBY" + expect(the_bundle).to not_include_gems "nokogiri" end end it "allows specifying only-ruby-platform on windows with gemspec dependency" do - build_lib("foo", "1.0", :path => ".") do |s| + build_lib("foo", "1.0", :path => bundled_app) do |s| s.add_dependency "rack" end diff --git a/spec/bundler/runtime/require_spec.rb b/spec/bundler/runtime/require_spec.rb index a8d7826123..3b9021b4fc 100644 --- a/spec/bundler/runtime/require_spec.rb +++ b/spec/bundler/runtime/require_spec.rb @@ -155,7 +155,7 @@ RSpec.describe "Bundler.require" do begin Bundler.require rescue LoadError => e - $stderr.puts "ZOMG LOAD ERROR: \#{e.message}" + warn "ZOMG LOAD ERROR: \#{e.message}" end RUBY run(cmd) @@ -228,7 +228,7 @@ RSpec.describe "Bundler.require" do begin Bundler.require rescue LoadError => e - $stderr.puts "ZOMG LOAD ERROR" if e.message.include?("Could not open library 'libfuuu-1.0'") + warn "ZOMG LOAD ERROR" if e.message.include?("Could not open library 'libfuuu-1.0'") end RUBY run(cmd) @@ -251,7 +251,7 @@ RSpec.describe "Bundler.require" do begin Bundler.require rescue LoadError => e - $stderr.puts "ZOMG LOAD ERROR: \#{e.message}" + warn "ZOMG LOAD ERROR: \#{e.message}" end RUBY run(cmd) @@ -423,7 +423,7 @@ RSpec.describe "Bundler.require with platform specific dependencies" do source "#{file_uri_for(gem_repo1)}" platforms :#{not_local_tag} do - gem "fail", :require => "omgomg" + gem "platform_specific", :require => "omgomg" end gem "rack", "1.0.0" @@ -434,6 +434,8 @@ RSpec.describe "Bundler.require with platform specific dependencies" do end it "requires gems pinned to multiple platforms, including the current one" do + skip "platform issues" if Gem.win_platform? + install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index 7f00a63078..b39a740653 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -159,7 +159,7 @@ RSpec.describe "Bundler.setup" do "/gems/actionpack-2.3.2/lib", "/gems/actionmailer-2.3.2/lib", "/gems/activesupport-2.3.2/lib", - "/gems/rake-12.3.2/lib" + "/gems/rake-13.0.1/lib" ) end @@ -218,7 +218,7 @@ RSpec.describe "Bundler.setup" do Bundler.setup R - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist end it "doesn't change the Gemfile.lock if the setup fails" do @@ -227,7 +227,7 @@ RSpec.describe "Bundler.setup" do gem "rack" G - lockfile = File.read(bundled_app("Gemfile.lock")) + lockfile = File.read(bundled_app_lock) gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -241,7 +241,7 @@ RSpec.describe "Bundler.setup" do Bundler.setup R - expect(File.read(bundled_app("Gemfile.lock"))).to eq(lockfile) + expect(File.read(bundled_app_lock)).to eq(lockfile) end it "makes a Gemfile.lock if setup succeeds" do @@ -250,12 +250,12 @@ RSpec.describe "Bundler.setup" do gem "rack" G - File.read(bundled_app("Gemfile.lock")) + File.read(bundled_app_lock) - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) run "1" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end describe "$BUNDLE_GEMFILE" do @@ -460,7 +460,7 @@ RSpec.describe "Bundler.setup" do it "provides a good exception if the lockfile is unavailable" do bundle "install" - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) break_git! @@ -489,15 +489,16 @@ RSpec.describe "Bundler.setup" do it "does not randomly change the path when specifying --path and the bundle directory becomes read only" do bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") - with_read_only("**/*") do + with_read_only("#{bundled_app}/**/*") do expect(the_bundle).to include_gems "rack 1.0.0" end end it "finds git gem when default bundle path becomes read only" do + bundle "config set --local path .bundle" bundle "install" - with_read_only("#{Bundler.bundle_path}/**/*") do + with_read_only("#{bundled_app(".bundle")}/**/*") do expect(the_bundle).to include_gems "rack 1.0.0" end end @@ -708,7 +709,7 @@ end end context "when the user has one set" do - before { ENV["MANPATH"] = "/foo:" } + before { ENV["MANPATH"] = "/foo#{File::PATH_SEPARATOR}" } it "adds the gem's man dir to the MANPATH" do install_gemfile! <<-G @@ -717,7 +718,7 @@ end G run! "puts ENV['MANPATH']" - expect(out).to eq("#{default_bundle_path("gems/with_man-1.0/man")}:/foo") + expect(out).to eq("#{default_bundle_path("gems/with_man-1.0/man")}#{File::PATH_SEPARATOR}/foo") end end @@ -793,6 +794,8 @@ end let(:full_name) { "bundler-#{Bundler::VERSION}" } before do + skip "symlink destination exists" if Gem.win_platform? + FileUtils.ln_sf(gem_home, symlinked_gem_home) gems_dir = File.join(gem_home, "gems") specifications_dir = File.join(gem_home, "specifications") @@ -863,11 +866,9 @@ end gem 'foo', '1.2.3', :path => 'vendor/foo' G - Dir.chdir(bundled_app.parent) do - run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app("Gemfile").to_s } - require 'foo' - R - end + run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s }, :dir => bundled_app.parent + require 'foo' + R expect(err).to be_empty end @@ -887,11 +888,9 @@ end bundle :install - Dir.chdir(bundled_app.parent) do - run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app("Gemfile").to_s } - require 'foo' - R - end + run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s }, :dir => bundled_app.parent + require 'foo' + R expect(err).to be_empty end @@ -1015,6 +1014,8 @@ end end it "error intelligently if the gemspec has a LoadError" do + skip "whitespace issue?" if Gem.win_platform? + ref = update_git "bar", :gemspec => false do |s| s.write "bar.gemspec", "require 'foobarbaz'" end.ref_for("HEAD") @@ -1202,11 +1203,13 @@ end describe "default gem activation" do let(:exemptions) do - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7") + exempts = if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7") %w[did_you_mean] else %w[io-console openssl] end << "bundler" + exempts << "fiddle" if Gem.win_platform? && Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7") + exempts end let(:activation_warning_hack) { strip_whitespace(<<-RUBY) } @@ -1256,6 +1259,8 @@ end end it "activates no gems with bundle exec that is loaded" do + skip "not executable" if Gem.win_platform? + install_gemfile! "" create_file("script.rb", "#!/usr/bin/env ruby\n\n#{code}") FileUtils.chmod(0o777, bundled_app("script.rb")) @@ -1367,7 +1372,7 @@ end end it "takes care of requiring rubygems" do - sys_exec("#{Gem.ruby} -I#{lib_dir} -e \"puts require('bundler/setup')\"", "RUBYOPT" => "--disable=gems") + sys_exec("#{Gem.ruby} -I#{lib_dir} -rbundler/setup -e'puts true'", :env => { "RUBYOPT" => opt_add("--disable=gems", ENV["RUBYOPT"]) }) expect(last_command.stdboth).to eq("true") end diff --git a/spec/bundler/runtime/with_unbundled_env_spec.rb b/spec/bundler/runtime/with_unbundled_env_spec.rb index 4aaf9d499c..80c5d92b76 100644 --- a/spec/bundler/runtime/with_unbundled_env_spec.rb +++ b/spec/bundler/runtime/with_unbundled_env_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true RSpec.describe "Bundler.with_env helpers" do - def bundle_exec_ruby!(code, options = {}) + def bundle_exec_ruby!(args, options = {}) build_bundler_context options - bundle! "exec '#{Gem.ruby}' -e #{code}", options + bundle! "exec '#{Gem.ruby}' #{args}", options end def build_bundler_context(options = {}) @@ -12,39 +12,47 @@ RSpec.describe "Bundler.with_env helpers" do bundle "install", options end + def run_bundler_script(env, script) + system(env, "ruby", "-I#{lib_dir}", "-rbundler", script.to_s) + end + describe "Bundler.original_env" do it "should return the PATH present before bundle was activated" do - code = "print Bundler.original_env['PATH']" + create_file("source.rb", <<-RUBY) + print Bundler.original_env["PATH"] + RUBY path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo" with_path_as(path) do - bundle_exec_ruby!(code.dump) + bundle_exec_ruby!(bundled_app("source.rb").to_s) expect(last_command.stdboth).to eq(path) end end it "should return the GEM_PATH present before bundle was activated" do - code = "print Bundler.original_env['GEM_PATH']" - gem_path = ENV["GEM_PATH"] + ":/foo" + create_file("source.rb", <<-RUBY) + print Bundler.original_env['GEM_PATH'] + RUBY + gem_path = ENV["GEM_PATH"] + "#{File::PATH_SEPARATOR}/foo" with_gem_path_as(gem_path) do - bundle_exec_ruby!(code.dump) + bundle_exec_ruby!(bundled_app("source.rb").to_s) expect(last_command.stdboth).to eq(gem_path) end end it "works with nested bundle exec invocations" do - create_file("exe.rb", <<-'RB') + create_file("exe.rb", <<-'RUBY') count = ARGV.first.to_i exit if count < 0 - STDERR.puts "#{count} #{ENV["PATH"].end_with?(":/foo")}" + STDERR.puts "#{count} #{ENV["PATH"].end_with?("#{File::PATH_SEPARATOR}/foo")}" if count == 2 - ENV["PATH"] = "#{ENV["PATH"]}:/foo" + ENV["PATH"] = "#{ENV["PATH"]}#{File::PATH_SEPARATOR}/foo" end exec(Gem.ruby, __FILE__, (count - 1).to_s) - RB + RUBY path = `getconf PATH`.strip + File::PATH_SEPARATOR + File.dirname(Gem.ruby) with_path_as(path) do build_bundler_context - bundle! "exec '#{Gem.ruby}' #{bundled_app("exe.rb")} 2" + bundle_exec_ruby!("#{bundled_app("exe.rb")} 2") end expect(err).to eq <<-EOS.strip 2 false @@ -58,40 +66,50 @@ RSpec.describe "Bundler.with_env helpers" do ENV.replace(ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) }) original = ruby!('puts ENV.to_a.map {|e| e.join("=") }.sort.join("\n")') - code = 'puts Bundler.original_env.to_a.map {|e| e.join("=") }.sort.join("\n")' - bundle_exec_ruby! code.dump + create_file("source.rb", <<-RUBY) + puts Bundler.original_env.to_a.map {|e| e.join("=") }.sort.join("\n") + RUBY + bundle_exec_ruby! bundled_app("source.rb") expect(out).to eq original end end shared_examples_for "an unbundling helper" do it "should delete BUNDLE_PATH" do - code = "print #{modified_env}.has_key?('BUNDLE_PATH')" + create_file("source.rb", <<-RUBY) + print #{modified_env}.has_key?('BUNDLE_PATH') + RUBY ENV["BUNDLE_PATH"] = "./foo" - bundle_exec_ruby! code.dump + bundle_exec_ruby! bundled_app("source.rb") expect(last_command.stdboth).to include "false" end it "should remove '-rbundler/setup' from RUBYOPT" do - code = "print #{modified_env}['RUBYOPT']" + create_file("source.rb", <<-RUBY) + print #{modified_env}['RUBYOPT'] + RUBY ENV["RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}" - bundle_exec_ruby! code.dump, :env => { "BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM" => "true" } + bundle_exec_ruby! bundled_app("source.rb"), :env => { "BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM" => "true" } expect(last_command.stdboth).not_to include("-rbundler/setup") end it "should restore RUBYLIB", :ruby_repo do - code = "print #{modified_env}['RUBYLIB']" + create_file("source.rb", <<-RUBY) + print #{modified_env}['RUBYLIB'] + RUBY ENV["RUBYLIB"] = lib_dir.to_s + File::PATH_SEPARATOR + "/foo" ENV["BUNDLER_ORIG_RUBYLIB"] = lib_dir.to_s + File::PATH_SEPARATOR + "/foo-original" - bundle_exec_ruby! code.dump + bundle_exec_ruby! bundled_app("source.rb") expect(last_command.stdboth).to include("/foo-original") end it "should restore the original MANPATH" do - code = "print #{modified_env}['MANPATH']" + create_file("source.rb", <<-RUBY) + print #{modified_env}['MANPATH'] + RUBY ENV["MANPATH"] = "/foo" ENV["BUNDLER_ORIG_MANPATH"] = "/foo-original" - bundle_exec_ruby! code.dump + bundle_exec_ruby! bundled_app("source.rb") expect(last_command.stdboth).to include("/foo-original") end end @@ -111,7 +129,7 @@ RSpec.describe "Bundler.with_env helpers" do describe "Bundler.with_original_env" do it "should set ENV to original_env in the block" do expected = Bundler.original_env - actual = Bundler.with_original_env { ENV.to_hash } + actual = Bundler.with_original_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) } expect(actual).to eq(expected) end @@ -129,7 +147,7 @@ RSpec.describe "Bundler.with_env helpers" do expected = Bundler.unbundled_env actual = Bundler.ui.silence do - Bundler.with_clean_env { ENV.to_hash } + Bundler.with_clean_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) } end expect(actual).to eq(expected) @@ -147,7 +165,7 @@ RSpec.describe "Bundler.with_env helpers" do describe "Bundler.with_unbundled_env" do it "should set ENV to unbundled_env in the block" do expected = Bundler.unbundled_env - actual = Bundler.with_unbundled_env { ENV.to_hash } + actual = Bundler.with_unbundled_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) } expect(actual).to eq(expected) end @@ -161,53 +179,53 @@ RSpec.describe "Bundler.with_env helpers" do end describe "Bundler.original_system" do - let(:code) do - <<~RUBY - Bundler.original_system(%([ "\$BUNDLE_FOO" = "bar" ] && exit 42)) + before do + create_file("source.rb", <<-'RUBY') + Bundler.original_system("ruby", "-e", "exit(42) if ENV['BUNDLE_FOO'] == 'bar'") exit $?.exitstatus RUBY end it "runs system inside with_original_env" do - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") + run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb")) expect($?.exitstatus).to eq(42) end end describe "Bundler.clean_system", :bundler => 2 do - let(:code) do - <<~RUBY - Bundler.ui.silence { Bundler.clean_system(%([ "\$BUNDLE_FOO" = "bar" ] || exit 42)) } + before do + create_file("source.rb", <<-'RUBY') + Bundler.ui.silence { Bundler.clean_system("ruby", "-e", "exit(42) unless ENV['BUNDLE_FOO'] == 'bar'") } exit $?.exitstatus RUBY end it "runs system inside with_clean_env" do - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") + run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb")) expect($?.exitstatus).to eq(42) end end describe "Bundler.unbundled_system" do - let(:code) do - <<~RUBY - Bundler.unbundled_system(%([ "\$BUNDLE_FOO" = "bar" ] || exit 42)) + before do + create_file("source.rb", <<-'RUBY') + Bundler.unbundled_system("ruby", "-e", "exit(42) unless ENV['BUNDLE_FOO'] == 'bar'") exit $?.exitstatus RUBY end it "runs system inside with_unbundled_env" do - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") + run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb")) expect($?.exitstatus).to eq(42) end end describe "Bundler.original_exec" do - let(:code) do - <<~RUBY + before do + create_file("source.rb", <<-'RUBY') Process.fork do exit Bundler.original_exec(%(test "\$BUNDLE_FOO" = "bar")) end @@ -221,14 +239,14 @@ RSpec.describe "Bundler.with_env helpers" do it "runs exec inside with_original_env" do skip "Fork not implemented" if Gem.win_platform? - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") + run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb")) expect($?.exitstatus).to eq(0) end end describe "Bundler.clean_exec", :bundler => 2 do - let(:code) do - <<~RUBY + before do + create_file("source.rb", <<-'RUBY') Process.fork do exit Bundler.ui.silence { Bundler.clean_exec(%(test "\$BUNDLE_FOO" = "bar")) } end @@ -242,14 +260,14 @@ RSpec.describe "Bundler.with_env helpers" do it "runs exec inside with_clean_env" do skip "Fork not implemented" if Gem.win_platform? - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") + run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb")) expect($?.exitstatus).to eq(1) end end describe "Bundler.unbundled_exec" do - let(:code) do - <<~RUBY + before do + create_file("source.rb", <<-'RUBY') Process.fork do exit Bundler.unbundled_exec(%(test "\$BUNDLE_FOO" = "bar")) end @@ -263,7 +281,7 @@ RSpec.describe "Bundler.with_env helpers" do it "runs exec inside with_clean_env" do skip "Fork not implemented" if Gem.win_platform? - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") + run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb")) expect($?.exitstatus).to eq(1) end end diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb index 0a49b46aaa..6b08cb203f 100644 --- a/spec/bundler/spec_helper.rb +++ b/spec/bundler/spec_helper.rb @@ -2,7 +2,6 @@ require_relative "support/path" -$:.unshift Spec::Path.spec_dir.to_s $:.unshift Spec::Path.lib_dir.to_s require "bundler/psyched_yaml" @@ -15,14 +14,15 @@ if File.expand_path(__FILE__) =~ %r{([^\w/\.:\-])} end require "bundler" -require "rspec" +require "rspec/core" +require "rspec/expectations" +require "rspec/mocks" require_relative "support/builders" require_relative "support/filters" require_relative "support/helpers" require_relative "support/indexes" require_relative "support/matchers" -require_relative "support/parallel" require_relative "support/permissions" require_relative "support/platforms" require_relative "support/sometimes" @@ -49,6 +49,8 @@ RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = ".rspec_status" + config.silence_filter_announcements = !ENV["TEST_ENV_NUMBER"].nil? + config.disable_monkey_patching! # Since failures cause us to keep a bunch of long strings in memory, stop @@ -59,7 +61,6 @@ RSpec.configure do |config| config.bisect_runner = :shell - original_wd = Dir.pwd original_env = ENV.to_hash config.expect_with :rspec do |c| @@ -81,8 +82,7 @@ RSpec.configure do |config| config.before :suite do require_relative "support/rubygems_ext" - Spec::Rubygems.setup - ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb" + Spec::Rubygems.test_setup ENV["BUNDLE_SPEC_RUN"] = "true" ENV["BUNDLE_USER_CONFIG"] = ENV["BUNDLE_USER_CACHE"] = ENV["BUNDLE_USER_PLUGIN"] = nil ENV["GEMRC"] = nil @@ -105,7 +105,7 @@ RSpec.configure do |config| ENV.replace(original_env) reset! system_gems [] - in_app_root + @command_executions = [] Bundler.ui.silence { example.run } @@ -118,8 +118,6 @@ RSpec.configure do |config| message end end - - Dir.chdir(original_wd) end config.after :suite do diff --git a/spec/bundler/support/artifice/compact_index.rb b/spec/bundler/support/artifice/compact_index.rb index 72abf26224..67fd05f9a2 100644 --- a/spec/bundler/support/artifice/compact_index.rb +++ b/spec/bundler/support/artifice/compact_index.rb @@ -100,7 +100,7 @@ class CompactIndexAPI < Endpoint get "/versions" do etag_response do file = tmp("versions.list") - file.delete if file.file? + FileUtils.rm_f(file) file = CompactIndex::VersionsFile.new(file.to_s) file.create(gems) file.contents diff --git a/spec/bundler/support/artifice/compact_index_concurrent_download.rb b/spec/bundler/support/artifice/compact_index_concurrent_download.rb index 7f989a3f37..14c31f35a4 100644 --- a/spec/bundler/support/artifice/compact_index_concurrent_download.rb +++ b/spec/bundler/support/artifice/compact_index_concurrent_download.rb @@ -10,7 +10,7 @@ class CompactIndexConcurrentDownload < CompactIndexAPI "localgemserver.test.80.dd34752a738ee965a2a4298dc16db6c5", "versions") # Verify the original (empty) content hasn't been deleted, e.g. on a retry - File.read(versions) == "" || raise("Original file should be present and empty") + File.binread(versions) == "" || raise("Original file should be present and empty") # Verify this is only requested once for a partial download env["HTTP_RANGE"] || raise("Missing Range header for expected partial download") @@ -21,7 +21,7 @@ class CompactIndexConcurrentDownload < CompactIndexAPI etag_response do file = tmp("versions.list") - file.delete if file.file? + FileUtils.rm_f(file) file = CompactIndex::VersionsFile.new(file.to_s) file.create(gems) file.contents diff --git a/spec/bundler/support/artifice/compact_index_creds_diff_host.rb b/spec/bundler/support/artifice/compact_index_creds_diff_host.rb index 6c3442e14b..cfe22c7f51 100644 --- a/spec/bundler/support/artifice/compact_index_creds_diff_host.rb +++ b/spec/bundler/support/artifice/compact_index_creds_diff_host.rb @@ -31,7 +31,7 @@ class CompactIndexCredsDiffHost < CompactIndexAPI get "/no/creds/:id" do if request.host.include?("diffhost") && !auth.provided? - File.read("#{gem_repo1}/gems/#{params[:id]}") + File.binread("#{gem_repo1}/gems/#{params[:id]}") end end end diff --git a/spec/bundler/support/artifice/compact_index_extra.rb b/spec/bundler/support/artifice/compact_index_extra.rb index 3a09afd06f..cec368276a 100644 --- a/spec/bundler/support/artifice/compact_index_extra.rb +++ b/spec/bundler/support/artifice/compact_index_extra.rb @@ -14,11 +14,11 @@ class CompactIndexExtra < CompactIndexAPI end get "/extra/specs.4.8.gz" do - File.read("#{gem_repo2}/specs.4.8.gz") + File.binread("#{gem_repo2}/specs.4.8.gz") end get "/extra/prerelease_specs.4.8.gz" do - File.read("#{gem_repo2}/prerelease_specs.4.8.gz") + File.binread("#{gem_repo2}/prerelease_specs.4.8.gz") end get "/extra/quick/Marshal.4.8/:id" do @@ -26,11 +26,11 @@ class CompactIndexExtra < CompactIndexAPI end get "/extra/fetch/actual/gem/:id" do - File.read("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") + File.binread("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") end get "/extra/gems/:id" do - File.read("#{gem_repo2}/gems/#{params[:id]}") + File.binread("#{gem_repo2}/gems/#{params[:id]}") end end diff --git a/spec/bundler/support/artifice/compact_index_extra_api.rb b/spec/bundler/support/artifice/compact_index_extra_api.rb index 3c716763c0..5cc13421a8 100644 --- a/spec/bundler/support/artifice/compact_index_extra_api.rb +++ b/spec/bundler/support/artifice/compact_index_extra_api.rb @@ -14,7 +14,7 @@ class CompactIndexExtraApi < CompactIndexAPI get "/extra/versions" do etag_response do file = tmp("versions.list") - file.delete if file.file? + FileUtils.rm_f(file) file = CompactIndex::VersionsFile.new(file.to_s) file.create(gems(gem_repo4)) file.contents @@ -29,11 +29,11 @@ class CompactIndexExtraApi < CompactIndexAPI end get "/extra/specs.4.8.gz" do - File.read("#{gem_repo4}/specs.4.8.gz") + File.binread("#{gem_repo4}/specs.4.8.gz") end get "/extra/prerelease_specs.4.8.gz" do - File.read("#{gem_repo4}/prerelease_specs.4.8.gz") + File.binread("#{gem_repo4}/prerelease_specs.4.8.gz") end get "/extra/quick/Marshal.4.8/:id" do @@ -41,11 +41,11 @@ class CompactIndexExtraApi < CompactIndexAPI end get "/extra/fetch/actual/gem/:id" do - File.read("#{gem_repo4}/quick/Marshal.4.8/#{params[:id]}") + File.binread("#{gem_repo4}/quick/Marshal.4.8/#{params[:id]}") end get "/extra/gems/:id" do - File.read("#{gem_repo4}/gems/#{params[:id]}") + File.binread("#{gem_repo4}/gems/#{params[:id]}") end end diff --git a/spec/bundler/support/artifice/compact_index_partial_update.rb b/spec/bundler/support/artifice/compact_index_partial_update.rb index 6e7c05d423..cb1c7b9481 100644 --- a/spec/bundler/support/artifice/compact_index_partial_update.rb +++ b/spec/bundler/support/artifice/compact_index_partial_update.rb @@ -18,19 +18,19 @@ class CompactIndexPartialUpdate < CompactIndexAPI ) # Verify a cached copy of the versions file exists - unless File.read(cached_versions_path).start_with?("created_at: ") + unless File.binread(cached_versions_path).start_with?("created_at: ") raise("Cached versions file should be present and have content") end # Verify that a partial request is made, starting from the index of the # final byte of the cached file. - unless env["HTTP_RANGE"] == "bytes=#{File.read(cached_versions_path).bytesize - 1}-" + unless env["HTTP_RANGE"] == "bytes=#{File.binread(cached_versions_path).bytesize - 1}-" raise("Range header should be present, and start from the index of the final byte of the cache.") end etag_response do # Return the exact contents of the cache. - File.read(cached_versions_path) + File.binread(cached_versions_path) end end end diff --git a/spec/bundler/support/artifice/compact_index_range_not_satisfiable.rb b/spec/bundler/support/artifice/compact_index_range_not_satisfiable.rb index 788f9d6f99..bb616125bb 100644 --- a/spec/bundler/support/artifice/compact_index_range_not_satisfiable.rb +++ b/spec/bundler/support/artifice/compact_index_range_not_satisfiable.rb @@ -11,7 +11,7 @@ class CompactIndexRangeNotSatisfiable < CompactIndexAPI else etag_response do file = tmp("versions.list") - file.delete if file.file? + FileUtils.rm_f(file) file = CompactIndex::VersionsFile.new(file.to_s) file.create(gems) file.contents diff --git a/spec/bundler/support/artifice/endpoint.rb b/spec/bundler/support/artifice/endpoint.rb index 7f4cafc239..3ed9a3f0f7 100644 --- a/spec/bundler/support/artifice/endpoint.rb +++ b/spec/bundler/support/artifice/endpoint.rb @@ -77,11 +77,11 @@ class Endpoint < Sinatra::Base end get "/fetch/actual/gem/:id" do - File.read("#{GEM_REPO}/quick/Marshal.4.8/#{params[:id]}") + File.binread("#{GEM_REPO}/quick/Marshal.4.8/#{params[:id]}") end get "/gems/:id" do - File.read("#{GEM_REPO}/gems/#{params[:id]}") + File.binread("#{GEM_REPO}/gems/#{params[:id]}") end get "/api/v1/dependencies" do @@ -89,11 +89,11 @@ class Endpoint < Sinatra::Base end get "/specs.4.8.gz" do - File.read("#{GEM_REPO}/specs.4.8.gz") + File.binread("#{GEM_REPO}/specs.4.8.gz") end get "/prerelease_specs.4.8.gz" do - File.read("#{GEM_REPO}/prerelease_specs.4.8.gz") + File.binread("#{GEM_REPO}/prerelease_specs.4.8.gz") end end diff --git a/spec/bundler/support/artifice/endpoint_creds_diff_host.rb b/spec/bundler/support/artifice/endpoint_creds_diff_host.rb index f20ef74ac6..8b8972cedd 100644 --- a/spec/bundler/support/artifice/endpoint_creds_diff_host.rb +++ b/spec/bundler/support/artifice/endpoint_creds_diff_host.rb @@ -31,7 +31,7 @@ class EndpointCredsDiffHost < Endpoint get "/no/creds/:id" do if request.host.include?("diffhost") && !auth.provided? - File.read("#{gem_repo1}/gems/#{params[:id]}") + File.binread("#{gem_repo1}/gems/#{params[:id]}") end end end diff --git a/spec/bundler/support/artifice/endpoint_extra.rb b/spec/bundler/support/artifice/endpoint_extra.rb index 31f6822161..942c4352b7 100644 --- a/spec/bundler/support/artifice/endpoint_extra.rb +++ b/spec/bundler/support/artifice/endpoint_extra.rb @@ -10,11 +10,11 @@ class EndpointExtra < Endpoint end get "/extra/specs.4.8.gz" do - File.read("#{gem_repo2}/specs.4.8.gz") + File.binread("#{gem_repo2}/specs.4.8.gz") end get "/extra/prerelease_specs.4.8.gz" do - File.read("#{gem_repo2}/prerelease_specs.4.8.gz") + File.binread("#{gem_repo2}/prerelease_specs.4.8.gz") end get "/extra/quick/Marshal.4.8/:id" do @@ -22,11 +22,11 @@ class EndpointExtra < Endpoint end get "/extra/fetch/actual/gem/:id" do - File.read("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") + File.binread("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") end get "/extra/gems/:id" do - File.read("#{gem_repo2}/gems/#{params[:id]}") + File.binread("#{gem_repo2}/gems/#{params[:id]}") end end diff --git a/spec/bundler/support/artifice/endpoint_extra_api.rb b/spec/bundler/support/artifice/endpoint_extra_api.rb index 213b8e5895..1cfef7a7fc 100644 --- a/spec/bundler/support/artifice/endpoint_extra_api.rb +++ b/spec/bundler/support/artifice/endpoint_extra_api.rb @@ -11,11 +11,11 @@ class EndpointExtraApi < Endpoint end get "/extra/specs.4.8.gz" do - File.read("#{gem_repo4}/specs.4.8.gz") + File.binread("#{gem_repo4}/specs.4.8.gz") end get "/extra/prerelease_specs.4.8.gz" do - File.read("#{gem_repo4}/prerelease_specs.4.8.gz") + File.binread("#{gem_repo4}/prerelease_specs.4.8.gz") end get "/extra/quick/Marshal.4.8/:id" do @@ -23,11 +23,11 @@ class EndpointExtraApi < Endpoint end get "/extra/fetch/actual/gem/:id" do - File.read("#{gem_repo4}/quick/Marshal.4.8/#{params[:id]}") + File.binread("#{gem_repo4}/quick/Marshal.4.8/#{params[:id]}") end get "/extra/gems/:id" do - File.read("#{gem_repo4}/gems/#{params[:id]}") + File.binread("#{gem_repo4}/gems/#{params[:id]}") end end diff --git a/spec/bundler/support/artifice/endpoint_mirror_source.rb b/spec/bundler/support/artifice/endpoint_mirror_source.rb index 318866e420..788a9027f3 100644 --- a/spec/bundler/support/artifice/endpoint_mirror_source.rb +++ b/spec/bundler/support/artifice/endpoint_mirror_source.rb @@ -5,7 +5,7 @@ require_relative "endpoint" class EndpointMirrorSource < Endpoint get "/gems/:id" do if request.env["HTTP_X_GEMFILE_SOURCE"] == "https://server.example.org/" - File.read("#{gem_repo1}/gems/#{params[:id]}") + File.binread("#{gem_repo1}/gems/#{params[:id]}") else halt 500 end diff --git a/spec/bundler/support/artifice/vcr.rb b/spec/bundler/support/artifice/vcr.rb index a46f8e9391..150436f0e3 100644 --- a/spec/bundler/support/artifice/vcr.rb +++ b/spec/bundler/support/artifice/vcr.rb @@ -79,7 +79,7 @@ class BundlerVCRHTTP < Net::HTTP end def read_stored_request(path) - contents = File.read(path) + contents = File.binread(path) headers = {} method = nil path = nil diff --git a/spec/bundler/support/builders.rb b/spec/bundler/support/builders.rb index b3f5f9b876..5ce6e01da3 100644 --- a/spec/bundler/support/builders.rb +++ b/spec/bundler/support/builders.rb @@ -17,6 +17,18 @@ module Spec Gem::Platform.new(platform) end + # Returns a number smaller than the size of the index. Useful for specs that + # need the API request limit to be reached for some reason. + def low_api_request_limit_for(gem_repo) + all_gems = Dir[gem_repo.join("gems/*.gem")] + + all_gem_names = all_gems.map do |file| + File.basename(file, ".gem").match(/\A(?<gem_name>[^-]+)-.*\z/)[:gem_name] + end.uniq + + (all_gem_names - ["bundler"]).size + end + def build_repo1 build_repo gem_repo1 do build_gem "rack", %w[0.9.1 1.0.0] do |s| @@ -40,7 +52,7 @@ module Spec build_gem "rails", "2.3.2" do |s| s.executables = "rails" - s.add_dependency "rake", "12.3.2" + s.add_dependency "rake", "13.0.1" s.add_dependency "actionpack", "2.3.2" s.add_dependency "activerecord", "2.3.2" s.add_dependency "actionmailer", "2.3.2" @@ -302,6 +314,18 @@ module Spec end RUBY end + + build_gem "has_metadata" do |s| + s.metadata = { + "bug_tracker_uri" => "https://example.com/user/bestgemever/issues", + "changelog_uri" => "https://example.com/user/bestgemever/CHANGELOG.md", + "documentation_uri" => "https://www.example.info/gems/bestgemever/0.0.1", + "homepage_uri" => "https://bestgemever.example.io", + "mailing_list_uri" => "https://groups.example.com/bestgemever", + "source_code_uri" => "https://example.com/user/bestgemever", + "wiki_uri" => "https://example.com/user/bestgemever/wiki", + } + end end end @@ -358,8 +382,8 @@ module Spec rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first if rake_path.nil? - Spec::Path.base_system_gems.rmtree - Spec::Rubygems.setup + FileUtils.rm_rf(Path.base_system_gems) + Spec::Rubygems.install_test_deps rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first end @@ -382,7 +406,7 @@ module Spec @_build_repo = File.basename(path) yield with_gem_path_as Path.base_system_gems do - Dir.chdir(path) { gem_command! :generate_index } + gem_command! :generate_index, :dir => path end ensure @_build_path = nil @@ -424,13 +448,13 @@ module Spec opts = args.last.is_a?(Hash) ? args.last : {} builder = opts[:bare] ? GitBareBuilder : GitBuilder spec = build_with(builder, name, args, &block) - GitReader.new(opts[:path] || lib_path(spec.full_name)) + GitReader.new(self, opts[:path] || lib_path(spec.full_name)) end def update_git(name, *args, &block) opts = args.last.is_a?(Hash) ? args.last : {} spec = build_with(GitUpdater, name, args, &block) - GitReader.new(opts[:path] || lib_path(spec.full_name)) + GitReader.new(self, opts[:path] || lib_path(spec.full_name)) end def build_plugin(name, *args, &blk) @@ -451,7 +475,6 @@ module Spec Array(versions).each do |version| spec = builder.new(self, name, version) - spec.authors = ["no one"] if !spec.authors || spec.authors.empty? yield spec if block_given? spec._build(options) end @@ -599,15 +622,6 @@ module Spec def @spec.validate(*); end end - case options[:gemspec] - when false - # do nothing - when :yaml - @files["#{name}.gemspec"] = @spec.to_yaml - else - @files["#{name}.gemspec"] = @spec.to_ruby - end - unless options[:no_default] gem_source = options[:source] || "path@#{path}" @files = _default_files. @@ -616,13 +630,24 @@ module Spec end @spec.authors = ["no one"] + @spec.files = @files.keys + + case options[:gemspec] + when false + # do nothing + when :yaml + @spec.files << "#{name}.gemspec" + @files["#{name}.gemspec"] = @spec.to_yaml + else + @spec.files << "#{name}.gemspec" + @files["#{name}.gemspec"] = @spec.to_ruby + end @files.each do |file, source| file = Pathname.new(path).join(file) FileUtils.mkdir_p(file.dirname) File.open(file, "w") {|f| f.puts source } end - @spec.files = @files.keys path end @@ -648,14 +673,12 @@ module Spec path = options[:path] || _default_path source = options[:source] || "git@#{path}" super(options.merge(:path => path, :source => source)) - Dir.chdir(path) do - `git init` - `git add *` - `git config user.email "[email protected]"` - `git config user.name "lolwut"` - `git config commit.gpgsign false` - `git commit -m "OMG INITIAL COMMIT"` - end + @context.git("init", path) + @context.git("add *", path) + @context.git("config user.email [email protected]", path) + @context.git("config user.name lolwut", path) + @context.git("config commit.gpgsign false", path) + @context.git("commit -m OMG_INITIAL_COMMIT", path) end end @@ -663,91 +686,81 @@ module Spec def _build(options) path = options[:path] || _default_path super(options.merge(:path => path)) - Dir.chdir(path) do - `git init --bare` - end + @context.git("init --bare", path) end end class GitUpdater < LibBuilder - def silently(str) - `#{str} 2>#{Bundler::NULL}` - end - def _build(options) libpath = options[:path] || _default_path update_gemspec = options[:gemspec] || false source = options[:source] || "git@#{libpath}" - Dir.chdir(libpath) do - silently "git checkout master" + @context.git "checkout master", libpath - if branch = options[:branch] - raise "You can't specify `master` as the branch" if branch == "master" - escaped_branch = Shellwords.shellescape(branch) + if branch = options[:branch] + raise "You can't specify `master` as the branch" if branch == "master" + escaped_branch = Shellwords.shellescape(branch) - if `git branch | grep #{escaped_branch}`.empty? - silently("git branch #{escaped_branch}") - end - - silently("git checkout #{escaped_branch}") - elsif tag = options[:tag] - `git tag #{Shellwords.shellescape(tag)}` - elsif options[:remote] - silently("git remote add origin #{options[:remote]}") - elsif options[:push] - silently("git push origin #{options[:push]}") + if @context.git("branch -l #{escaped_branch}", libpath).empty? + @context.git("branch #{escaped_branch}", libpath) end - current_ref = `git rev-parse HEAD`.strip - _default_files.keys.each do |path| - _default_files[path] += "\n#{Builders.constantize(name)}_PREV_REF = '#{current_ref}'" - end - super(options.merge(:path => libpath, :gemspec => update_gemspec, :source => source)) - `git add *` - `git commit -m "BUMP"` + @context.git("checkout #{escaped_branch}", libpath) + elsif tag = options[:tag] + @context.git("tag #{Shellwords.shellescape(tag)}", libpath) + elsif options[:remote] + @context.git("remote add origin #{options[:remote]}", libpath) + elsif options[:push] + @context.git("push origin #{options[:push]}", libpath) end + + current_ref = @context.git("rev-parse HEAD", libpath).strip + _default_files.keys.each do |path| + _default_files[path] += "\n#{Builders.constantize(name)}_PREV_REF = '#{current_ref}'" + end + super(options.merge(:path => libpath, :gemspec => update_gemspec, :source => source)) + @context.git("add *", libpath) + @context.git("commit -m BUMP", libpath) end end class GitReader - attr_reader :path + attr_reader :context, :path - def initialize(path) + def initialize(context, path) + @context = context @path = path end def ref_for(ref, len = nil) - ref = git "rev-parse #{ref}" + ref = context.git "rev-parse #{ref}", path ref = ref[0..len] if len ref end - - private - - def git(cmd) - Bundler::SharedHelpers.with_clean_git_env do - Dir.chdir(@path) { `git #{cmd}`.strip } - end - end end class GemBuilder < LibBuilder def _build(opts) lib_path = super(opts.merge(:path => @context.tmp(".tmp/#{@spec.full_name}"), :no_default => opts[:no_default])) destination = opts[:path] || _default_path - Dir.chdir(lib_path) do - FileUtils.mkdir_p(destination) - - @spec.authors = ["that guy"] if [email protected] || @spec.authors.empty? + FileUtils.mkdir_p(lib_path.join(destination)) - Bundler.rubygems.build(@spec, opts[:skip_validation]) + if opts[:gemspec] == :yaml || opts[:gemspec] == false + Dir.chdir(lib_path) do + Bundler.rubygems.build(@spec, opts[:skip_validation]) + end + elsif opts[:skip_validation] + @context.gem_command "build --force #{@spec.name}", :dir => lib_path + else + @context.gem_command! "build #{@spec.name}", :dir => lib_path end + gem_path = File.expand_path("#{@spec.full_name}.gem", lib_path) if opts[:to_system] @context.system_gems gem_path, :keep_path => true elsif opts[:to_bundle] - @context.system_gems gem_path, :path => :bundle_path, :keep_path => true + @context.system_gems gem_path, :path => @context.default_bundle_path, :keep_path => true else FileUtils.mv(gem_path, destination) end diff --git a/spec/bundler/support/command_execution.rb b/spec/bundler/support/command_execution.rb index b3c289979f..68e5c56c75 100644 --- a/spec/bundler/support/command_execution.rb +++ b/spec/bundler/support/command_execution.rb @@ -3,18 +3,7 @@ module Spec CommandExecution = Struct.new(:command, :working_directory, :exitstatus, :stdout, :stderr) do def to_s - c = Shellwords.shellsplit(command.strip).map {|s| s.include?("\n") ? " \\\n <<EOS\n#{s.gsub(/^/, " ").chomp}\nEOS" : Shellwords.shellescape(s) } - c = c.reduce("") do |acc, elem| - concat = acc + " " + elem - - last_line = concat.match(/.*\z/)[0] - if last_line.size >= 100 - acc + " \\\n " + elem - else - concat - end - end - "$ #{c.strip}" + "$ #{command}" end alias_method :inspect, :to_s diff --git a/spec/bundler/support/filters.rb b/spec/bundler/support/filters.rb index 4ce6648cdc..6322efda8b 100644 --- a/spec/bundler/support/filters.rb +++ b/spec/bundler/support/filters.rb @@ -21,17 +21,8 @@ class RequirementChecker < Proc end RSpec.configure do |config| - if ENV["BUNDLER_SUDO_TESTS"] && Spec::Sudo.present? - config.filter_run :sudo => true - else - config.filter_run_excluding :sudo => true - end - - if ENV["BUNDLER_REALWORLD_TESTS"] - config.filter_run :realworld => true - else - config.filter_run_excluding :realworld => true - end + config.filter_run_excluding :sudo => true + config.filter_run_excluding :realworld => true git_version = Bundler::Source::Git::GitProxy.new(nil, nil, nil).version @@ -40,6 +31,9 @@ RSpec.configure do |config| config.filter_run_excluding :bundler => RequirementChecker.against(Bundler::VERSION.split(".")[0]) config.filter_run_excluding :ruby_repo => !ENV["GEM_COMMAND"].nil? config.filter_run_excluding :no_color_tty => Gem.win_platform? || !ENV["GITHUB_ACTION"].nil? + config.filter_run_excluding :permissions => Gem.win_platform? + config.filter_run_excluding :readline => Gem.win_platform? + config.filter_run_excluding :jruby => RUBY_PLATFORM != "java" config.filter_run_when_matching :focus unless ENV["CI"] end diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb index c18470acd2..4b5c5dd94c 100644 --- a/spec/bundler/support/hax.rb +++ b/spec/bundler/support/hax.rb @@ -9,11 +9,6 @@ module Gem Gem.ruby = ENV["RUBY"] end - if version = ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] - remove_const(:VERSION) if const_defined?(:VERSION) - VERSION = version - end - class Platform @local = new(ENV["BUNDLER_SPEC_PLATFORM"]) if ENV["BUNDLER_SPEC_PLATFORM"] end @@ -27,16 +22,6 @@ module Gem end end -if ENV["BUNDLER_SPEC_VERSION"] - require_relative "path" - require "#{Spec::Path.lib_dir}/bundler/version" - - module Bundler - remove_const(:VERSION) if const_defined?(:VERSION) - VERSION = ENV["BUNDLER_SPEC_VERSION"].dup - end -end - if ENV["BUNDLER_SPEC_WINDOWS"] == "true" require_relative "path" require "#{Spec::Path.lib_dir}/bundler/constants" @@ -47,22 +32,17 @@ if ENV["BUNDLER_SPEC_WINDOWS"] == "true" end end -class Object - if ENV["BUNDLER_SPEC_RUBY_ENGINE"] - if RUBY_ENGINE != "jruby" && ENV["BUNDLER_SPEC_RUBY_ENGINE"] == "jruby" - begin - # this has to be done up front because psych will try to load a .jar - # if it thinks its on jruby - require "psych" - rescue LoadError - nil +if ENV["BUNDLER_SPEC_API_REQUEST_LIMIT"] + require_relative "path" + require "#{Spec::Path.lib_dir}/bundler/source" + require "#{Spec::Path.lib_dir}/bundler/source/rubygems" + + module Bundler + class Source + class Rubygems < Source + remove_const :API_REQUEST_LIMIT + API_REQUEST_LIMIT = ENV["BUNDLER_SPEC_API_REQUEST_LIMIT"].to_i end end - - remove_const :RUBY_ENGINE - RUBY_ENGINE = ENV["BUNDLER_SPEC_RUBY_ENGINE"] - - remove_const :RUBY_ENGINE_VERSION - RUBY_ENGINE_VERSION = ENV["BUNDLER_SPEC_RUBY_ENGINE_VERSION"] end end diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index e9c9e766cf..7ef32a5e8e 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -8,11 +8,7 @@ module Spec def reset! Dir.glob("#{tmp}/{gems/*,*}", File::FNM_DOTMATCH).each do |dir| next if %w[base remote1 gems rubygems . ..].include?(File.basename(dir)) - if ENV["BUNDLER_SUDO_TESTS"] - `sudo rm -rf "#{dir}"` - else - FileUtils.rm_rf(dir) - end + FileUtils.rm_rf(dir) end FileUtils.mkdir_p(home) FileUtils.mkdir_p(tmpdir) @@ -59,23 +55,11 @@ module Spec last_command.exitstatus end - def in_app_root(&blk) - Dir.chdir(bundled_app, &blk) - end - - def in_app_root2(&blk) - Dir.chdir(bundled_app2, &blk) - end - - def in_app_root_custom(root, &blk) - Dir.chdir(root, &blk) - end - def run(cmd, *args) opts = args.last.is_a?(Hash) ? args.pop : {} groups = args.map(&:inspect).join(", ") - setup = "require '#{lib_dir}/bundler' ; Bundler.ui.silence { Bundler.setup(#{groups}) }\n" - ruby(setup + cmd, opts) + setup = "require '#{lib_dir}/bundler' ; Bundler.ui.silence { Bundler.setup(#{groups}) }" + ruby([setup, cmd].join(" ; "), opts) end bang :run @@ -84,7 +68,7 @@ module Spec begin #{ruby} rescue LoadError => e - $stderr.puts "ZOMG LOAD ERROR" if e.message.include?("-- #{name}") + warn "ZOMG LOAD ERROR" if e.message.include?("-- #{name}") end RUBY opts = args.last.is_a?(Hash) ? args.pop : {} @@ -92,9 +76,9 @@ module Spec run(cmd, *args) end - def bundle(cmd, options = {}) + def bundle(cmd, options = {}, &block) with_sudo = options.delete(:sudo) - sudo = with_sudo == :preserve_env ? "sudo -E" : "sudo" if with_sudo + sudo = with_sudo == :preserve_env ? "sudo -E --preserve-env=RUBYOPT" : "sudo" if with_sudo bundle_bin = options.delete("bundle_bin") || bindir.join("bundle") @@ -106,7 +90,6 @@ module Spec env["PATH"].gsub!("#{Path.root}/exe", "") if env["PATH"] && system_bundler requires = options.delete(:requires) || [] - requires << "support/hax" artifice = options.delete(:artifice) do if RSpec.current_example.metadata[:realworld] @@ -116,15 +99,14 @@ module Spec end end if artifice - requires << "support/artifice/#{artifice}" + requires << "#{Path.spec_dir}/support/artifice/#{artifice}.rb" end - requires_str = requires.map {|r| "-r#{r}" }.join(" ") - load_path = [] load_path << lib_dir unless system_bundler load_path << spec_dir - load_path_str = "-I#{load_path.join(File::PATH_SEPARATOR)}" + + dir = options.delete(:dir) || bundled_app args = options.map do |k, v| case v @@ -139,8 +121,9 @@ module Spec end end.join - cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" - sys_exec(cmd, env) {|i, o, thr| yield i, o, thr if block_given? } + ruby_cmd = build_ruby_cmd({ :sudo => sudo, :load_path => load_path, :requires => requires }) + cmd = "#{ruby_cmd} #{bundle_bin} #{cmd}#{args}" + sys_exec(cmd, { :env => env, :dir => dir }, &block) end bang :bundle @@ -167,10 +150,9 @@ module Spec end def ruby(ruby, options = {}) - env = options.delete(:env) || {} - ruby = ruby.gsub(/["`\$]/) {|m| "\\#{m}" } - lib_option = options[:no_lib] ? "" : " -I#{lib_dir}" - sys_exec(%(#{Gem.ruby}#{lib_option} -w -e "#{ruby}"), env) + ruby_cmd = build_ruby_cmd({ :load_path => options[:no_lib] ? [] : [lib_dir] }) + escaped_ruby = RUBY_PLATFORM == "java" ? ruby.shellescape.dump : ruby.shellescape + sys_exec(%(#{ruby_cmd} -w -e #{escaped_ruby}), options) end bang :ruby @@ -179,22 +161,35 @@ module Spec begin #{ruby} rescue LoadError => e - $stderr.puts "ZOMG LOAD ERROR"# if e.message.include?("-- #{name}") + warn "ZOMG LOAD ERROR" if e.message.include?("-- #{name}") end R end - def gembin(cmd) + def build_ruby_cmd(options = {}) + sudo = options.delete(:sudo) + + libs = options.delete(:load_path) || [] + lib_option = "-I#{libs.join(File::PATH_SEPARATOR)}" + + requires = options.delete(:requires) || [] + requires << "#{Path.spec_dir}/support/hax.rb" + require_option = requires.map {|r| "-r#{r}" } + + [sudo, Gem.ruby, *lib_option, *require_option].compact.join(" ") + end + + def gembin(cmd, options = {}) old = ENV["RUBYOPT"] ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{lib_dir}" cmd = bundled_app("bin/#{cmd}") unless cmd.to_s.include?("/") - sys_exec(cmd.to_s) + sys_exec(cmd.to_s, options) ensure ENV["RUBYOPT"] = old end - def gem_command(command, args = "") - sys_exec("#{Path.gem_bin} #{command} #{args}") + def gem_command(command, options = {}) + sys_exec("#{Path.gem_bin} #{command}", options) end bang :gem_command @@ -202,11 +197,19 @@ module Spec "#{Gem.ruby} -S #{ENV["GEM_PATH"]}/bin/rake" end - def sys_exec(cmd, env = {}) - command_execution = CommandExecution.new(cmd.to_s, Dir.pwd) + def git(cmd, path) + sys_exec("git #{cmd}", :dir => path) + end + + def sys_exec(cmd, options = {}) + env = options[:env] || {} + env["RUBYOPT"] = opt_add("-r#{spec_dir}/support/switch_rubygems.rb", env["RUBYOPT"] || ENV["RUBYOPT"]) + dir = options[:dir] || bundled_app + command_execution = CommandExecution.new(cmd.to_s, dir) require "open3" - Open3.popen3(env, cmd.to_s) do |stdin, stdout, stderr, wait_thr| + require "shellwords" + Open3.popen3(env, *cmd.shellsplit, :chdir => dir) do |stdin, stdout, stderr, wait_thr| yield stdin, stdout, wait_thr if block_given? stdin.close @@ -250,7 +253,7 @@ module Spec contents = args.shift if contents.nil? - File.open("Gemfile", "r", &:read) + File.open(bundled_app_gemfile, "r", &:read) else create_file("Gemfile", contents, *args) end @@ -260,7 +263,7 @@ module Spec contents = args.shift if contents.nil? - File.open("Gemfile.lock", "r", &:read) + File.open(bundled_app_lock, "r", &:read) else create_file("Gemfile.lock", contents, *args) end @@ -291,12 +294,14 @@ module Spec options = gems.last.is_a?(Hash) ? gems.pop : {} gem_repo = options.fetch(:gem_repo) { gem_repo1 } gems.each do |g| - if g == :bundler - with_built_bundler {|gem_path| install_gem(gem_path) } - elsif g.to_s =~ %r{\A(?:[A-Z]:)?/.*\.gem\z} - install_gem(g) + gem_name = g.to_s + if gem_name.start_with?("bundler") + version = gem_name.match(/\Abundler-(?<version>.*)\z/)[:version] if gem_name != "bundler" + with_built_bundler(version) {|gem_path| install_gem(gem_path) } + elsif gem_name =~ %r{\A(?:[a-zA-Z]:)?/.*\.gem\z} + install_gem(gem_name) else - install_gem("#{gem_repo}/gems/#{g}.gem") + install_gem("#{gem_repo}/gems/#{gem_name}.gem") end end end @@ -304,20 +309,32 @@ module Spec def install_gem(path) raise "OMG `#{path}` does not exist!" unless File.exist?(path) - gem_command! :install, "--no-document --ignore-dependencies '#{path}'" + gem_command! "install --no-document --ignore-dependencies '#{path}'" end - def with_built_bundler - with_root_gemspec do |gemspec| - Dir.chdir(root) { gem_command! :build, gemspec.to_s } - end + def with_built_bundler(version = nil) + version ||= Bundler::VERSION + full_name = "bundler-#{version}" + build_path = tmp + full_name + bundler_path = build_path + "#{full_name}.gem" - bundler_path = root + "bundler-#{Bundler::VERSION}.gem" + Dir.mkdir build_path begin + shipped_files.each do |shipped_file| + target_shipped_file = build_path + shipped_file + target_shipped_dir = File.dirname(target_shipped_file) + FileUtils.mkdir_p target_shipped_dir unless File.directory?(target_shipped_dir) + FileUtils.cp shipped_file, target_shipped_file, :preserve => true + end + + replace_version_file(version, dir: build_path) # rubocop:disable Style/HashSyntax + + gem_command! "build bundler.gemspec", :dir => build_path + yield(bundler_path) ensure - bundler_path.rmtree + build_path.rmtree end end @@ -346,6 +363,16 @@ module Spec end end + def opt_add(option, options) + [option.strip, options].compact.reject(&:empty?).join(" ") + end + + def opt_remove(option, options) + return unless options + + options.split(" ").reject {|opt| opt.strip == option.strip }.join(" ") + end + def break_git! FileUtils.mkdir_p(tmp("broken_path")) File.open(tmp("broken_path/git"), "w", 0o755) do |f| @@ -356,6 +383,8 @@ module Spec end def with_fake_man + skip "fake_man is not a Windows friendly binstub" if Gem.win_platform? + FileUtils.mkdir_p(tmp("fake_man")) File.open(tmp("fake_man/man"), "w", 0o755) do |f| f.puts "#!/usr/bin/env ruby\nputs ARGV.inspect\n" @@ -366,18 +395,6 @@ module Spec def system_gems(*gems) opts = gems.last.is_a?(Hash) ? gems.last : {} path = opts.fetch(:path, system_gem_path) - if path == :bundle_path - path = ruby!(<<-RUBY) - require "bundler" - begin - puts Bundler.bundle_path - rescue Bundler::GemfileNotFound - ENV["BUNDLE_GEMFILE"] = "Gemfile" - retry - end - - RUBY - end gems = gems.flatten unless opts[:keep_path] @@ -416,7 +433,7 @@ module Spec ENV["GEM_PATH"] = system_gem_path.to_s gems.each do |gem| - gem_command! :install, "--no-document #{gem}" + gem_command! "install --no-document #{gem}" end return unless block_given? begin @@ -464,35 +481,6 @@ module Spec ENV["BUNDLER_SPEC_RUBY_VERSION"] = old if block_given? end - def simulate_ruby_engine(engine, version = "1.6.0") - return if engine == local_ruby_engine - - old = ENV["BUNDLER_SPEC_RUBY_ENGINE"] - ENV["BUNDLER_SPEC_RUBY_ENGINE"] = engine - old_version = ENV["BUNDLER_SPEC_RUBY_ENGINE_VERSION"] - ENV["BUNDLER_SPEC_RUBY_ENGINE_VERSION"] = version - yield if block_given? - ensure - ENV["BUNDLER_SPEC_RUBY_ENGINE"] = old if block_given? - ENV["BUNDLER_SPEC_RUBY_ENGINE_VERSION"] = old_version if block_given? - end - - def simulate_bundler_version(version) - old = ENV["BUNDLER_SPEC_VERSION"] - ENV["BUNDLER_SPEC_VERSION"] = version.to_s - yield if block_given? - ensure - ENV["BUNDLER_SPEC_VERSION"] = old if block_given? - end - - def simulate_rubygems_version(version) - old = ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] - ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] = version.to_s - yield if block_given? - ensure - ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] = old if block_given? - end - def simulate_windows(platform = mswin) old = ENV["BUNDLER_SPEC_WINDOWS"] ENV["BUNDLER_SPEC_WINDOWS"] = "true" @@ -504,7 +492,7 @@ module Spec end def revision_for(path) - Dir.chdir(path) { `git rev-parse HEAD`.strip } + sys_exec("git rev-parse HEAD", :dir => path).strip end def with_read_only(pattern) diff --git a/spec/bundler/support/indexes.rb b/spec/bundler/support/indexes.rb index dc6e0bd1e9..7440523fc9 100644 --- a/spec/bundler/support/indexes.rb +++ b/spec/bundler/support/indexes.rb @@ -26,6 +26,10 @@ module Spec end end source_requirements ||= {} + args[0] ||= [] # base + args[1] ||= Bundler::GemVersionPromoter.new # gem_version_promoter + args[2] ||= [] # additional_base_requirements + args[3] ||= @platforms # platforms Bundler::Resolver.resolve(deps, @index, source_requirements, *args) end diff --git a/spec/bundler/support/matchers.rb b/spec/bundler/support/matchers.rb index df35854c2f..e6275064a8 100644 --- a/spec/bundler/support/matchers.rb +++ b/spec/bundler/support/matchers.rb @@ -75,16 +75,6 @@ module Spec end end - RSpec::Matchers.define :have_rubyopts do |*args| - args = args.flatten - args = args.first.split(/\s+/) if args.size == 1 - - match do |actual| - actual = actual.split(/\s+/) if actual.is_a?(String) - args.all? {|arg| actual.include?(arg) } && actual.uniq.size == actual.size - end - end - RSpec::Matchers.define :be_sorted do diffable attr_reader :expected @@ -214,11 +204,11 @@ module Spec end def lockfile_should_be(expected) - expect(bundled_app("Gemfile.lock")).to have_lockfile(expected) + expect(bundled_app_lock).to have_lockfile(expected) end def gemfile_should_be(expected) - expect(bundled_app("Gemfile")).to read_as(strip_whitespace(expected)) + expect(bundled_app_gemfile).to read_as(strip_whitespace(expected)) end end end diff --git a/spec/bundler/support/parallel.rb b/spec/bundler/support/parallel.rb deleted file mode 100644 index 8763cb9ec4..0000000000 --- a/spec/bundler/support/parallel.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -RSpec.configure do |config| - config.silence_filter_announcements = true -end diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb index 645da52c97..b851fa389a 100644 --- a/spec/bundler/support/path.rb +++ b/spec/bundler/support/path.rb @@ -34,21 +34,19 @@ module Spec end def tracked_files - skip "not in git working directory" unless git_root_dir? - - @tracked_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb spec/bundler man/bundler*` : `git ls-files -z` + @tracked_files ||= sys_exec(ruby_core? ? "git ls-files -z -- lib/bundler lib/bundler.rb spec/bundler man/bundler*" : "git ls-files -z", :dir => root).split("\x0") end def shipped_files - skip "not in git working directory" unless git_root_dir? - - @shipped_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb man/bundler* libexec/bundle*` : `git ls-files -z -- lib man exe CHANGELOG.md LICENSE.md README.md bundler.gemspec` + @shipped_files ||= sys_exec(ruby_core? ? "git ls-files -z -- lib/bundler lib/bundler.rb man/bundler* libexec/bundle*" : "git ls-files -z -- lib man exe CHANGELOG.md LICENSE.md README.md bundler.gemspec", :dir => root).split("\x0") end def lib_tracked_files - skip "not in git working directory" unless git_root_dir? + @lib_tracked_files ||= sys_exec(ruby_core? ? "git ls-files -z -- lib/bundler lib/bundler.rb" : "git ls-files -z -- lib", :dir => root).split("\x0") + end - @lib_tracked_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb` : `git ls-files -z -- lib` + def man_tracked_files + @man_tracked_files ||= sys_exec(ruby_core? ? "git ls-files -z -- man/bundler*" : "git ls-files -z -- man", :dir => root).split("\x0") end def tmp(*path) @@ -67,10 +65,10 @@ module Spec end def default_bundle_path(*path) - if Bundler::VERSION.split(".").first.to_i < 3 - system_gem_path(*path) + if Bundler.feature_flag.default_install_uses_path? + local_gem_path(*path) else - bundled_app(*[".bundle", ENV.fetch("BUNDLER_SPEC_RUBY_ENGINE", Gem.ruby_engine), RbConfig::CONFIG["ruby_version"], *path].compact) + system_gem_path(*path) end end @@ -80,8 +78,6 @@ module Spec root.join(*path) end - alias_method :bundled_app1, :bundled_app - def bundled_app2(*path) root = tmp.join("bundled_app2") FileUtils.mkdir_p(root) @@ -96,6 +92,14 @@ module Spec bundled_app("vendor/cache/#{path}.gem") end + def bundled_app_gemfile + bundled_app("Gemfile") + end + + def bundled_app_lock + bundled_app("Gemfile.lock") + end + def base_system_gems tmp.join("gems/base") end @@ -135,6 +139,10 @@ module Spec tmp("gems/system", *path) end + def local_gem_path(*path, base: bundled_app) + base.join(*[".bundle", Gem.ruby_engine, RbConfig::CONFIG["ruby_version"], *path].compact) + end + def lib_path(*args) tmp("libs", *args) end @@ -155,18 +163,11 @@ module Spec tmp "tmpdir", *args end - def with_root_gemspec - if ruby_core? - root_gemspec = root.join("bundler.gemspec") - # Dir.chdir(root) for Dir.glob in gemspec - spec = Dir.chdir(root) { Gem::Specification.load(gemspec.to_s) } - spec.bindir = "libexec" - File.open(root_gemspec.to_s, "w") {|f| f.write spec.to_ruby } - yield(root_gemspec) - FileUtils.rm(root_gemspec) - else - yield(gemspec) - end + def replace_version_file(version, dir: root) + version_file = File.expand_path("lib/bundler/version.rb", dir) + contents = File.read(version_file) + contents.sub!(/(^\s+VERSION\s*=\s*)"#{Gem::Version::VERSION_PATTERN}"/, %(\\1"#{version}")) + File.open(version_file, "w") {|f| f << contents } end def ruby_core? @@ -181,11 +182,5 @@ module Spec end extend self - - private - - def git_root_dir? - root.to_s == `git rev-parse --show-toplevel`.chomp - end end end diff --git a/spec/bundler/support/platforms.rb b/spec/bundler/support/platforms.rb index f4d63c8ded..a6ebd7510f 100644 --- a/spec/bundler/support/platforms.rb +++ b/spec/bundler/support/platforms.rb @@ -65,12 +65,10 @@ module Spec end def local_ruby_engine - ENV["BUNDLER_SPEC_RUBY_ENGINE"] || RUBY_ENGINE + RUBY_ENGINE end def local_engine_version - return ENV["BUNDLER_SPEC_RUBY_ENGINE_VERSION"] if ENV["BUNDLER_SPEC_RUBY_ENGINE_VERSION"] - RUBY_ENGINE_VERSION end diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb index ee9c750a52..03c47ce57c 100644 --- a/spec/bundler/support/rubygems_ext.rb +++ b/spec/bundler/support/rubygems_ext.rb @@ -2,45 +2,18 @@ require_relative "path" +$LOAD_PATH.unshift(Spec::Path.lib_dir.to_s) + module Spec module Rubygems - DEV_DEPS = { - "automatiek" => "~> 0.3.0", - "parallel_tests" => "~> 2.29", - "rake" => "~> 12.0", - "ronn" => "~> 0.7.3", - "rspec" => "~> 3.8", - "rubocop" => "= 0.77.0", - "rubocop-performance" => "= 1.5.1", - }.freeze - - DEPS = { - "rack" => "~> 2.0", - "rack-test" => "~> 1.1", - "artifice" => "~> 0.6.0", - "compact_index" => "~> 0.11.0", - "sinatra" => "~> 2.0", - # Rake version has to be consistent for tests to pass - "rake" => "12.3.2", - "builder" => "~> 3.2", - # ruby-graphviz is used by the viz tests - "ruby-graphviz" => ">= 0.a", - }.freeze - extend self def dev_setup - deps = DEV_DEPS - - # JRuby can't build ronn, so we skip that - deps.delete("ronn") if RUBY_ENGINE == "jruby" - - install_gems(deps) + install_gems(dev_gemfile, dev_lockfile) end def gem_load(gem_name, bin_container) - require_relative "rubygems_version_manager" - RubygemsVersionManager.new(ENV["RGV"]).switch + require_relative "switch_rubygems" gem_load_and_activate(gem_name, bin_container) end @@ -50,25 +23,10 @@ module Spec require gem_name end - def setup - require "fileutils" - - Gem.clear_paths - - ENV["BUNDLE_PATH"] = nil - ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gems.to_s - ENV["PATH"] = [Path.bindir, Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR) + def test_setup + setup_test_paths - manifest = DEPS.to_a.sort_by(&:first).map {|k, v| "#{k} => #{v}\n" } - manifest_path = Path.base_system_gems.join("manifest.txt") - # it's OK if there are extra gems - if !manifest_path.file? || !(manifest - manifest_path.readlines).empty? - FileUtils.rm_rf(Path.base_system_gems) - FileUtils.mkdir_p(Path.base_system_gems) - puts "installing gems for the tests to use..." - install_gems(DEPS) - manifest_path.open("wb") {|f| f << manifest.join } - end + require "fileutils" FileUtils.mkdir_p(Path.home) FileUtils.mkdir_p(Path.tmpdir) @@ -80,8 +38,52 @@ module Spec Gem::DefaultUserInteraction.ui = Gem::SilentUI.new end + def install_parallel_test_deps + require "parallel" + + prev_env_test_number = ENV["TEST_ENV_NUMBER"] + + begin + Parallel.processor_count.times do |n| + ENV["TEST_ENV_NUMBER"] = (n + 1).to_s + + install_test_deps + end + ensure + ENV["TEST_ENV_NUMBER"] = prev_env_test_number + end + end + + def setup_test_paths + Gem.clear_paths + + ENV["BUNDLE_PATH"] = nil + ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gems.to_s + ENV["PATH"] = [Path.bindir, Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR) + end + + def install_test_deps + setup_test_paths + + workaround_loaded_specs_issue + + install_gems(test_gemfile, test_lockfile) + end + private + # Some rubygems versions include loaded specs when loading gemspec stubs + # from the file system. In this situation, that makes bundler incorrectly + # assume that `rake` is already installed at `tmp/` because it's installed + # globally, and makes it skip installing it to the proper location for our + # tests. To workaround, we remove `rake` from the loaded specs when running + # under those versions, so that `bundler` does the right thing. + def workaround_loaded_specs_issue + current_rubygems_version = Gem::Version.new(Gem::VERSION) + + Gem.loaded_specs.delete("rake") if current_rubygems_version >= Gem::Version.new("3.0.0.beta2") && current_rubygems_version < Gem::Version.new("3.2.0") + end + def gem_load_and_activate(gem_name, bin_container) gem_activate(gem_name) load Gem.bin_path(gem_name, bin_container) @@ -90,18 +92,40 @@ module Spec end def gem_activate(gem_name) - gem_requirement = DEV_DEPS[gem_name] + require "bundler" + gem_requirement = Bundler::LockfileParser.new(File.read(dev_lockfile)).dependencies[gem_name]&.requirement gem gem_name, gem_requirement end - def install_gems(gems) - reqs, no_reqs = gems.partition {|_, req| !req.nil? && !req.split(" ").empty? } - no_reqs.map!(&:first) - reqs.map! {|name, req| "'#{name}:#{req}'" } - deps = reqs.concat(no_reqs).join(" ") - gem = ENV["GEM_COMMAND"] || "#{Gem.ruby} -S gem --backtrace" - cmd = "#{gem} install #{deps} --no-document --conservative" - system(cmd) || raise("Installing gems #{deps} for the tests to use failed!") + def install_gems(gemfile, lockfile) + old_gemfile = ENV["BUNDLE_GEMFILE"] + ENV["BUNDLE_GEMFILE"] = gemfile.to_s + require "bundler" + definition = Bundler::Definition.build(gemfile, lockfile, nil) + definition.validate_runtime! + Bundler::Installer.install(Path.root, definition, :path => ENV["GEM_HOME"]) + ensure + ENV["BUNDLE_GEMFILE"] = old_gemfile + end + + def test_gemfile + Path.root.join("test_gems.rb") + end + + def test_lockfile + lockfile_for(test_gemfile) + end + + def dev_gemfile + Path.root.join("dev_gems.rb") + end + + def dev_lockfile + lockfile_for(dev_gemfile) + end + + def lockfile_for(gemfile) + Pathname.new("#{gemfile.expand_path}.lock") end end end diff --git a/spec/bundler/support/rubygems_version_manager.rb b/spec/bundler/support/rubygems_version_manager.rb index 854bce890d..aa4cfc460b 100644 --- a/spec/bundler/support/rubygems_version_manager.rb +++ b/spec/bundler/support/rubygems_version_manager.rb @@ -15,11 +15,34 @@ class RubygemsVersionManager def switch return if use_system? + assert_system_features_not_loaded! + switch_local_copy_if_needed reexec_if_needed end + def assert_system_features_not_loaded! + at_exit do + rubylibdir = RbConfig::CONFIG["rubylibdir"] + + rubygems_path = rubylibdir + "/rubygems" + rubygems_default_path = rubygems_path + "/defaults" + + bundler_path = rubylibdir + "/bundler" + bundler_exemptions = Gem.rubygems_version < Gem::Version.new("3.2.0") ? [bundler_path + "/errors.rb"] : [] + + bad_loaded_features = $LOADED_FEATURES.select do |loaded_feature| + (loaded_feature.start_with?(rubygems_path) && !loaded_feature.start_with?(rubygems_default_path)) || + (loaded_feature.start_with?(bundler_path) && !bundler_exemptions.any? {|bundler_exemption| loaded_feature.start_with?(bundler_exemption) }) + end + + if bad_loaded_features.any? + raise "the following features were incorrectly loaded:\n#{bad_loaded_features.join("\n")}" + end + end + end + private def use_system? @@ -36,7 +59,7 @@ private cmd = [ruby, $0, *ARGV].compact - ENV["RUBYOPT"] = "-I#{local_copy_path.join("lib")} #{ENV["RUBYOPT"]}" + ENV["RUBYOPT"] = opt_add("-I#{local_copy_path.join("lib")}", opt_remove("--disable-gems", ENV["RUBYOPT"])) exec(ENV, *cmd) end @@ -44,10 +67,8 @@ private def switch_local_copy_if_needed return unless local_copy_switch_needed? - Dir.chdir(local_copy_path) do - sys_exec!("git remote update") - sys_exec!("git checkout #{target_tag} --quiet") - end + sys_exec!("git remote update", :dir => local_copy_path) + sys_exec!("git checkout #{target_tag} --quiet", :dir => local_copy_path) ENV["RGV"] = local_copy_path.to_s end @@ -65,9 +86,7 @@ private end def local_copy_tag - Dir.chdir(local_copy_path) do - sys_exec!("git rev-parse --abbrev-ref HEAD") - end + sys_exec!("git rev-parse --abbrev-ref HEAD", :dir => local_copy_path) end def local_copy_path diff --git a/spec/bundler/support/switch_rubygems.rb b/spec/bundler/support/switch_rubygems.rb new file mode 100644 index 0000000000..d3dd685d31 --- /dev/null +++ b/spec/bundler/support/switch_rubygems.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require_relative "rubygems_version_manager" +RubygemsVersionManager.new(ENV["RGV"]).switch + +if ENV["BUNDLER_SPEC_IGNORE_DEFAULT_BUNDLER_GEM"] + module NoBundlerStubs + def default_stubs(pattern = "*.gemspec") + super(pattern).reject {|s| s.name == "bundler" } + end + end + + Gem::Specification.singleton_class.prepend(NoBundlerStubs) +end diff --git a/spec/bundler/update/gemfile_spec.rb b/spec/bundler/update/gemfile_spec.rb index 8c2bd9ccbf..4a902e59e2 100644 --- a/spec/bundler/update/gemfile_spec.rb +++ b/spec/bundler/update/gemfile_spec.rb @@ -38,12 +38,10 @@ RSpec.describe "bundle update" do it "uses the gemfile while in a subdirectory" do bundled_app("subdir").mkpath - Dir.chdir(bundled_app("subdir")) do - bundle! "update", :all => true - bundle "list" + bundle! "update", :all => true, :dir => bundled_app("subdir") + bundle "list", :dir => bundled_app("subdir") - expect(out).to include("rack (1.0.0)") - end + expect(out).to include("rack (1.0.0)") end end end diff --git a/spec/bundler/update/git_spec.rb b/spec/bundler/update/git_spec.rb index 752033c842..71f0e8496a 100644 --- a/spec/bundler/update/git_spec.rb +++ b/spec/bundler/update/git_spec.rb @@ -75,6 +75,8 @@ RSpec.describe "bundle update" do end it "notices when you change the repo url in the Gemfile" do + skip "some of monorepo issues" if Gem.win_platform? + build_git "foo", :path => lib_path("foo_one") build_git "foo", :path => lib_path("foo_two") @@ -131,10 +133,8 @@ RSpec.describe "bundle update" do s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", :dir => lib_path("has_submodule-1.0") + sys_exec "git commit -m \"submodulator\"", :dir => lib_path("has_submodule-1.0") end it "it unlocks the source when submodules are added to a git source" do @@ -183,6 +183,8 @@ RSpec.describe "bundle update" do end it "errors with a message when the .git repo is gone" do + skip "some of monorepo issues" if Gem.win_platform? + build_git "foo", "1.0" install_gemfile <<-G @@ -214,24 +216,15 @@ RSpec.describe "bundle update" do end it "shows the previous version of the gem" do - build_git "rails", "3.0", :path => lib_path("rails") + skip "some of monorepo issues" if Gem.win_platform? + + build_git "rails", "2.3.2", :path => lib_path("rails") install_gemfile <<-G gem "rails", :git => "#{lib_path("rails")}" G - lockfile <<-G - GIT - remote: #{lib_path("rails")} - specs: - rails (2.3.2) - - PLATFORMS - #{generic_local_platform} - - DEPENDENCIES - rails! - G + update_git "rails", "3.0", :path => lib_path("rails"), :gemspec => true bundle "update", :all => true expect(out).to include("Using rails 3.0 (was 2.3.2) from #{lib_path("rails")} (at master@#{revision_for(lib_path("rails"))[0..6]})") @@ -259,14 +252,12 @@ RSpec.describe "bundle update" do bundle "update --source foo" - in_app_root do - run <<-RUBY - require 'foo' - puts "WIN" if defined?(FOO_PREV_REF) - RUBY + run <<-RUBY + require 'foo' + puts "WIN" if defined?(FOO_PREV_REF) + RUBY - expect(out).to eq("WIN") - end + expect(out).to eq("WIN") end it "unlocks gems that were originally pulled in by the source" do |