From 567a7952dd0a506b04e2e50a1ac29715bc48aa6d Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 16 Jan 2017 16:25:09 -0500 Subject: [PATCH 1/2] test/helper: fix flaky plugin path test by initializing Configuration::DEFAULTS at start of tests If we do a Dir.chdir before Configuration::DEFAULTS is initialized, then its source and destination values will not be what we expect. We expect that Dir.pwd should stay as the root of the repo but there are some errant calls to Dir.chdir without a block that are still not yet cleaned up. --- test/helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/helper.rb b/test/helper.rb index 0c6935a0..fcbb7166 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -30,6 +30,11 @@ require "minitest/profile" require "rspec/mocks" require_relative "../lib/jekyll.rb" +# The default "source" and "destination" values depend on Dir.pwd, +# which changes when we use Dir.chdir without a block. Initialize +# it here so it has Dir.pwd = root of this repo. +Jekyll::Configuration::DEFAULTS + Jekyll.logger = Logger.new(StringIO.new) unless jruby? From aa7e47a30d4db30e644c54fc939ecd526db3c161 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 16 Jan 2017 16:43:25 -0500 Subject: [PATCH 2/2] Remove calls to Dir.chdir without a block. This removes the necessity to initialize Jekyll::Configuration::DEFAULTS manually. --- test/helper.rb | 11 +++++------ test/test_static_file.rb | 15 ++++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index fcbb7166..28c37ecf 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -30,11 +30,6 @@ require "minitest/profile" require "rspec/mocks" require_relative "../lib/jekyll.rb" -# The default "source" and "destination" values depend on Dir.pwd, -# which changes when we use Dir.chdir without a block. Initialize -# it here so it has Dir.pwd = root of this repo. -Jekyll::Configuration::DEFAULTS - Jekyll.logger = Logger.new(StringIO.new) unless jruby? @@ -67,6 +62,10 @@ module Minitest::Assertions end module DirectoryHelpers + def root_dir(*subdirs) + File.join(File.dirname(File.dirname(__FILE__)), *subdirs) + end + def dest_dir(*subdirs) test_dir("dest", *subdirs) end @@ -76,7 +75,7 @@ module DirectoryHelpers end def test_dir(*subdirs) - File.join(File.dirname(__FILE__), *subdirs) + root_dir("test", *subdirs) end end diff --git a/test/test_static_file.rb b/test/test_static_file.rb index 2be800a6..c45dcd78 100644 --- a/test/test_static_file.rb +++ b/test/test_static_file.rb @@ -16,33 +16,34 @@ class TestStaticFile < JekyllUnitTest end def setup_static_file(base, dir, name) - StaticFile.new(@site, base, dir, name) + Dir.chdir(@site.source) { StaticFile.new(@site, base, dir, name) } end def setup_static_file_with_collection(base, dir, name, metadata) site = fixture_site("collections" => { "foo" => metadata }) - StaticFile.new(site, base, dir, name, site.collections["foo"]) + Dir.chdir(site.source) do + StaticFile.new(site, base, dir, name, site.collections["foo"]) + end end def setup_static_file_with_defaults(base, dir, name, defaults) site = fixture_site("defaults" => defaults) - StaticFile.new(site, base, dir, name) + Dir.chdir(site.source) do + StaticFile.new(site, base, dir, name) + end end context "A StaticFile" do setup do clear_dest - @old_pwd = Dir.pwd - Dir.chdir source_dir @site = fixture_site @filename = "static_file.txt" make_dummy_file(@filename) - @static_file = setup_static_file(nil, nil, @filename) + @static_file = setup_static_file(@site.source, "", @filename) end teardown do remove_dummy_file(@filename) if File.exist?(source_dir(@filename)) - Dir.chdir @old_pwd end should "have a source file path" do