Module: RubyUnit::Assertions::Methods

Includes:
RubyUnit::AssertionMessage, Root
Included in:
RubyUnit::Assertions
Defined in:
lib/RubyUnit/Assertions/Methods.rb

Constant Summary

Constants included from RubyUnit::AssertionMessage

RubyUnit::AssertionMessage::ASSERT_CLASS_METHOD_ERROR, RubyUnit::AssertionMessage::ASSERT_CONST_DEFINED_ERROR, RubyUnit::AssertionMessage::ASSERT_CONST_ERROR, RubyUnit::AssertionMessage::ASSERT_CONST_NOT_DEFINED_ERROR, RubyUnit::AssertionMessage::ASSERT_DESCENDENT_ERROR, RubyUnit::AssertionMessage::ASSERT_EMPTY_ERROR, RubyUnit::AssertionMessage::ASSERT_EQUAL_ERROR, RubyUnit::AssertionMessage::ASSERT_ERROR, RubyUnit::AssertionMessage::ASSERT_FALSE_ERROR, RubyUnit::AssertionMessage::ASSERT_GREATERTHANOREQUAL_ERROR, RubyUnit::AssertionMessage::ASSERT_GREATERTHAN_ERROR, RubyUnit::AssertionMessage::ASSERT_INCLUDE_ERROR, RubyUnit::AssertionMessage::ASSERT_INSTANCE_METHOD_ERROR, RubyUnit::AssertionMessage::ASSERT_INSTANCE_OF_ERROR, RubyUnit::AssertionMessage::ASSERT_INSTANCE_VARIABLE_DEFINED_ERROR, RubyUnit::AssertionMessage::ASSERT_INSTANCE_VARIABLE_EQUAL_ERROR, RubyUnit::AssertionMessage::ASSERT_INSTANCE_VARIABLE_KIND_OF_ERROR, RubyUnit::AssertionMessage::ASSERT_INSTANCE_VARIABLE_NOT_DEFINED_ERROR, RubyUnit::AssertionMessage::ASSERT_INSTANCE_VARIABLE_NOT_EQUAL_ERROR, RubyUnit::AssertionMessage::ASSERT_INSTANCE_VARIABLE_NOT_KIND_OF_ERROR, RubyUnit::AssertionMessage::ASSERT_KIND_OF_ERROR, RubyUnit::AssertionMessage::ASSERT_LESSTHANOREQUAL_ERROR, RubyUnit::AssertionMessage::ASSERT_LESSTHAN_ERROR, RubyUnit::AssertionMessage::ASSERT_MATCH_ERROR, RubyUnit::AssertionMessage::ASSERT_METHOD_ERROR, RubyUnit::AssertionMessage::ASSERT_NIL_ERROR, RubyUnit::AssertionMessage::ASSERT_NOTHING_RAISED_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_CLASS_METHOD_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_DESCENDENT_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_EMPTY_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_EQUAL_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_INCLUDE_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_INSTANCE_METHOD_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_INSTANCE_OF_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_KIND_OF_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_MATCH_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_METHOD_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_NIL_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_RESPOND_TO_ERROR, RubyUnit::AssertionMessage::ASSERT_NOT_SAME_ERROR, RubyUnit::AssertionMessage::ASSERT_RAISE_ERROR, RubyUnit::AssertionMessage::ASSERT_RAISE_EXPECTED_ERROR, RubyUnit::AssertionMessage::ASSERT_RAISE_KIND_OF_ERROR, RubyUnit::AssertionMessage::ASSERT_RAISE_MESSAGE_ERROR, RubyUnit::AssertionMessage::ASSERT_RESPOND_TO_ERROR, RubyUnit::AssertionMessage::ASSERT_SAME_ERROR, RubyUnit::AssertionMessage::ASSERT_TRUE_ERROR, RubyUnit::AssertionMessage::FAILING, RubyUnit::AssertionMessage::FAILURE

Instance Method Summary collapse

Instance Method Details

#assertClassMethod(klass, class_method, message = nil) ⇒ Object

Assert that an Class has defined the specified class method.

  • raises RubyUnit::AssertionFailure unless klass has defined class_method

klass

The object to check for class_method

method

The method to check

message

The message provided to be reported for a failure

