Project

General

Profile

Bug #1219 ยป test_ostruct.patch

The patch for test/ostruct/test_ostruct.rb - RobertDober (Robert Dober), 02/27/2009 06:11 AM

View differences:

test_ostruct-new.rb 2009-02-26 22:04:10.000000000 +0100
34 34
    foo.bar.foo = foo
35 35
    assert_equal('#<OpenStruct bar=#<OpenStruct foo=#<OpenStruct ...>>>', foo.inspect)
36 36
  end
37

  
38
  def test_frozen
39
    o = OpenStruct::new :a => 42
40
    o.freeze
41
    assert_raise TypeError do
42
      o.b = 1
43
    end
44
    assert_raise TypeError do
45
      o.a = 1764
46
    end
47
    assert_equal 42, o.a
48
    assert_equal nil, o.b
49
  end
50

  
51
  def test_really_frozen
52
    o1 = OpenStruct::new :a => 42
53
    o2 = o1.dup
54
    class << o1; def frozen?; nil end end
55
    o1.freeze
56
    o2.b = 42
57
    assert_equal 42, o2.b
58
    assert_raise TypeError do
59
      o1.b = 1
60
    end
61
    assert_raise TypeError do
62
      o1.a = 1806
63
    end
64
    assert_equal 42, o1.a
65
    OpenStruct.module_eval do def frozen?; nil end end
66
    o2.freeze
67
    assert_raise TypeError do
68
      o2.b = 1
69
    end
70
    assert_equal 42, o2.b
71
  end
37 72
end