summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2019-02-12 17:41:41 +0100
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2019-03-27 14:08:09 +0100
commit5c71a1fc4c9ea6db34c3c22c99e342808769d748 (patch)
tree6cd5d12871390f07f85c3d5b8c5e8689a2bf4cd1
parentd368aa9e6257a27fab31efe0396069c8977cdc99 (diff)
downloadbundler-5c71a1fc4c9ea6db34c3c22c99e342808769d748.tar.gz
Allow to `bundle exec` default gems
Even when they are not explicitly specified in the Gemfile.
-rw-r--r--lib/bundler/rubygems_integration.rb9
-rw-r--r--spec/commands/exec_spec.rb77
2 files changed, 86 insertions, 0 deletions
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index c1d785a6e1..865bbc1f76 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -512,6 +512,15 @@ module Bundler
h
end
+ Gem::Specification.send(:default_stubs, "*.gemspec").each do |stub|
+ default_spec = stub.to_spec
+ default_spec_name = default_spec.name
+ next if specs_by_name.key?(default_spec_name)
+
+ specs << default_spec
+ specs_by_name[default_spec_name] = default_spec
+ end
+
replace_gem(specs, specs_by_name)
stub_rubygems(specs)
replace_bin_path(specs, specs_by_name)
diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb
index d339486ed1..375aebfa13 100644
--- a/spec/commands/exec_spec.rb
+++ b/spec/commands/exec_spec.rb
@@ -140,6 +140,83 @@ RSpec.describe "bundle exec" do
end
end
+ context "with default gems" do
+ let(:system_gems_to_install) { [] }
+
+ let(:default_irb_version) { ruby "gem 'irb', '< 999999'; require 'irb'; puts IRB::VERSION" }
+
+ context "when not specified in Gemfile" do
+ before do
+ skip "irb isn't a default gem" if default_irb_version.empty?
+
+ install_gemfile ""
+ end
+
+ it "uses version provided by ruby" do
+ bundle! "exec irb --version"
+
+ expect(out).to include(default_irb_version)
+ expect(last_command.stderr).to be_empty
+ end
+ end
+
+ context "when specified in Gemfile directly" do
+ let(:specified_irb_version) { "0.9.6" }
+
+ before do
+ skip "irb isn't a default gem" if default_irb_version.empty?
+
+ build_repo2 do
+ build_gem "irb", specified_irb_version do |s|
+ s.executables = "irb"
+ end
+ end
+
+ install_gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "irb", "#{specified_irb_version}"
+ G
+ end
+
+ it "uses version specified" do
+ bundle! "exec irb --version"
+
+ expect(out).to include(specified_irb_version)
+ expect(last_command.stderr).to be_empty
+ end
+ end
+
+ context "when specified in Gemfile indirectly" do
+ let(:indirect_irb_version) { "0.9.6" }
+
+ before do
+ skip "irb isn't a default gem" if default_irb_version.empty?
+
+ build_repo2 do
+ build_gem "irb", indirect_irb_version do |s|
+ s.executables = "irb"
+ end
+
+ build_gem "gem_depending_on_old_irb" do |s|
+ s.add_dependency "irb", indirect_irb_version
+ end
+ end
+
+ install_gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "gem_depending_on_old_irb"
+ G
+
+ bundle! "exec irb --version"
+ end
+
+ it "uses resolved version" do
+ expect(out).to include(indirect_irb_version)
+ expect(last_command.stderr).to be_empty
+ end
+ end
+ end
+
it "handles gems installed with --without" do
install_gemfile <<-G, forgotten_command_line_options(:without => "middleware")
source "file://#{gem_repo1}"