summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorwyhaines <wyhaines@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-08 16:13:26 +0000
committerwyhaines <wyhaines@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-08 16:13:26 +0000
commit35232b26bb0ebb3bdbe3d1198c8b2fa02ea8b08c (patch)
tree53a2c60e61c289122ab5dd9047606c5e56d8dd01 /test
parentfdcbfdc47088050b77c0d0568b7de538d16d481e (diff)
Openstruct fix, and fix to test_file_exhaustive.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@24797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ostruct/test_ostruct.rb29
-rw-r--r--test/ruby/test_file_exhaustive.rb4
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