From bce2c2efb41fd128195256455dd9714183abb124 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 6 Dec 2013 00:52:33 -0500 Subject: [PATCH] Print the output of Jekyll if the command fails --- features/step_definitions/jekyll_steps.rb | 16 +++++++---- features/support/env.rb | 34 ++++++++++++++--------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 5f8f93fc..43c7e31d 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -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| diff --git a/features/support/env.rb b/features/support/env.rb index 5fcacc8a..c6d47583 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -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)