diff options
Diffstat (limited to 'spec/bundler/runtime')
-rw-r--r-- | spec/bundler/runtime/gem_tasks_spec.rb | 24 | ||||
-rw-r--r-- | spec/bundler/runtime/inline_spec.rb | 22 | ||||
-rw-r--r-- | spec/bundler/runtime/setup_spec.rb | 104 |
3 files changed, 90 insertions, 60 deletions
diff --git a/spec/bundler/runtime/gem_tasks_spec.rb b/spec/bundler/runtime/gem_tasks_spec.rb index 4760b6a749..4b92de76bb 100644 --- a/spec/bundler/runtime/gem_tasks_spec.rb +++ b/spec/bundler/runtime/gem_tasks_spec.rb @@ -6,15 +6,25 @@ RSpec.describe "require 'bundler/gem_tasks'" do f.write <<-GEMSPEC Gem::Specification.new do |s| s.name = "foo" + s.version = "1.0" + s.summary = "dummy" + s.author = "Perry Mason" end GEMSPEC end + bundled_app("Rakefile").open("w") do |f| f.write <<-RAKEFILE $:.unshift("#{lib_dir}") require "bundler/gem_tasks" RAKEFILE end + + install_gemfile! <<-G + source "#{file_uri_for(gem_repo1)}" + + gem "rake" + G end it "includes the relevant tasks" do @@ -22,7 +32,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do sys_exec "#{rake} -T", "RUBYOPT" => "-I#{lib_dir}" end - expect(err).to eq("") + expect(err).to be_empty expected_tasks = [ "rake build", "rake clean", @@ -35,6 +45,18 @@ RSpec.describe "require 'bundler/gem_tasks'" do expect(exitstatus).to eq(0) if exitstatus end + 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}" + end + + expect(err).to be_empty + + bundle! "exec rake install" + + expect(err).to be_empty + end + it "adds 'pkg' to rake/clean's CLOBBER" do with_gem_path_as(Spec::Path.base_system_gems.to_s) do sys_exec! %(#{rake} -e 'load "Rakefile"; puts CLOBBER.inspect') diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index 06be2ef83d..94d8b086a2 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -5,7 +5,7 @@ RSpec.describe "bundler/inline#gemfile" do requires = ["#{lib_dir}/bundler/inline"] requires.unshift "#{spec_dir}/support/artifice/" + options.delete(:artifice) if options.key?(:artifice) requires = requires.map {|r| "require '#{r}'" }.join("\n") - @out = ruby("#{requires}\n\n" + code, options) + ruby("#{requires}\n\n" + code, options) end before :each do @@ -88,9 +88,8 @@ RSpec.describe "bundler/inline#gemfile" do RUBY expect(out).to include("Installing activesupport") - err.gsub! %r{(.*lib/sinatra/base\.rb:\d+: warning: constant ::Fixnum is deprecated$)}, "" err_lines = err.split("\n") - err_lines.reject!{|line| line =~ /\.rb:\d+: warning: / } + err_lines.reject!{|line| line =~ /\.rb:\d+: warning: / } unless RUBY_VERSION < "2.7" expect(err_lines).to be_empty expect(exitstatus).to be_zero if exitstatus end @@ -317,4 +316,21 @@ RSpec.describe "bundler/inline#gemfile" do expect(err).to be_empty end + + it "preserves previous BUNDLE_GEMFILE value" do + ENV["BUNDLE_GEMFILE"] = "" + script <<-RUBY + gemfile do + source "#{file_uri_for(gem_repo1)}" + gem "rack" + end + + puts "BUNDLE_GEMFILE is empty" if ENV["BUNDLE_GEMFILE"].empty? + system("#{Gem.ruby} -w -e '42'") # this should see original value of BUNDLE_GEMFILE + exit $?.exitstatus + RUBY + + expect(last_command).to be_success + expect(out).to include("BUNDLE_GEMFILE is empty") + end end diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index 4a754945b7..53300af618 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -130,7 +130,7 @@ RSpec.describe "Bundler.setup" do load_path = out.split("\n") rack_load_order = load_path.index {|path| path.include?("rack") } - expect(err).to eq("") + expect(err).to be_empty expect(load_path).to include(a_string_ending_with("dash_i_dir"), "rubylib_dir") expect(rack_load_order).to be > 0 end @@ -845,6 +845,12 @@ end end describe "when a vendored gem specification uses the :path option" do + let(:filesystem_root) do + current = Pathname.new(Dir.pwd) + current = current.parent until current == current.parent + current + end + it "should resolve paths relative to the Gemfile" do path = bundled_app(File.join("vendor", "foo")) build_lib "foo", :path => path @@ -858,7 +864,7 @@ end G Dir.chdir(bundled_app.parent) do - run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app("Gemfile") } + run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app("Gemfile").to_s } require 'foo' R end @@ -866,7 +872,7 @@ end end it "should make sure the Bundler.root is really included in the path relative to the Gemfile" do - relative_path = File.join("vendor", Dir.pwd[1..-1], "foo") + relative_path = File.join("vendor", Dir.pwd.gsub(/^#{filesystem_root}/, "")) absolute_path = bundled_app(relative_path) FileUtils.mkdir_p(absolute_path) build_lib "foo", :path => absolute_path @@ -882,7 +888,7 @@ end bundle :install Dir.chdir(bundled_app.parent) do - run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app("Gemfile") } + run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app("Gemfile").to_s } require 'foo' R end @@ -1027,6 +1033,8 @@ end ruby <<-RUBY require '#{lib_dir}/bundler' + bundler_module = class << Bundler; self; end + bundler_module.send(:remove_method, :require) def Bundler.require(path) raise "LOSE" end @@ -1034,7 +1042,7 @@ end RUBY expect(err).to be_empty - expect(out).to eq("") + expect(out).to be_empty end end @@ -1090,8 +1098,8 @@ end it "does not change the lock or warn" do lockfile lock_with(Bundler::VERSION.succ) ruby "require '#{lib_dir}/bundler/setup'" - expect(out).to eq("") - expect(err).to eq("") + expect(out).to be_empty + expect(err).to be_empty lockfile_should_be lock_with(Bundler::VERSION.succ) end end @@ -1154,8 +1162,8 @@ end let(:ruby_version) { "5.5.5" } it "does not change the lock or warn" do expect { ruby! "require '#{lib_dir}/bundler/setup'" }.not_to change { lockfile } - expect(out).to eq("") - expect(err).to eq("") + expect(out).to be_empty + expect(err).to be_empty end end @@ -1195,7 +1203,7 @@ end describe "default gem activation" do let(:exemptions) do if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7") - [] + %w[delegate did_you_mean] else %w[io-console openssl] end << "bundler" @@ -1204,17 +1212,15 @@ end let(:activation_warning_hack) { strip_whitespace(<<-RUBY) } require #{spec_dir.join("support/hax").to_s.dump} - if Gem::Specification.instance_methods.map(&:to_sym).include?(:activate) - Gem::Specification.send(:alias_method, :bundler_spec_activate, :activate) - Gem::Specification.send(:define_method, :activate) do - unless #{exemptions.inspect}.include?(name) - warn '-' * 80 - warn "activating \#{full_name}" - warn *caller - warn '*' * 80 - end - bundler_spec_activate + Gem::Specification.send(:alias_method, :bundler_spec_activate, :activate) + Gem::Specification.send(:define_method, :activate) do + unless #{exemptions.inspect}.include?(name) + warn '-' * 80 + warn "activating \#{full_name}" + warn(*caller) + warn '*' * 80 end + bundler_spec_activate end RUBY @@ -1238,14 +1244,14 @@ end it "activates no gems with -rbundler/setup" do install_gemfile! "" - ruby! code, :env => { :RUBYOPT => activation_warning_hack_rubyopt + " -r#{lib_dir}/bundler/setup" } + ruby! code, :env => { "RUBYOPT" => activation_warning_hack_rubyopt + " -r#{lib_dir}/bundler/setup" } expect(out).to eq("{}") end it "activates no gems with bundle exec" do install_gemfile! "" create_file("script.rb", code) - bundle! "exec ruby ./script.rb", :env => { :RUBYOPT => activation_warning_hack_rubyopt } + bundle! "exec ruby ./script.rb", :env => { "RUBYOPT" => activation_warning_hack_rubyopt } expect(out).to eq("{}") end @@ -1253,54 +1259,40 @@ end install_gemfile! "" create_file("script.rb", "#!/usr/bin/env ruby\n\n#{code}") FileUtils.chmod(0o777, bundled_app("script.rb")) - bundle! "exec ./script.rb", :artifice => nil, :env => { :RUBYOPT => activation_warning_hack_rubyopt } + bundle! "exec ./script.rb", :artifice => nil, :env => { "RUBYOPT" => activation_warning_hack_rubyopt } expect(out).to eq("{}") end - let(:default_gems) do - ruby!(<<-RUBY).split("\n") - if Gem::Specification.is_a?(Enumerable) - puts Gem::Specification.select(&:default_gem?).map(&:name) - end - RUBY - end + Gem::Specification.select(&:default_gem?).map(&:name).each do |g| + it "activates newer versions of #{g}" do + skip if exemptions.include?(g) - it "activates newer versions of default gems" do - build_repo4 do - default_gems.each do |g| + build_repo4 do build_gem g, "999999" end - end - default_gems.reject! {|g| exemptions.include?(g) } + install_gemfile! <<-G + source "#{file_uri_for(gem_repo4)}" + gem "#{g}", "999999" + G - install_gemfile! <<-G - source "#{file_uri_for(gem_repo4)}" - #{default_gems}.each do |g| - gem g, "999999" - end - G + expect(the_bundle).to include_gem("#{g} 999999", :env => { "RUBYOPT" => activation_warning_hack_rubyopt }) + end - expect(the_bundle).to include_gems(*default_gems.map {|g| "#{g} 999999" }) - end + it "activates older versions of #{g}" do + skip if exemptions.include?(g) - it "activates older versions of default gems" do - build_repo4 do - default_gems.each do |g| + build_repo4 do build_gem g, "0.0.0.a" end - end - default_gems.reject! {|g| exemptions.include?(g) } + install_gemfile! <<-G + source "#{file_uri_for(gem_repo4)}" + gem "#{g}", "0.0.0.a" + G - install_gemfile! <<-G - source "#{file_uri_for(gem_repo4)}" - #{default_gems}.each do |g| - gem g, "0.0.0.a" - end - G - - expect(the_bundle).to include_gems(*default_gems.map {|g| "#{g} 0.0.0.a" }) + expect(the_bundle).to include_gem("#{g} 0.0.0.a", :env => { "RUBYOPT" => activation_warning_hack_rubyopt }) + end end end end |