Module: RubyUnit::Assertions::Basic

Includes:
RubyUnit::AssertionMessage, Root
Included in:
RubyUnit::Assertions
Defined in:
lib/RubyUnit/Assertions/Basic.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

#assert(value, message = nil) ⇒ Object

Assert that a test condition is true.

  • raises RubyUnit::AssertionFailure if value is false or nil

value

The value that is being checked by the assertion

message

The message provided to be reported for a failure

assert false, "This will fail"  # => fail


39
40
41
# File 'lib/RubyUnit/Assertions/Basic.rb', line 39

def assert value, message = nil
  __assert value, ASSERT_ERROR, message, {:value=>value}
end

#assertFalse(value, message = nil) ⇒ Object

Assert that a test condition is exactly false.

  • raises RubyUnit::AssertionFailure unless value is false

value

The value that is being checked by the assertion

message

The message provided to be reported for a failure

assertNil true, "This will fail"  # => fail


87
88
89
# File 'lib/RubyUnit/Assertions/Basic.rb', line 87

def assertFalse value, message = nil
  __assert (false == value), ASSERT_FALSE_ERROR, message, {:value=>value}
end

#assertNil(value, message = nil) ⇒ Object

Assert that a test condition is exactly nil.

  • raises RubyUnit::AssertionFailure unless value is nil

value

The value that is being checked by the assertion

message

The message provided to be reported for a failure

assertNil true, "This will fail"  # => fail


103
104
105
# File 'lib/RubyUnit/Assertions/Basic.rb', line 103

def assertNil value, message = nil
  __assert value.nil?, ASSERT_NIL_ERROR, message, {:value=>value}
end

#assertNot(value, message = nil) ⇒ Object

Assert that a test condition is false.

  • raises RubyUnit::AssertionFailure unless value is false or nil

value

The value that is being checked by the assertion

message

The message provided to be reported for a failure

assertNot true, "This will fail"  # => fail


55
56
57
# File 'lib/RubyUnit/Assertions/Basic.rb', line 55

def assertNot value, message = nil
  __reject value, ASSERT_NOT_ERROR, message, {:value=>value}
end

#assertNotNil(value, message = nil) ⇒ Object

Assert that a test condition is not nil.

  • raises RubyUnit::AssertionFailure if value is nil

value

The value that is being checked by the assertion

message

The message provided to be reported for a failure

assertNotNil nil, "This will fail"  # => fail


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

def assertNotNil value, message = nil
  __reject value.nil?, ASSERT_NOT_NIL_ERROR, message, {:value=>value}
end

#assertTrue(value, message = nil) ⇒ Object

Assert that a test condition is exactly true.

  • raises RubyUnit::AssertionFailure unless value is true

value

The value that is being checked by the assertion

message

The message provided to be reported for a failure

assertTrue false, "This will fail"  # => fail


71
72
73
# File 'lib/RubyUnit/Assertions/Basic.rb', line 71

def assertTrue value, message = nil
  __assert (true == value), ASSERT_TRUE_ERROR, message, {:value=>value}
end

#fail(message = nil, data = {}) ⇒ Object

Fail the test. This is used when some conditioned outside the test warrants a test failure.

  • This is likely an indication of something unexpected or missing functionality

  • raises RubyUnit::AssertionFailure

message

The message provided to be reported for a failure

data

The data associated with assertion

fail "I wasn't expecting the moon to fall into Lake Michigan"  # => fail


23
24
25
# File 'lib/RubyUnit/Assertions/Basic.rb', line 23

def fail message = nil, data = {}
  __assert_block FAILING, message, data
end