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

View File

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