Permalink
Browse files

Add testcases for YAML syntax error and non UTF-8 encoding

  • Loading branch information...
1 parent a5a6900 commit da096f307b31fcc0a1e7fe0e80658f335901bcae @stereobooster committed Dec 30, 2012
Showing with 39 additions and 0 deletions.
  1. +4 −0 test/fixtures/broken_front_matter2.erb
  2. +7 −0 test/fixtures/broken_front_matter3.erb
  3. +10 −0 test/helper.rb
  4. +18 −0 test/test_convertible.rb
@@ -0,0 +1,4 @@
+---
+bad yaml: [
+---
+Real content starts here
@@ -0,0 +1,7 @@
+---
+test: good
+---
+Real content starts here
+
+Ðóññêèé òåêñò
+
View
@@ -31,4 +31,14 @@ def source_dir(*subdirs)
def clear_dest
FileUtils.rm_rf(dest_dir)
end
+
+ def capture_stdout
+ $old_stdout = $stdout
+ $stdout = StringIO.new
+ yield
+ $stdout.rewind
+ return $stdout.string
+ ensure
+ $stdout = $old_stdout
+ end
end
View
@@ -18,5 +18,23 @@ class TestConvertible < Test::Unit::TestCase
ret = @convertible.read_yaml(@base, 'broken_front_matter1.erb')
assert_equal({}, ret)
end
+
+ should "not parse if there is syntax error in front-matter" do
+ out = capture_stdout do
+ ret = @convertible.read_yaml(@base, 'broken_front_matter2.erb')
+ assert_equal({}, ret)
+ end
+ assert_match(/YAML Exception|syntax error/, out)
+ end
+
+ if RUBY_VERSION >= '1.9.2'
+ should "not parse if there is encoding error in file" do
+ out = capture_stdout do
+ ret = @convertible.read_yaml(@base, 'broken_front_matter3.erb')
+ assert_equal({}, ret)
+ end
+ assert_match(/invalid byte sequence in UTF-8/, out)
+ end
+ end
end
end

0 comments on commit da096f3

Please sign in to comment.