diff --git a/lib/jekyll/plugin_manager.rb b/lib/jekyll/plugin_manager.rb index d7785338..fe2e43f9 100644 --- a/lib/jekyll/plugin_manager.rb +++ b/lib/jekyll/plugin_manager.rb @@ -46,7 +46,7 @@ module Jekyll end def self.require_from_bundler - if !ENV["JEKYLL_NO_BUNDLER_REQUIRE"] && File.file?("Gemfile") + if !ENV["JEKYLL_NO_BUNDLER_REQUIRE"] && gemfile_exists? require "bundler" Bundler.setup @@ -61,6 +61,13 @@ module Jekyll end end + # Check for the existence of a Gemfile. + # + # Returns true if a Gemfile exists in the places bundler will look + def self.gemfile_exists? + File.file?("Gemfile") || (ENV["BUNDLE_GEMFILE"] && File.file?(ENV["BUNDLE_GEMFILE"])) + end + # Check whether a gem plugin is allowed to be used during this build. # # plugin_name - the name of the plugin diff --git a/test/test_plugin_manager.rb b/test/test_plugin_manager.rb index dfcb4dfe..a7b9359e 100644 --- a/test/test_plugin_manager.rb +++ b/test/test_plugin_manager.rb @@ -10,6 +10,13 @@ class TestPluginManager < JekyllUnitTest FileUtils.mv "Gemfile.old", "Gemfile" end + def with_bundle_gemfile + FileUtils.mv "Gemfile", "AlternateGemfile" + yield + ensure + FileUtils.mv "AlternateGemfile", "Gemfile" + end + context "JEKYLL_NO_BUNDLER_REQUIRE set to `nil`" do should "require from bundler" do with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do @@ -20,6 +27,18 @@ class TestPluginManager < JekyllUnitTest end end + context "BUNDLE_GEMFILE set to `AlternateGemfile`" do + should "require from bundler" do + with_env("BUNDLE_GEMFILE", "AlternateGemfile") do + with_bundle_gemfile do + assert Jekyll::PluginManager.require_from_bundler, + "require_from_bundler should return true" + assert ENV["JEKYLL_NO_BUNDLER_REQUIRE"], "Gemfile plugins were not required." + end + end + end + end + context "JEKYLL_NO_BUNDLER_REQUIRE set to `true`" do should "not require from bundler" do with_env("JEKYLL_NO_BUNDLER_REQUIRE", "true") do