diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ostruct/test_ostruct.rb | 29 | ||||
-rw-r--r-- | test/ruby/test_file_exhaustive.rb | 4 |
2 files changed, 31 insertions, 2 deletions
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index ef83db5d15..4d56102462 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -2,6 +2,21 @@ require 'test/unit' require 'ostruct' class TC_OpenStruct < Test::Unit::TestCase + def assert_not_respond_to(object, method, message="") + _wrap_assertion do + full_message = build_message(message, <<EOT, object, object.class, method) +<?> +of type <?> +expected not to respond_to\\?<?>. +EOT + _wrap_assertion do + if object.respond_to?(method) + raise Test::Unit::AssertionFailedError, full_message, caller(5) + end + end + end + end + def test_equality o1 = OpenStruct.new o2 = OpenStruct.new @@ -23,9 +38,23 @@ class TC_OpenStruct < Test::Unit::TestCase def test_inspect foo = OpenStruct.new + assert_equal("#<OpenStruct>", foo.inspect) + foo.bar = 1 + foo.baz = 2 + assert_equal("#<OpenStruct bar=1, baz=2>", foo.inspect) + + foo = OpenStruct.new foo.bar = OpenStruct.new assert_equal('#<OpenStruct bar=#<OpenStruct>>', foo.inspect) foo.bar.foo = foo assert_equal('#<OpenStruct bar=#<OpenStruct foo=#<OpenStruct ...>>>', foo.inspect) end + + def test_frozen + o = OpenStruct.new + o.a = 'a' + o.freeze + assert_raise(TypeError) {o.b = 'b'} + assert_not_respond_to(o, :b) + end end diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb index aac0329713..75a7d779b0 100644 --- a/test/ruby/test_file_exhaustive.rb +++ b/test/ruby/test_file_exhaustive.rb @@ -3,8 +3,8 @@ require "fileutils" require "tmpdir" class String - def start_with(prefix) - self =~ /^#{prefix}/ + def start_with?(prefix) + self[0..(prefix.length - 1)] == prefix end end |