Module: ShapeOf::Assertions

Defined in:
lib/shape_of.rb

Overview

To be included in a MiniTest test class

Instance Method Summary collapse

Instance Method Details

#assert_shape_of(object, shape) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/shape_of.rb', line 90

def assert_shape_of(object, shape)
  if shape.respond_to? :shape_of?
    assert shape.shape_of? object
  elsif shape.instance_of? ::Array
    assert Array[shape.first].shape_of? object
  elsif shape.instance_of? ::Hash
    assert Hash[shape].shape_of? object
  else
    raise TypeError, "Expected #{Shape.inspect}, an #{::Array.inspect}, or a #{::Hash.inspect} as the shape"
  end
end

#refute_shape_of(object, shape) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/shape_of.rb', line 102

def refute_shape_of(object, shape)
  if shape.respond_to? :shape_of?
    refute shape.shape_of? object
  elsif shape.instance_of? ::Array
    refute Array[shape.first].shape_of? object
  elsif shape.instance_of? ::Hash
    refute Hash[shape].shape_of? object
  else
    raise TypeError, "Expected #{Shape.inspect}, an #{::Array.inspect}, or a #{::Hash.inspect} as the shape"
  end
end