Better tests for plugin manager.
This commit is contained in:
parent
03d9396b85
commit
ef53e677a4
|
@ -17,7 +17,6 @@ module Jekyll
|
||||||
def conscientious_require
|
def conscientious_require
|
||||||
require_plugin_files
|
require_plugin_files
|
||||||
require_gems
|
require_gems
|
||||||
self.class.require_from_bundler
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Require each of the gem plugins specified.
|
# Require each of the gem plugins specified.
|
||||||
|
@ -33,15 +32,15 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.require_from_bundler
|
def self.require_from_bundler
|
||||||
if ENV["JEKYLL_NO_BUNDLER_REQUIRE"] || !File.file?("Gemfile")
|
if !ENV["JEKYLL_NO_BUNDLER_REQUIRE"] && File.file?("Gemfile")
|
||||||
false
|
|
||||||
else
|
|
||||||
require "bundler"
|
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
|
required_gems = Bundler.require(:jekyll_plugins) # requires the gems in this group only
|
||||||
Jekyll.logger.debug("PluginManager:", "Required #{required_gems.map(&:name).join(', ')}")
|
Jekyll.logger.debug("PluginManager:", "Required #{required_gems.map(&:name).join(', ')}")
|
||||||
ENV["JEKYLL_NO_BUNDLER_REQUIRE"] = "true"
|
ENV["JEKYLL_NO_BUNDLER_REQUIRE"] = "true"
|
||||||
true
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
end
|
end
|
||||||
rescue LoadError, Bundler::GemfileNotFound
|
rescue LoadError, Bundler::GemfileNotFound
|
||||||
false
|
false
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
require 'helper'
|
require 'helper'
|
||||||
|
|
||||||
class TestPluginManager < Test::Unit::TestCase
|
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
|
def test_requiring_from_bundler
|
||||||
with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do
|
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.'
|
assert ENV["JEKYLL_NO_BUNDLER_REQUIRE"], 'Gemfile plugins were not required.'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,6 +18,16 @@ class TestPluginManager < Test::Unit::TestCase
|
||||||
def test_blocking_requiring_from_bundler
|
def test_blocking_requiring_from_bundler
|
||||||
with_env("JEKYLL_NO_BUNDLER_REQUIRE", "true") do
|
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_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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue