From 45f1dfe098d8599977f68bdbca759d78dd5c9770 Mon Sep 17 00:00:00 2001 From: MoHKale Date: Mon, 30 Dec 2019 21:42:04 +0000 Subject: [PATCH] fix broken test cases and revert _config.yml exclusion check I couldn't figure out how to make rspec change dir to the root of the site, so I couldn't make it pass the test. Just ended up reverting to the original method name :(. Also didn't realise the regexps used by listen_ignore_paths began with a ^, my bad. Fixed now. --- lib/jekyll/watcher.rb | 19 +++++++------------ spec/watcher_spec.rb | 3 ++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/jekyll/watcher.rb b/lib/jekyll/watcher.rb index 3c2c114..370d142 100644 --- a/lib/jekyll/watcher.rb +++ b/lib/jekyll/watcher.rb @@ -88,12 +88,8 @@ def custom_excludes(options) end def config_files(options) - # only check to exclude config file when config file is within our src directory - # which can only happen if our src directory is the same as our cwd. - if Pathname.new(options["source"]).expand_path.eql?(Pathname.new(".").expand_path) - %w(yml yaml toml).map(&"^_config\.".method(:+)) - else - [] + %w(yml yaml toml).map do |ext| + Jekyll.sanitized_path(options["source"], "_config.#{ext}") end end @@ -115,23 +111,22 @@ def to_exclude(options) # to ignore. def listen_ignore_paths(options) source = Pathname.new(options["source"]).expand_path - exclusion_fnmatch_paths = Array.new() + exclusion_fnmatch_paths = [] exclusion_regexps = to_exclude(options).map do |path| # convert to absolute path from the source directory absolute_path = Pathname.new(path).expand_path - relative_path = absolute_path.relative_path_from(source) + relative_path = absolute_path.relative_path_from(source).to_s - unless absolute_path.exist? + if !absolute_path.exist? # maybe wildcard, or just a file that doesn't exist. - exclusion_fnmatch_paths << relative_path.to_s - nil + nil.tap { exclusion_fnmatch_paths << relative_path } else relative_path = File.join(relative_path, "") if absolute_path.directory? begin unless relative_path.start_with?("../") - Regexp.new(Regexp.escape(relative_path)).tap do |pattern| + %r!^#{Regexp.escape(relative_path)}!.tap do |pattern| Jekyll.logger.debug "Watcher:", "Ignoring #{pattern}" end end diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index 98af237..76b6a57 100644 --- a/spec/watcher_spec.rb +++ b/spec/watcher_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 require "spec_helper" describe(Jekyll::Watcher) do @@ -97,7 +98,7 @@ end context "#listen_ignore_paths" do - let(:ignored) { subject.send(:listen_ignore_paths, options) } + let(:ignored) { subject.send(:listen_ignore_paths, options)[0] } let(:metadata_path) { Jekyll.sanitized_path(options["source"], ".jekyll-metadata") } before(:each) { FileUtils.touch(metadata_path) }