assertClassMethod String, :integer?, 'Nope' # => fail


138
139
140
# File 'lib/RubyUnit/Assertions/Methods.rb', line 138

def assertClassMethod klass, class_method, message = nil
  assertInclude klass.singleton_methods, class_method, message
end

#assertInstanceMethod(klass, instance_method, message = nil) ⇒ Object

Assert that an object has defined the specified instance method.

  • raises RubyUnit::AssertionFailure unless klass has defined instance_method

klass

The object to check for instance_method

method

The method to check

message

The message provided to be reported for a failure

assertInstanceMethod String, :integer?, 'Nope' # => fail


100
101
102
# File 'lib/RubyUnit/Assertions/Methods.rb', line 100

def assertInstanceMethod klass, instance_method, message = nil
  assertInclude klass.instance_methods, instance_method, message
end

#assertMethod(klass, method, message = nil) ⇒ Object

Assert that an object has defined the specified method.

  • raises RubyUnit::AssertionFailure unless klass has defined method

klass

The object to check for method

method

The method to check

message

The message provided to be reported for a failure

assertMethod String, :integer?, 'Nope' # => fail


62
63
64
# File 'lib/RubyUnit/Assertions/Methods.rb', line 62

def assertMethod klass, method, message = nil
  assertInclude klass.methods, method, message
end

#assertNotClassMethod(klass, not_class_method, message = nil) ⇒ Object

Assert that an Class has not defined the specified class method.

  • raises RubyUnit::AssertionFailure unless klass has defined not_class_method

klass

The object to check for not_class_method

method

The method to check

message

The message provided to be reported for a failure

assertNotClassMethod String, :new, 'Nope' # => fail


157
158
159
# File 'lib/RubyUnit/Assertions/Methods.rb', line 157

def assertNotClassMethod klass, not_class_method, message = nil
  assertNotInclude klass.singleton_methods, not_class_method, message
end

#assertNotInstanceMethod(klass, not_instance_method, message = nil) ⇒ Object

Assert that an object has not defined the specified instance method.

  • raises RubyUnit::AssertionFailure unless klass has defined not_instance_method

klass

The object to check for not_instance_method

method

The method to check

message

The message provided to be reported for a failure

assertNotInstanceMethod Integer, :integer?, 'Nope' # => fail


119
120
121
# File 'lib/RubyUnit/Assertions/Methods.rb', line 119

def assertNotInstanceMethod klass, not_instance_method, message = nil
  assertNotInclude klass.instance_methods, not_instance_method, message
end

#assertNotMethod(klass, not_method, message = nil) ⇒ Object

Assert that an object has not defined the specified method.

  • raises RubyUnit::AssertionFailure if klass has defined method

klass

The object to check for method

method

The method to check

message

The message provided to be reported for a failure

assertNotMethod Integer, :integer?, 'Nope' # => fail


81
82
83
# File 'lib/RubyUnit/Assertions/Methods.rb', line 81

def assertNotMethod klass, not_method, message = nil
  assertNotInclude klass.methods, not_method, message
end

#assertNotRespondTo(object, method, message = nil) ⇒ Object

Assert that an object does not respond to a particular method

  • raises RubyUnit::AssertionFailure if object responds to method

object

The object to check

method

The method to assert on the object

message

The message provided to be reported for a failure

assertNotRespondTo 25, :integer?, 'It does, so close'  # => fail


43
44
45
# File 'lib/RubyUnit/Assertions/Methods.rb', line 43

def assertNotRespondTo object, method, message = nil
  __assert (object.respond_to? method), ASSERT_NOT_RESPOND_TO_ERROR, message, {:object=>object, :method=>method}
end

#assertRespondTo(object, method, message = nil) ⇒ Object

Assert that an object responds to particular method

  • raises RubyUnit::AssertionFailure unless object responds to method

object

The object to check

method

The method to assert on the object

message

The message provided to be reported for a failure

assertRespondTo /^Regexp/, :length, 'It does not, so... no'  # => fail


24
25
26
# File 'lib/RubyUnit/Assertions/Methods.rb', line 24

def assertRespondTo object, method, message = nil
  __assert (object.respond_to? method), ASSERT_RESPOND_TO_ERROR, message, {:object=>object, :method=>method}
end