diff options
author | David Rodríguez <[email protected]> | 2019-08-20 02:46:31 +0200 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2019-08-20 09:46:31 +0900 |
commit | 5a384e2c08704dc7af9d8d3bdfc475eb8c0723aa () | |
tree | c1310eb2766c0f66c1a16d8a5efce7cb1b083944 | |
parent | aa03de8ba13e5ffa7049d3a881d2f5fe70dd4092 (diff) |
Fix some bundler specs (#2380)
* These seem to consistenly pass already * Show actual command when running `make test-bundler` Current the setup command that installs the necessary gems for testing bundler was printed, but not the actual command that runs the tests. That was a bit confusing. * Borrow trick from setproctitle specs * A title that long doesn't get set sometimes No idea why, but the test doesn't need that the title is that long. * Fix most gem helper spec ruby-core failures * Fix the rest of the gem helper failures * Fix version spec by improving the assertion * Remove unnecessary `BUNDLE_RUBY` environment var We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name because bundler considers `BUNDLE_*` variables as settings. * Rename `BUNDLE_GEM` to `GEM_COMMAND` This is more descriptive I think, and also friendlier for bundler because `BUNDLE_` env variables are interpreted by bundler as settings, and this is not a bundler setting. This fixes one bundler spec failure in config specs against ruby-core. * Fix quality spec when run in core Use the proper path helper. * Fix dummy lib builder to never load default gems If a dummy library is named as a default gem, when requiring the library from its executable, the default gem would be loaded when running from core, because in core all default gems share path with bundler, and thus they are always in the $LOAD_PATH. We fix the issue by loading lib relatively inside dummy lib executables. * More exact assertions Sometimes I have the problem that I do some "print debugging" inside specs, and suddently the spec passes. This happens when the assertion is too relaxed, and the things I print make it match, specially when they are simple strings like "1.0" than can be easily be part of gem paths that I print for debugging. I fix this by making a more exact assertion. * Detect the correct shebang when ENV["RUBY"] is set * Relax assertion So that the spec passes even if another paths containing "ext" are in the load path. This works to fix a ruby-core issue, but it's a better assertion in general. We just want to know that the extension path was added. * Use folder structure independent path helper It should fix this spec for ruby-core. * Fix the last failing spec on ruby-core * Skip `bundle open <default_gem>` spec when no default gems
25 files changed, 77 insertions, 61 deletions
@@ -1299,7 +1299,6 @@ RSPECOPTS = --format progress BUNDLER_SPECS = test-bundler: $(TEST_RUNNABLE)-test-bundler yes-test-bundler: yes-test-bundler-prepare - $(gnumake_recursive)$(Q) \ $(XRUBY) -C $(srcdir) -Ispec/bundler .bundle/bin/rspec \ --require spec_helper $(RSPECOPTS) spec/bundler/$(BUNDLER_SPECS) no-test-bundler: @@ -34,14 +34,11 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 2.3.0" s.required_rubygems_version = ">= 2.5.2" - # s.files = Dir.glob("{lib,man,exe}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) } - # Include the CHANGELOG.md, LICENSE.md, README.md manually - # s.files += %w[CHANGELOG.md LICENSE.md README.md] - # include the gemspec itself because warbler breaks w/o it - s.files += %w[bundler.gemspec] - s.bindir = "exe" s.executables = %w[bundle bundler] s.require_paths = ["lib"] end @@ -75,8 +75,8 @@ module Bundler def build_gem file_name = nil - gem = ENV["BUNDLE_GEM"] ? ENV["BUNDLE_GEM"] : "gem" - sh(%W[#{gem} build -V #{spec_path}]) do file_name = File.basename(built_gem_path) SharedHelpers.filesystem_access(File.join(base, "pkg")) {|p| FileUtils.mkdir_p(p) } FileUtils.mv(built_gem_path, "pkg") @@ -87,10 +87,10 @@ module Bundler def install_gem(built_gem_path = nil, local = false) built_gem_path ||= build_gem - gem = ENV["BUNDLE_GEM"] ? ENV["BUNDLE_GEM"] : "gem" - cmd = %W[#{gem} install #{built_gem_path}] - cmd << "--local" if local - out, status = sh_with_status(cmd) unless status.success? && out[/Successfully installed/] raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" end @@ -268,7 +268,7 @@ module Bundler until !File.directory?(current) || current == previous if ENV["BUNDLE_SPEC_RUN"] # avoid stepping above the tmp directory when testing - gemspec = if ENV["BUNDLE_RUBY"] && ENV["BUNDLE_GEM"] # for Ruby Core "lib/bundler/bundler.gemspec" else @@ -15,7 +15,7 @@ RSpec.describe "bundle executable" do it "looks for a binary and executes it if it's named bundler-<task>" do File.open(tmp("bundler-testtasks"), "w", 0o755) do |f| - ruby = ENV["BUNDLE_RUBY"] || "/usr/bin/env ruby" f.puts "#!#{ruby}\nputs 'Hello, world'\n" end @@ -190,11 +190,11 @@ RSpec.describe Bundler::Env do end end - describe ".version_of", :ruby_repo do let(:parsed_version) { described_class.send(:version_of, "ruby") } it "strips version of new line characters" do - expect(parsed_version).to_not include("\n") end end end @@ -50,7 +50,7 @@ RSpec.describe Bundler::GemHelper do end end - context "gem management", :ruby_repo do def mock_confirm_message(message) expect(Bundler.ui).to receive(:confirm).with(message) end @@ -304,7 +304,7 @@ RSpec.describe Bundler::Settings::TCPSocketProbe do server.close unless server.closed? end - it "probes the server correctly", :ruby_repo do with_server_and_mirror do |server, mirror| expect(server.closed?).to be_falsey expect(probe.replies?(mirror)).to be_truthy @@ -389,7 +389,7 @@ E end describe "subcommands" do - it "list", :ruby_repo do bundle! "config list" expect(out).to eq "Settings are listed in order of priority. The top value will be used.\nspec_run\nSet via BUNDLE_SPEC_RUN: \"true\"" @@ -33,7 +33,7 @@ RSpec.describe "bundle exec" do expect(out).to eq("1.0.0") end - it "works when running from a random directory", :ruby_repo do install_gemfile <<-G gem "rack" G @@ -56,14 +56,14 @@ RSpec.describe "bundle exec" do end it "respects custom process title when loading through ruby", :_action_linux do - script_that_changes_its_own_title_and_checks_if_picked_up_by_ps_unix_utility = <<~RUBY - Process.setproctitle("1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16") - puts `ps -eo args | grep [1]-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16` RUBY create_file "Gemfile" create_file "a.rb", script_that_changes_its_own_title_and_checks_if_picked_up_by_ps_unix_utility bundle "exec ruby a.rb" - expect(out).to eq("1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16") end it "accepts --verbose" do @@ -192,7 +192,7 @@ RSpec.describe "bundle exec" do it "uses version specified" do bundle! "exec irb --version" - expect(out).to include(specified_irb_version) expect(err).to be_empty end end @@ -222,7 +222,7 @@ RSpec.describe "bundle exec" do end it "uses resolved version" do - expect(out).to include(indirect_irb_version) expect(err).to be_empty end end @@ -336,7 +336,7 @@ RSpec.describe "bundle exec" do expect(err).to include("bundler: exec needs a command to run") end - it "raises a helpful error when exec'ing to something outside of the bundle", :ruby_repo do bundle! "config set clean false" # want to keep the rackup binstub install_gemfile! <<-G source "#{file_uri_for(gem_repo1)}" @@ -688,7 +688,7 @@ RSpec.describe "bundle exec" do it_behaves_like "it runs" end - context "when the file uses the current ruby shebang", :ruby_repo do let(:shebang) { "#!#{Gem.ruby}" } it_behaves_like "it runs" end @@ -116,7 +116,7 @@ RSpec.describe "bundle info" do end end - context "with a valid regexp for gem name", :ruby_repo do it "presents alternatives" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -210,7 +210,7 @@ RSpec.describe "bundle gem" do end end - it "generates a valid gemspec", :ruby_repo do in_app_root bundle! "gem newgem --bin" @@ -92,8 +92,18 @@ RSpec.describe "bundle open" do end end - context "when opening a default gem", :ruby_repo do before do install_gemfile <<-G gem "json" G @@ -166,7 +166,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do end context "with a valid regexp for gem name" do - it "presents alternatives", :ruby_repo do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "rack" @@ -1110,7 +1110,7 @@ RSpec.describe "bundle install with git sources" do end context "with an extension" do - it "installs the extension", :ruby_repo do build_git "foo" do |s| s.add_dependency "rake" s.extensions << "Rakefile" @@ -1139,7 +1139,7 @@ RSpec.describe "bundle install with git sources" do run! <<-R puts $:.grep(/ext/) R - expect(out).to eq(Pathname.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s) end it "does not use old extension after ref changes", :ruby_repo do @@ -1204,7 +1204,7 @@ In Gemfile: expect(out).not_to include("gem install foo") end - it "does not reinstall the extension", :ruby_repo do build_git "foo" do |s| s.add_dependency "rake" s.extensions << "Rakefile" @@ -1245,7 +1245,7 @@ In Gemfile: expect(out).to eq(installed_time) end - it "does not reinstall the extension when changing another gem", :ruby_repo do build_git "foo" do |s| s.add_dependency "rake" s.extensions << "Rakefile" @@ -1288,7 +1288,7 @@ In Gemfile: expect(out).to eq(installed_time) end - it "does reinstall the extension when changing refs", :ruby_repo do build_git "foo" do |s| s.add_dependency "rake" s.extensions << "Rakefile" @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe "bundle install with install-time dependencies" do - it "installs gems with implicit rake dependencies", :ruby_repo do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "with_implicit_rake_dep" @@ -48,7 +48,7 @@ RSpec.describe "bundle install with install-time dependencies" do expect(the_bundle).to include_gems "net_b 1.0" end - it "installs plugins depended on by other plugins", :ruby_repo do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "net_a" @@ -57,7 +57,7 @@ RSpec.describe "bundle install with install-time dependencies" do expect(the_bundle).to include_gems "net_a 1.0", "net_b 1.0" end - it "installs multiple levels of dependencies", :ruby_repo do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "net_c" @@ -55,11 +55,11 @@ RSpec.describe "La biblioteca si misma" do expect(error_messages.compact).to be_well_formed end - it "mantiene la calidad de lenguaje de oraciones usadas en el código fuente", :ruby_repo do error_messages = [] exempt = /vendor/ Dir.chdir(root) do - `git ls-files -z -- lib`.split("\x0").each do |filename| next if filename =~ exempt error_messages << check_for_expendable_words(filename) error_messages << check_for_specific_pronouns(filename) @@ -230,10 +230,9 @@ RSpec.describe "The library itself" do end end - it "ships the correct set of files", :ruby_repo do Dir.chdir(root) do - git_list = IO.popen("git ls-files -z", &:read).split("\x0").select {|f| f.match(%r{^(lib|man|exe)/}) } - git_list += %w[CHANGELOG.md LICENSE.md README.md bundler.gemspec] gem_list = Gem::Specification.load(gemspec.to_s).files @@ -810,12 +810,12 @@ end end end - it "should not remove itself from the LOAD_PATH and require a different copy of 'bundler/setup'", :ruby_repo do install_gemfile "" ruby <<-R, :env => { "GEM_PATH" => symlinked_gem_home }, :no_lib => true TracePoint.trace(:class) do |tp| - if tp.path.include?("bundler") && !tp.path.start_with?("#{File.expand_path("../..", __dir__)}") puts "OMG. Defining a class from another bundler at \#{tp.path}:\#{tp.lineno}" end end @@ -31,7 +31,7 @@ RSpec.describe "Bundler.with_env helpers" do end end - it "works with nested bundle exec invocations", :ruby_repo do create_file("exe.rb", <<-'RB') count = ARGV.first.to_i exit if count < 0 @@ -70,7 +70,7 @@ RSpec.configure do |config| config.filter_run_excluding :rubygems => RequirementChecker.against(Gem::VERSION) config.filter_run_excluding :git => RequirementChecker.against(git_version) config.filter_run_excluding :bundler => RequirementChecker.against(Bundler::VERSION.split(".")[0]) - config.filter_run_excluding :ruby_repo => !(ENV["BUNDLE_RUBY"] && ENV["BUNDLE_GEM"]).nil? config.filter_run_excluding :no_color_tty => Gem.win_platform? || !ENV["_ACTION"].nil? config.filter_run_excluding :_action_linux => !ENV["_ACTION"].nil? && (ENV["RUNNER_OS"] == "Linux") @@ -88,12 +88,12 @@ RSpec.configure do |config| end config.around :each do |example| - if ENV["BUNDLE_RUBY"] orig_ruby = Gem.ruby - Gem.ruby = ENV["BUNDLE_RUBY"] end example.run - Gem.ruby = orig_ruby if ENV["BUNDLE_RUBY"] end config.before :suite do @@ -108,7 +108,7 @@ RSpec.configure do |config| original_env = ENV.to_hash - if ENV["BUNDLE_RUBY"] FileUtils.cp_r Spec::Path.bindir, File.join(Spec::Path.root, "lib", "exe") end end @@ -139,7 +139,7 @@ RSpec.configure do |config| end config.after :suite do - if ENV["BUNDLE_RUBY"] FileUtils.rm_rf File.join(Spec::Path.root, "lib", "exe") end end @@ -557,7 +557,7 @@ module Spec "#!/usr/bin/env ruby\n" end @spec.files << executable - write executable, "#{shebang}require '#{@name}' ; puts #{Builders.constantize(@name)}" end end @@ -1,6 +1,14 @@ # frozen_string_literal: true module Gem if version = ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] remove_const(:VERSION) if const_defined?(:VERSION) VERSION = version @@ -22,7 +22,7 @@ module Spec end def gem_bin - @gem_bin ||= ruby_core? ? ENV["BUNDLE_GEM"] : "#{Gem.ruby} -S gem --backtrace" end def spec_dir @@ -30,7 +30,11 @@ module Spec end def tracked_files - @tracked_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb spec/bundler` : `git ls-files -z` end def lib_tracked_files @@ -154,7 +158,7 @@ module Spec @ruby_core ||= nil if @ruby_core.nil? - @ruby_core = true & (ENV["BUNDLE_RUBY"] && ENV["BUNDLE_GEM"]) else @ruby_core end @@ -111,8 +111,7 @@ runner = nil unless File.exist?(runner) abs_ruby = runner || File.expand_path(ruby) env["RUBY"] = abs_ruby env["GEM_PATH"] = env["GEM_HOME"] = File.expand_path(".bundle", srcdir) -env["BUNDLE_RUBY"] = abs_ruby -env["BUNDLE_GEM"] = "#{abs_ruby} -rrubygems #{srcdir}/bin/gem --backtrace" env["PATH"] = [File.dirname(abs_ruby), abs_archdir, ENV["PATH"]].compact.join(File::PATH_SEPARATOR) if e = ENV["RUBYLIB"] |