Class: Oval::InstanceOf

Inherits:
ClassDeclBase show all
Defined in:
lib/oval/instance_of.rb

Instance Attribute Summary

Attributes inherited from ClassDeclBase

#klass

Instance Method Summary collapse

Methods inherited from ClassDeclBase

[], #initialize

Methods inherited from Base

[], ensure_equal, #initialize, it_should, validate

Constructor Details

This class inherits a constructor from Oval::ClassDeclBase

Instance Method Details

#it_shouldObject


11
12
13
# File 'lib/oval/instance_of.rb', line 11

def it_should
  "be an instance of #{klass.name}"
end

#validate(object, subject = nil) ⇒ Object


4
5
6
7
8
9
10
# File 'lib/oval/instance_of.rb', line 4

def validate(object, subject = nil)
  unless object.instance_of?(klass)
    raise Oval::ValueError,
      "Invalid object #{object.inspect} of type #{object.class.name}" +
      "#{for_subject(subject)}. Should be an instance of #{klass.name}"
  end
end