summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-05-26 01:53:27 +0900
committerSamuel Giddins <segiddins@segiddins.me>2016-05-25 13:57:25 -0500
commit9b83c889243b7277cd7c2f1072f76073edbead5d (patch)
tree6f58c8a746a2b4e9614deb4c2258cdd8f9e3b4a5
parent7e6aa5a5a98493e15286bc78d4049345a2c41ac9 (diff)
downloadbundler-9b83c889243b7277cd7c2f1072f76073edbead5d.tar.gz
Auto merge of #4611 - BrianHawley:fix_20160524_require_env, r=segiddins
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 0b4dfeccb7..3847a83bb9 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}"