From 1d920f52f1db09b3f654f88fab8b7fcfd0941d03 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 16 Mar 2013 13:57:28 +0100 Subject: [PATCH 1/5] Fix bug where Command.globs didn't delete the destination directory. There was often a mix between absolute and relative paths and in the previous version, the destination argument was usually an absolute path where the glob array (from Dir['*']) was a relative path. --- lib/jekyll/command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/command.rb b/lib/jekyll/command.rb index bbc9e8a6..ab553dd8 100644 --- a/lib/jekyll/command.rb +++ b/lib/jekyll/command.rb @@ -3,7 +3,7 @@ module Jekyll def self.globs(source, destination) Dir.chdir(source) do dirs = Dir['*'].select { |x| File.directory?(x) } - dirs -= [destination] + dirs -= [destination, File.realpath(destination), File.basename(destination)] dirs = dirs.map { |x| "#{x}/**/*" } dirs += ['*'] end From a0c0d983bf6df8e217956c63cb5c7de0b871ca61 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 16 Mar 2013 13:59:40 +0100 Subject: [PATCH 2/5] Using a test_dir helper method for tests. --- test/helper.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index f4bdcf19..51194f56 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -28,17 +28,21 @@ class Test::Unit::TestCase include RR::Adapters::TestUnit def dest_dir(*subdirs) - File.join(File.dirname(__FILE__), 'dest', *subdirs) + test_dir('dest', *subdirs) end def source_dir(*subdirs) - File.join(File.dirname(__FILE__), 'source', *subdirs) + test_dir('source', *subdirs) end def clear_dest FileUtils.rm_rf(dest_dir) end + def test_dir(*subdirs) + File.join(File.dirname(__FILE__), *subdirs) + end + def capture_stdout $old_stdout = $stdout $stdout = StringIO.new From d93faac3b8a250391c33aa8becae07572e3f3cb5 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 16 Mar 2013 13:59:59 +0100 Subject: [PATCH 3/5] Rudimentary tests for Jekyll::Command --- test/test_command.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/test_command.rb diff --git a/test/test_command.rb b/test/test_command.rb new file mode 100644 index 00000000..ad7d6db1 --- /dev/null +++ b/test/test_command.rb @@ -0,0 +1,36 @@ +require 'helper' + +class TestCommand < Test::Unit::TestCase + context "when calling .globs" do + context "when non-default dest & source dirs" do + setup do + @source = source_dir + @dest = dest_dir + @globs = Command.globs(@source, @dest) + end + should "return an array without the destination dir" do + assert @globs.is_a?(Array) + assert !@globs.include?(@dest) + end + end + context "when using default dest dir" do + setup do + @source = test_dir + @dest = test_dir('_site') + FileUtils.mkdir(@dest) + File.open("#{@dest}/index.html", "w"){ |f| f.write("I was previously generated.") } + @globs = Command.globs(@source, @dest) + end + should "return an array without the destination dir" do + assert @globs.is_a?(Array) + assert !@globs.include?(@dest) + @globs.each do |glob| + assert !glob.include?(File.basename(@dest)) + end + end + teardown do + FileUtils.rm_r(@dest) + end + end + end +end From 52efb71aa24206209d65fe6bbf7a35aefb18a640 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 16 Mar 2013 14:09:53 +0100 Subject: [PATCH 4/5] Added directory_with_contents() to DRY up test code and ensure folders exist in TestCommand. --- test/helper.rb | 6 ++++++ test/test_command.rb | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index 51194f56..a20d236f 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -43,6 +43,12 @@ class Test::Unit::TestCase File.join(File.dirname(__FILE__), *subdirs) end + def directory_with_contents(path) + FileUtils.rm_rf(path) + FileUtils.mkdir(path) + File.open("#{path}/index.html", "w"){ |f| f.write("I was previously generated.") } + end + def capture_stdout $old_stdout = $stdout $stdout = StringIO.new diff --git a/test/test_command.rb b/test/test_command.rb index ad7d6db1..860c0c3d 100644 --- a/test/test_command.rb +++ b/test/test_command.rb @@ -6,19 +6,22 @@ class TestCommand < Test::Unit::TestCase setup do @source = source_dir @dest = dest_dir + directory_with_contents(@dest) @globs = Command.globs(@source, @dest) end should "return an array without the destination dir" do assert @globs.is_a?(Array) assert !@globs.include?(@dest) end + teardown do + clear_dest + end end context "when using default dest dir" do setup do @source = test_dir @dest = test_dir('_site') - FileUtils.mkdir(@dest) - File.open("#{@dest}/index.html", "w"){ |f| f.write("I was previously generated.") } + directory_with_contents(@dest) @globs = Command.globs(@source, @dest) end should "return an array without the destination dir" do From 8acb1b29bdfa26f595e78aadeddef18c91aa2121 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 16 Mar 2013 14:24:34 +0100 Subject: [PATCH 5/5] Using 1.8.7-compliant File.expand_path instead of >1.9 File.realpath --- lib/jekyll/command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/command.rb b/lib/jekyll/command.rb index ab553dd8..ea513e0d 100644 --- a/lib/jekyll/command.rb +++ b/lib/jekyll/command.rb @@ -3,7 +3,7 @@ module Jekyll def self.globs(source, destination) Dir.chdir(source) do dirs = Dir['*'].select { |x| File.directory?(x) } - dirs -= [destination, File.realpath(destination), File.basename(destination)] + dirs -= [destination, File.expand_path(destination), File.basename(destination)] dirs = dirs.map { |x| "#{x}/**/*" } dirs += ['*'] end