summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Hawley <bhawley@verticalresponse.com>2016-05-24 19:20:48 -0700
committerBrian Hawley <bhawley@verticalresponse.com>2016-05-24 19:20:48 -0700
commit1dc9911e5fb999b60ea15f515b9b8001ac005f4f (patch)
treec7521d0a964ea3c9fb6ca40abe4591e03f257ab8
parentdbad52b5b477936b25c2c5605247a9e70a0796cb (diff)
downloadbundler-1dc9911e5fb999b60ea15f515b9b8001ac005f4f.tar.gz
Fix the combination of gem :require and env or install_if
If you guard the installation of a gem with env or install_if, and that gem declaration has a :require option specified, it tried to require the gem even though it hadn't been installed. It looks like a spot was missed when the env command was added in the first place.
-rw-r--r--lib/bundler/runtime.rb6
-rw-r--r--spec/runtime/require_spec.rb24
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 6f02ad8512..b0ff6f5ae2 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -68,9 +68,9 @@ module Bundler
groups = [:default] if groups.empty?
@definition.dependencies.each do |dep|
- # Skip the dependency if it is not in any of the requested
- # groups
- next unless (dep.groups & groups).any? && dep.current_platform?
+ # Skip the dependency if it is not in any of the requested groups, or
+ # not for the current platform, or doesn't match the gem constraints.
+ next unless (dep.groups & groups).any? && dep.should_include?
required_file = nil
diff --git a/spec/runtime/require_spec.rb b/spec/runtime/require_spec.rb
index fbfa398239..5ddf1ef013 100644
--- a/spec/runtime/require_spec.rb
+++ b/spec/runtime/require_spec.rb
@@ -38,6 +38,14 @@ describe "Bundler.require" do
s.write "lib/eight.rb", "puts 'eight'"
end
+ build_lib "nine", "1.0.0" do |s|
+ s.write "lib/nine.rb", "puts 'nine'"
+ end
+
+ build_lib "ten", "1.0.0" do |s|
+ s.write "lib/ten.rb", "puts 'ten'"
+ end
+
gemfile <<-G
path "#{lib_path}"
gem "one", :group => :bar, :require => %w[baz qux]
@@ -48,6 +56,10 @@ describe "Bundler.require" do
gem "six", :group => "string"
gem "seven", :group => :not
gem "eight", :require => true, :group => :require_true
+ env "BUNDLER_TEST" => "nine" do
+ gem "nine", :require => true
+ end
+ gem "ten", :install_if => lambda { ENV["BUNDLER_TEST"] == "ten" }
G
end
@@ -86,6 +98,18 @@ describe "Bundler.require" do
expect(out).to eq("two\nfive")
end
+ it "allows requiring gems which are scoped by env" do
+ ENV["BUNDLER_TEST"] = "nine"
+ run "Bundler.require"
+ expect(out).to eq("two\nnine")
+ end
+
+ it "allows requiring gems which are scoped by install_if" do
+ ENV["BUNDLER_TEST"] = "ten"
+ run "Bundler.require"
+ expect(out).to eq("two\nten")
+ end
+
it "raises an exception if a require is specified but the file does not exist" do
gemfile <<-G
path "#{lib_path}"