From d158d73ce1da2b1c105bdd3eaea525852b9b097a Mon Sep 17 00:00:00 2001 From: Florian Thomas Date: Sat, 30 Jul 2016 15:49:16 +0200 Subject: [PATCH] add missing tests --- test/test_plugin_manager.rb | 106 ++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/test/test_plugin_manager.rb b/test/test_plugin_manager.rb index 67dfa726..809a1a46 100644 --- a/test/test_plugin_manager.rb +++ b/test/test_plugin_manager.rb @@ -39,4 +39,110 @@ class TestPluginManager < JekyllUnitTest end end end + + context "require gems" do + should "check if configured gems are allowed" do + allow(Jekyll::External).to receive(:require_with_graceful_fail).and_return(nil) + site = double(:gems => %w(jemoji foobar)) + plugin_manager = PluginManager.new(site) + + expect(plugin_manager).to receive(:plugin_allowed?).with("jemoji") + expect(plugin_manager).to receive(:plugin_allowed?).with("foobar") + plugin_manager.require_gems + end + end + + context "site is not marked as safe" do + should "allow all plugins" do + site = double(:safe => false) + plugin_manager = PluginManager.new(site) + + assert plugin_manager.plugin_allowed?("foobar") + end + + should "require plugin files" do + site = double({ :safe => false, + :config => { "plugins_dir" => "_plugins" }, + :in_source_dir => "/tmp/" }) + plugin_manager = PluginManager.new(site) + + expect(Jekyll::External).to receive(:require_with_graceful_fail) + plugin_manager.require_plugin_files + end + end + + context "site is marked as safe" do + should "allow plugins if they are whitelisted" do + site = double({ :safe => true, :config => { "whitelist" => ["jemoji"] } }) + plugin_manager = PluginManager.new(site) + + assert plugin_manager.plugin_allowed?("jemoji") + assert !plugin_manager.plugin_allowed?("not_allowed_plugin") + end + + should "not require plugin files" do + site = double({ :safe => true }) + plugin_manager = PluginManager.new(site) + + expect(Jekyll::External).to_not receive(:require_with_graceful_fail) + plugin_manager.require_plugin_files + end + end + + context "plugins_dir is set to the default" do + should "call site's in_source_dir" do + site = double({ + :config => { + "plugins_dir" => Jekyll::Configuration::DEFAULTS["plugins_dir"] + }, + :in_source_dir => "/tmp/" + }) + plugin_manager = PluginManager.new(site) + + expect(site).to receive(:in_source_dir).with("_plugins") + plugin_manager.plugins_path + end + end + + context "plugins_dir is set to a different dir" do + should "expand plugin path" do + site = double({ :config => { "plugins_dir" => "some_other_plugins_path" } }) + plugin_manager = PluginManager.new(site) + + expect(File).to receive(:expand_path).with("some_other_plugins_path") + plugin_manager.plugins_path + end + end + + context "`paginate` config is activated" do + should "print deprecation warning if jekyll-paginate is not present" do + site = double({ :config => { "paginate" => true } }) + plugin_manager = PluginManager.new(site) + + expect(Jekyll::Deprecator).to( + receive(:deprecation_message).with(%r!jekyll-paginate!) + ) + plugin_manager.deprecation_checks + end + + should "print no deprecation warning if jekyll-paginate is present" do + site = double({ + :config => { "paginate" => true, "gems" => ["jekyll-paginate"] } + }) + plugin_manager = PluginManager.new(site) + + expect(Jekyll::Deprecator).to_not receive(:deprecation_message) + plugin_manager.deprecation_checks + end + end + + should "conscientious require" do + site = double + plugin_manager = PluginManager.new(site) + + expect(plugin_manager).to( + receive_messages([:require_plugin_files, :require_gems, :deprecation_checks]) + ) + plugin_manager.conscientious_require + end end