diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-06 15:14:27 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-06 15:14:27 -0800 |
commit | 40b1bc7cf72570f0645675b0e950de455566fe5e (patch) | |
tree | 3cda8d7d4e6308d62f97968af525c1227004ae92 /test/psych/test_exception.rb | |
parent | 7aad593c5e6e37e5b5f218b51a91cc005d10a3ac (diff) | |
download | psych-40b1bc7cf72570f0645675b0e950de455566fe5e.tar.gz |
* ext/psych/lib/psych.rb (module Psych): parse and load methods take
an optional file name that is used when raising Psych::SyntaxError
exceptions
* ext/psych/lib/psych/syntax_error.rb (module Psych): allow nil file
names and handle nil file names in the exception message
* test/psych/test_exception.rb (module Psych): Tests for changes.
Diffstat (limited to 'test/psych/test_exception.rb')
-rw-r--r-- | test/psych/test_exception.rb | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/test/psych/test_exception.rb b/test/psych/test_exception.rb index 5530a69..c6d98d7 100644 --- a/test/psych/test_exception.rb +++ b/test/psych/test_exception.rb @@ -16,12 +16,88 @@ module Psych @wups = Wups.new end + def test_load_takes_file + ex = assert_raises(Psych::SyntaxError) do + Psych.load '--- `' + end + assert_nil ex.file + + ex = assert_raises(Psych::SyntaxError) do + Psych.load '--- `', 'meow' + end + assert_equal 'meow', ex.file + end + + def test_psych_parse_stream_takes_file + ex = assert_raises(Psych::SyntaxError) do + Psych.parse_stream '--- `' + end + assert_nil ex.file + assert_match '(<unknown>)', ex.message + + ex = assert_raises(Psych::SyntaxError) do + Psych.parse_stream '--- `', 'omg!' + end + assert_equal 'omg!', ex.file + assert_match 'omg!', ex.message + end + + def test_load_stream_takes_file + ex = assert_raises(Psych::SyntaxError) do + Psych.load_stream '--- `' + end + assert_nil ex.file + assert_match '(<unknown>)', ex.message + + ex = assert_raises(Psych::SyntaxError) do + Psych.load_stream '--- `', 'omg!' + end + assert_equal 'omg!', ex.file + end + + def test_parse_file_exception + t = Tempfile.new(['parsefile', 'yml']) + t.binmode + t.write '--- `' + t.close + ex = assert_raises(Psych::SyntaxError) do + Psych.parse_file t.path + end + assert_equal t.path, ex.file + t.close(true) + end + + def test_load_file_exception + t = Tempfile.new(['loadfile', 'yml']) + t.binmode + t.write '--- `' + t.close + ex = assert_raises(Psych::SyntaxError) do + Psych.load_file t.path + end + assert_equal t.path, ex.file + t.close(true) + end + + def test_psych_parse_takes_file + ex = assert_raises(Psych::SyntaxError) do + Psych.parse '--- `' + end + assert_match '(<unknown>)', ex.message + assert_nil ex.file + + ex = assert_raises(Psych::SyntaxError) do + Psych.parse '--- `', 'omg!' + end + assert_match 'omg!', ex.message + end + def test_attributes e = assert_raises(Psych::SyntaxError) { Psych.load '--- `foo' } - assert_equal '<unknown>', e.file + assert_nil e.file assert_equal 1, e.line assert_equal 5, e.column # FIXME: offset isn't being set correctly by libyaml |