Better tests for plugin manager.

This commit is contained in:
Parker Moore 2014-11-23 13:14:51 -08:00
parent 03d9396b85
commit ef53e677a4
2 changed files with 22 additions and 6 deletions

View File

@ -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

View File

@ -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