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

This commit is contained in:
stereobooster 2012-12-30 02:08:46 +02:00
parent a5a6900948
commit da096f307b
4 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
bad yaml: [
---
Real content starts here

View File

@ -0,0 +1,7 @@
---
test: good
---
Real content starts here
Ðóññêèé òåêñò

View File

@ -31,4 +31,14 @@ class Test::Unit::TestCase
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 File

@ -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