diff --git a/lib/jekyll/tags/gist.rb b/lib/jekyll/tags/gist.rb index d69499af..f4f32880 100644 --- a/lib/jekyll/tags/gist.rb +++ b/lib/jekyll/tags/gist.rb @@ -12,7 +12,15 @@ module Jekyll gist_id, filename = tag_contents[0], tag_contents[1] gist_script_tag(gist_id, filename) else - "Error parsing gist id" + raise ArgumentError.new <<-eos +Syntax error in tag 'gist' while parsing the following markup: + + #{@markup} + +Valid syntax: + for public gists: {% gist 1234567 %} + for private gists: {% gist user/1234567 %} +eos end end diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index 57095ce7..e359dae4 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -77,14 +77,10 @@ eos def render(context) dir = File.join(context.registers[:site].source, INCLUDES_DIR) - if error = validate_dir(dir, context.registers[:site].safe) - return error - end + validate_dir(dir, context.registers[:site].safe) file = File.join(dir, @file) - if error = validate_file(dir, context.registers[:site].safe) - return error - end + validate_file(file, context.registers[:site].safe) partial = Liquid::Template.parse(source(file, context)) @@ -96,15 +92,15 @@ eos def validate_dir(dir, safe) if File.symlink?(dir) && safe - "Includes directory '#{dir}' cannot be a symlink" + raise IOError.new "Includes directory '#{dir}' cannot be a symlink" end end def validate_file(file, safe) if !File.exists?(file) - "Included file '#{@file}' not found in '#{INCLUDES_DIR}' directory" + raise IOError.new "Included file '#{@file}' not found in '#{INCLUDES_DIR}' directory" elsif File.symlink?(file) && safe - "The included file '#{INCLUDES_DIR}/#{@file}' should not be a symlink" + raise IOError.new "The included file '#{INCLUDES_DIR}/#{@file}' should not be a symlink" end end diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 51b3b605..063e22a4 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -50,9 +50,11 @@ module Jekyll end end - puts "ERROR: post_url: \"#{@orig_post}\" could not be found" + raise ArgumentError.new <<-eos +Could not find post "#{@orig_post}" in tag 'post_url'. - return "#" +Make sure the post exists and the name is correct. +eos end end end diff --git a/test/test_tags.rb b/test/test_tags.rb index c58c9c7e..fe16faa5 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -19,7 +19,7 @@ class TestTags < Test::Unit::TestCase payload = { "pygments_prefix" => @converter.pygments_prefix, "pygments_suffix" => @converter.pygments_suffix } - @result = Liquid::Template.parse(content).render(payload, info) + @result = Liquid::Template.parse(content).render!(payload, info) @result = @converter.convert(@result) end @@ -273,22 +273,19 @@ CONTENT end end - context "when invalid" do - setup do - @gist = "mattr-24081a1d93d2898ecf0f" - @filename = "myfile.ext" - content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) - end - should "write script tag with specific file in gist" do - assert_match "Error parsing gist id", @result + assert_raise ArgumentError do + create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end end end @@ -313,7 +310,7 @@ CONTENT end context "with blank gist id" do - setup do + should "raise ArgumentError" do content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) - end - should "output error message" do - assert_match "Error parsing gist id", @result + assert_raise ArgumentError do + create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) + end end end context "with invalid gist id" do - setup do + should "raise ArgumentError" do invalid_gist = 'invalid' content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) - end - should "output error message" do - assert_match "Error parsing gist id", @result + assert_raise ArgumentError do + create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) + end end end end