diff --git a/test/fixtures/broken_front_matter2.erb b/test/fixtures/broken_front_matter2.erb new file mode 100644 index 00000000..f895dd26 --- /dev/null +++ b/test/fixtures/broken_front_matter2.erb @@ -0,0 +1,4 @@ +--- +bad yaml: [ +--- +Real content starts here diff --git a/test/fixtures/broken_front_matter3.erb b/test/fixtures/broken_front_matter3.erb new file mode 100644 index 00000000..5fff53b7 --- /dev/null +++ b/test/fixtures/broken_front_matter3.erb @@ -0,0 +1,7 @@ +--- +test: good +--- +Real content starts here + +Русский текст + diff --git a/test/helper.rb b/test/helper.rb index c6a8a763..491a41c7 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -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 diff --git a/test/test_convertible.rb b/test/test_convertible.rb index 2032715b..b9a9e41c 100644 --- a/test/test_convertible.rb +++ b/test/test_convertible.rb @@ -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