Class: Simple::Immutable::TestCase

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/simple/immutable.rb

Constant Summary collapse

Immutable =
::Simple::Immutable

Instance Method Summary collapse

Instance Method Details

#hshObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/simple/immutable.rb', line 72

def hsh
  {
    a: "a-value",
    "b": "b-value",
    "child": {
      name: "childname",
      grandchild: {
        name: "grandchildname"
      }
    },
    "children": [
      "anna",
      "arthur",
      {
        action: {
          keep_your_mouth_shut: true
        }
      }
    ]
  }
end

#immutableObject



94
95
96
# File 'lib/simple/immutable.rb', line 94

def immutable
  Immutable.create hsh
end

#test_array_accessObject



117
118
119
120
121
122
123
124
# File 'lib/simple/immutable.rb', line 117

def test_array_access
  assert_kind_of(Array, immutable.children)
  assert_equal 3, immutable.children.length
  assert_equal "anna", immutable.children[0]

  assert_kind_of(Immutable, immutable.children[2])
  assert_equal true, immutable.children[2].action.keep_your_mouth_shut
end

#test_base_classObject



126
127
128
129
130
# File 'lib/simple/immutable.rb', line 126

def test_base_class
  assert_nothing_raised do
    immutable.object_id
  end
end

#test_child_accessObject



110
111
112
113
114
115
# File 'lib/simple/immutable.rb', line 110

def test_child_access
  child = immutable.child
  assert_kind_of(Immutable, child)
  assert_equal "childname", immutable.child.name
  assert_equal "grandchildname", immutable.child.grandchild.name
end

#test_comparisonObject



103
104
105
106
107
108
# File 'lib/simple/immutable.rb', line 103

def test_comparison
  immutable = Immutable.create hsh

  assert_equal immutable, hsh
  assert_not_equal({}, immutable)
end

#test_hash_accessObject



98
99
100
101
# File 'lib/simple/immutable.rb', line 98

def test_hash_access
  assert_equal "a-value", immutable.a
  assert_equal "b-value", immutable.b
end

#test_missing_keysObject



132
133
134
135
136
# File 'lib/simple/immutable.rb', line 132

def test_missing_keys
  assert_raise(NoMethodError) do
    immutable.foo
  end
end

#test_skip_when_args_or_blockObject



138
139
140
141
142
143
144
145
# File 'lib/simple/immutable.rb', line 138

def test_skip_when_args_or_block
  assert_raise(NoMethodError) do
    immutable.a(1, 2, 3)
  end
  assert_raise(NoMethodError) do
    immutable.a { :dummy }
  end
end