From ef53e677a4f53cd8c665c1824807469c527713f3 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 23 Nov 2014 13:14:51 -0800 Subject: [PATCH] Better tests for plugin manager. --- lib/jekyll/plugin_manager.rb | 9 ++++----- test/test_plugin_manager.rb | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/plugin_manager.rb b/lib/jekyll/plugin_manager.rb index a89908c6..9ce593ae 100644 --- a/lib/jekyll/plugin_manager.rb +++ b/lib/jekyll/plugin_manager.rb @@ -17,7 +17,6 @@ module Jekyll def conscientious_require require_plugin_files require_gems - self.class.require_from_bundler end # Require each of the gem plugins specified. @@ -33,15 +32,15 @@ module Jekyll end def self.require_from_bundler - if ENV["JEKYLL_NO_BUNDLER_REQUIRE"] || !File.file?("Gemfile") - false - else + if !ENV["JEKYLL_NO_BUNDLER_REQUIRE"] && File.file?("Gemfile") require "bundler" - Bundler.setup # puts all groups on the load path + #Bundler.setup # puts all groups on the load path required_gems = Bundler.require(:jekyll_plugins) # requires the gems in this group only Jekyll.logger.debug("PluginManager:", "Required #{required_gems.map(&:name).join(', ')}") ENV["JEKYLL_NO_BUNDLER_REQUIRE"] = "true" true + else + false end rescue LoadError, Bundler::GemfileNotFound false diff --git a/test/test_plugin_manager.rb b/test/test_plugin_manager.rb index 1f7931ca..0d12a254 100644 --- a/test/test_plugin_manager.rb +++ b/test/test_plugin_manager.rb @@ -1,9 +1,16 @@ require 'helper' class TestPluginManager < Test::Unit::TestCase + def with_no_gemfile + FileUtils.mv "Gemfile", "Gemfile.old" + yield + ensure + FileUtils.mv "Gemfile.old", "Gemfile" + end + def test_requiring_from_bundler with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do - Jekyll::PluginManager.require_from_bundler + 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 @@ -11,6 +18,16 @@ class TestPluginManager < Test::Unit::TestCase def test_blocking_requiring_from_bundler with_env("JEKYLL_NO_BUNDLER_REQUIRE", "true") do assert_equal false, Jekyll::PluginManager.require_from_bundler, "Gemfile plugins were required but shouldn't have been" + assert ENV["JEKYLL_NO_BUNDLER_REQUIRE"] + end + end + + def test_no_gemfile + with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do + with_no_gemfile do + assert_equal false, Jekyll::PluginManager.require_from_bundler, "Gemfile plugins were required but shouldn't have been" + assert_nil ENV["JEKYLL_NO_BUNDLER_REQUIRE"] + end end end end