diff options
-rw-r--r-- | lib/psych/ruby.rb | 2 | ||||
-rw-r--r-- | lib/psych/visitors/yast_builder.rb | 4 | ||||
-rw-r--r-- | test/visitors/test_yast_builder.rb | 18 |
3 files changed, 20 insertions, 4 deletions
diff --git a/lib/psych/ruby.rb b/lib/psych/ruby.rb index 97734f5..896c185 100644 --- a/lib/psych/ruby.rb +++ b/lib/psych/ruby.rb @@ -1,4 +1,4 @@ -[Object, String].each do |klass| +[Object, String, Class].each do |klass| klass.send(:remove_method, :to_yaml) end diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb index 65ed594..df6d390 100644 --- a/lib/psych/visitors/yast_builder.rb +++ b/lib/psych/visitors/yast_builder.rb @@ -23,6 +23,10 @@ module Psych visitor_for(::String) do |o| @stack.last.children << Nodes::Scalar.new(o) end + + visitor_for(::Class) do |o| + raise TypeError, "can't dump anonymous class #{o.class}" + end end end end diff --git a/test/visitors/test_yast_builder.rb b/test/visitors/test_yast_builder.rb index 02f4c91..e73a57b 100644 --- a/test/visitors/test_yast_builder.rb +++ b/test/visitors/test_yast_builder.rb @@ -4,11 +4,13 @@ require 'psych' module Psych module Visitors class TestYASTBuilder < MiniTest::Unit::TestCase + def setup + @v = Visitors::YASTBuilder.new + end def test_scalar - v = Visitors::YASTBuilder.new - v.accept 'foo' + @v.accept 'foo' - assert_equal 'foo', Psych.load(v.tree.to_yaml) + assert_equal 'foo', Psych.load(@v.tree.to_yaml) assert_equal 'foo', Psych.load('foo'.to_yaml) end @@ -16,6 +18,16 @@ module Psych string = [0, 123,22, 44, 9, 32, 34, 39].pack('C*') assert_equal string, Psych.load(string.to_yaml) end + + def test_anon_class + assert_raises(TypeError) do + @v.accept Class.new + end + + assert_raises(TypeError) do + Class.new.to_yaml + end + end end end end |