module RubyUnit::Assertions::Classes
Public Instance Methods
Assert that a constant is defined correctly in the correct class
-
raises
RubyUnit::AssertionFailure
unless the constant is defined in the specified class and it is the correct type and value
- expected
-
The value that is expected for the constant
- klass
-
The class where the constant should be defined
- konstant
-
The name of the constant
- message
-
The message provided to be reported for a failure
assertConst 42, Numbers, 'TWENTYFOUR', 'So dyslexic.' # => fail
# File lib/RubyUnit/Assertions/Classes.rb, line 156 def assertConst expected, klass, konstant, message = nil __assert_block ASSERT_CONST_ERROR, message do assertConstDefined klass, konstant, message value = klass.const_get konstant assertKindOf expected.class, value, message assertEqual expected, value, message end end
Assert that a constant is defined in the specified class
-
raises
RubyUnit::AssertionFailure
unless the constant is defined in the specified class
- klass
-
The class where the constant should be defined
- konstant
-
The name of the constant
- message
-
The message provided to be reported for a failure
assertConstDefined Numbers, 'FORTYTWO', 'Mystery.' # => ??
# File lib/RubyUnit/Assertions/Classes.rb, line 181 def assertConstDefined klass, konstant, message = nil __assert (klass.const_defined? konstant), ASSERT_CONST_DEFINED_ERROR, message, {:klass=>klass, :konstant=>konstant} end
Assert that a constant is not defined in the specified class
-
raises
RubyUnit::AssertionFailure
if the constant is defined in the specified class
- klass
-
The class where the constant should not be defined
- konstant
-
The name of the constant
- message
-
The message provided to be reported for a failure
assertConstNotDefined Numbers, 'TWENTYFOUR', 'Mystery.' # => ??
# File lib/RubyUnit/Assertions/Classes.rb, line 201 def assertConstNotDefined klass, konstant, message = nil __reject (klass.const_defined? konstant), ASSERT_CONST_NOT_DEFINED_ERROR, message, {:klass=>klass, :konstant=>konstant} end
Assert that a class is a descendent of another class
-
raises
RubyUnit::AssertionFailure
unless descendent is a descendent of_super
- _super
-
The parent class
- descendent
-
The descendent class
- message
-
The message provided to be reported for a failure
assertDescendent Numeric, Exception, 'Nope' # => fail
# File lib/RubyUnit/Assertions/Classes.rb, line 110 def assertDescendent _super, descendent, message = nil __assert_descendent ASSERT_DESCENDENT_ERROR, _super, descendent, message do descendent < _super end end
Assert that an object is an instance of a specified class
-
raises
RubyUnit::AssertionFailure
unless object is an instance of klass.
- klass
-
The class that is expected
- object
-
The object that will be checked against klass
- message
-
The message provided to be reported for a failure
assertInstanceOf Integer, '25', 'So close, but... No.' # => fail
# File lib/RubyUnit/Assertions/Classes.rb, line 72 def assertInstanceOf klass, object, message = nil __assert (object.instance_of? klass), ASSERT_INSTANCE_OF_ERROR, message, {:klass=>klass, :object=>object} end
Assert that an object is an instance of the specified class or one of its descendents.
-
raises
RubyUnit::AssertionFailure
unless object is an instance of klass or one of its descendents.
- klass
-
The class that is expected
- object
-
The object that will be checked against klass
- message
-
The message provided to be reported for a failure
assertKindOf String, 25, 'Nope, try again.' # => fail
# File lib/RubyUnit/Assertions/Classes.rb, line 26 def assertKindOf klass, object, message = nil __assert (object.is_a? klass), ASSERT_KIND_OF_ERROR, message, {:klass=>klass, :object=>object} end
Assert that a class is not a descendent of another class
-
raises
RubyUnit::AssertionFailure
if klass is a descendent of klass
- klass
-
The parent class
- descendent
-
The illegal descendent class
- message
-
The message provided to be reported for a failure
assertDescendent StandardError, Exception, 'It is' # => fail
# File lib/RubyUnit/Assertions/Classes.rb, line 131 def assertNotDescendent klass, descendent, message = nil __assert_descendent ASSERT_NOT_DESCENDENT_ERROR, klass, descendent, message do not descendent < klass end end
Assert that an object is an instance of a specified class
-
raises
RubyUnit::AssertionFailure
unless object is an instance of klass.
- exclusion
-
The class that is expected
- object
-
The object that will be checked against klass
- message
-
The message provided to be reported for a failure
assertNotInstanceOf Integer, 25, 'So close, but... No.' # => fail
# File lib/RubyUnit/Assertions/Classes.rb, line 91 def assertNotInstanceOf exclusion, object, message = nil __reject (object.instance_of? exclusion), ASSERT_NOT_INSTANCE_OF_ERROR, message, {:exclusion=>exclusion, :object=>object} end
Assert that an object is not an instance of the specified class or one of its descendents.
-
raises
RubyUnit::AssertionFailure
if object is an instance of exclusion or
one of its descendents.
- exclusion
-
The class that is excluded
- object
-
The object that will be checked against klass
- message
-
The message provided to be reported for a failure
assertNotKindOf Numeric, 25, 'Nope, try again.' # => fail
# File lib/RubyUnit/Assertions/Classes.rb, line 49 def assertNotKindOf exclusion, object, message = nil __reject (object.is_a? exclusion), ASSERT_NOT_KIND_OF_ERROR, message, {:exclusion=>exclusion, :object=>object} end