Add testcases for YAML syntax error and non UTF-8 encoding
This commit is contained in:
parent
a5a6900948
commit
da096f307b
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
bad yaml: [
|
||||
---
|
||||
Real content starts here
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
test: good
|
||||
---
|
||||
Real content starts here
|
||||
|
||||
Ðóññêèé òåêñò
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue