summaryrefslogtreecommitdiff
path: root/test/psych/test_exception.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/psych/test_exception.rb')
-rw-r--r--test/psych/test_exception.rb65
1 files changed, 46 insertions, 19 deletions
diff --git a/test/psych/test_exception.rb b/test/psych/test_exception.rb
index c6d98d7..30dfb24 100644
--- a/test/psych/test_exception.rb
+++ b/test/psych/test_exception.rb
@@ -1,4 +1,4 @@
-require 'psych/helper'
+require_relative 'helper'
module Psych
class TestException < TestCase
@@ -16,6 +16,12 @@ module Psych
@wups = Wups.new
end
+ def test_naming_exception
+ err = String.xxx rescue $!
+ new_err = Psych.load(Psych.dump(err))
+ assert_equal err.message, new_err.message
+ end
+
def test_load_takes_file
ex = assert_raises(Psych::SyntaxError) do
Psych.load '--- `'
@@ -56,27 +62,27 @@ module Psych
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)
+ Tempfile.create(['parsefile', 'yml']) {|t|
+ t.binmode
+ t.write '--- `'
+ t.close
+ ex = assert_raises(Psych::SyntaxError) do
+ Psych.parse_file t.path
+ end
+ assert_equal t.path, ex.file
+ }
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)
+ Tempfile.create(['loadfile', 'yml']) {|t|
+ t.binmode
+ t.write '--- `'
+ t.close
+ ex = assert_raises(Psych::SyntaxError) do
+ Psych.load_file t.path
+ end
+ assert_equal t.path, ex.file
+ }
end
def test_psych_parse_takes_file
@@ -126,5 +132,26 @@ module Psych
assert_equal 1, w.foo
assert_nil w.bar
end
+
+ def test_psych_syntax_error
+ Tempfile.create(['parsefile', 'yml']) do |t|
+ t.binmode
+ t.write '--- `'
+ t.close
+
+ begin
+ Psych.parse_file t.path
+ rescue StandardError
+ assert true # count assertion
+ ensure
+ return unless $!
+
+ ancestors = $!.class.ancestors.inspect
+
+ flunk "Psych::SyntaxError not rescued by StandardError: #{ancestors}"
+ end
+ end
+ end
+
end
end