Print the output of Jekyll if the command fails

This commit is contained in:
Parker Moore 2013-12-06 00:52:33 -05:00
parent f0fbc8f356
commit bce2c2efb4
2 changed files with 31 additions and 19 deletions

View File

@ -1,9 +1,13 @@
Before do Before do
FileUtils.rm_rf(TEST_DIR)
FileUtils.mkdir(TEST_DIR) FileUtils.mkdir(TEST_DIR)
Dir.chdir(TEST_DIR) Dir.chdir(TEST_DIR)
end end
After do
FileUtils.rm_rf(TEST_DIR)
FileUtils.rm_rf(JEKYLL_COMMAND_OUTPUT_FILE)
end
World(Test::Unit::Assertions) World(Test::Unit::Assertions)
Given /^I have a blank site in "(.*)"$/ do |path| Given /^I have a blank site in "(.*)"$/ do |path|
@ -123,23 +127,23 @@ end
When /^I run jekyll$/ do When /^I run jekyll$/ do
run_jekyll run_jekyll_build
end end
When /^I run jekyll in safe mode$/ do When /^I run jekyll in safe mode$/ do
run_jekyll(:safe => true) run_jekyll_build("--safe")
end end
When /^I run jekyll with drafts$/ do When /^I run jekyll with drafts$/ do
run_jekyll(:drafts => true) run_jekyll_build("--drafts")
end end
When /^I call jekyll new with test_blank --blank$/ do When /^I call jekyll new with test_blank --blank$/ do
call_jekyll_new(:path => "test_blank", :blank => true) run_jekyll_new("test_blank --blank")
end end
When /^I debug jekyll$/ do When /^I debug jekyll$/ do
run_jekyll(:debug => true) run_jekyll_build("--verbose")
end end
When /^I change "(.*)" to contain "(.*)"$/ do |file, text| When /^I change "(.*)" to contain "(.*)"$/ do |file, text|

View File

@ -10,23 +10,31 @@ require 'time'
TEST_DIR = File.join('/', 'tmp', 'jekyll') TEST_DIR = File.join('/', 'tmp', 'jekyll')
JEKYLL_PATH = File.join(File.dirname(__FILE__), '..', '..', 'bin', 'jekyll') JEKYLL_PATH = File.join(File.dirname(__FILE__), '..', '..', 'bin', 'jekyll')
JEKYLL_COMMAND_OUTPUT_FILE = File.join('/', 'tmp', 'jekyll_output.txt')
def run_jekyll(opts = {}) def jekyll_output_file
command = JEKYLL_PATH.clone JEKYLL_COMMAND_OUTPUT_FILE
command << " build" end
command << " --drafts" if opts[:drafts]
command << " --safe" if opts[:safe] def jekyll_output
command << " >> /dev/null 2>&1" if opts[:debug].nil? File.read(jekyll_output_file)
end
def run_jekyll(args, output_file)
command = "#{JEKYLL_PATH} #{args} > #{jekyll_output_file} 2>&1"
system command system command
end end
def call_jekyll_new(opts = {}) def run_jekyll_build(build_args = "")
command = JEKYLL_PATH.clone if !run_jekyll("build #{build_args}", jekyll_output_file) || build_args.eql?("--verbose")
command << " new" puts jekyll_run_output
command << " #{opts[:path]}" if opts[:path] end
command << " --blank" if opts[:blank] end
command << " >> /dev/null 2>&1" if opts[:debug].nil?
system command def run_jekyll_new(new_args = "")
unless run_jekyll("new #{new_args}", jekyll_output_file)
puts jekyll_run_output
end
end end
def slug(title) def slug(title)