Module: Overseer::Assertions
- Defined in:
- lib/overseer/assertions.rb
Overview
A set of assertion methods
Instance Method Summary collapse
-
#assert(result, message = nil) ⇒ Object
Raises an
Assertionexception if the given object isn’ttrue. -
#assert_equal(expected, actual, message = nil) ⇒ Object
Compare two given objects if they are equal Fails if
actualisn’t equal toexpected. -
#assert_false(obj, message = nil) ⇒ Object
Verify if an object is
falseFails ifobjisn’tfalse. -
#assert_instance_of(clazz, obj, message = nil) ⇒ Object
Verify if an object is a instance of a specified class Fails if
objisn’t an instance ofclazz. -
#assert_kind_of(clazz, obj, message = nil) ⇒ Object
Verify if an object is a kind of a specified class Fails if
objisn’t a kind ofclazz. -
#assert_nil(obj, message = nil) ⇒ Object
Verify if an object is
nilFails ifobjisn’tnil. -
#assert_respond_to(obj, method, message = nil) ⇒ Object
Verify if an object responds to a method.
-
#assert_true(obj, message = nil) ⇒ Object
Verify if an object is
trueFails ifobjisn’ttrue.
Instance Method Details
#assert(result, message = nil) ⇒ Object
Raises an Assertion exception if the given object isn’t true. It adds the exception to the failure collection of the current test, in which the assertion was executed
Parameters
- result
-
the assertion result
- message<String>
-
the identifying message for the
Assertionexcpetion
20 21 22 23 24 25 |
# File 'lib/overseer/assertions.rb', line 20 def assert(result, =nil) Overseer.current_test.assertions += 1 raise Assertion, unless result rescue Assertion => e Overseer.current_test.failures << e end |
#assert_equal(expected, actual, message = nil) ⇒ Object
Compare two given objects if they are equal Fails if actual isn’t equal to expected
Parameters
- expected
-
the object which is expected
- actual
-
the actual given object
- message<String>
-
the identifying message for the
Assertionexception
35 36 37 38 |
# File 'lib/overseer/assertions.rb', line 35 def assert_equal(expected, actual, =nil) ||= "Expected: \"#{expected}\"\n Got: \"#{actual}\"" assert(expected == actual, ) end |
#assert_false(obj, message = nil) ⇒ Object
Verify if an object is false Fails if obj isn’t false
Parameters
- obj
-
the object which will be verified
- message<String>
-
the identifying message for the
Assertionexception
71 72 73 74 |
# File 'lib/overseer/assertions.rb', line 71 def assert_false(obj, =nil) ||= "Expected #{obj} to be false" assert(!obj, ) end |
#assert_instance_of(clazz, obj, message = nil) ⇒ Object
Verify if an object is a instance of a specified class Fails if obj isn’t an instance of clazz
Parameters
- clazz
-
the expected class which should
objbe an instance of - obj
-
the object which will be verified
- message<String>
-
the identifying message for the
Assertionexception
97 98 99 100 |
# File 'lib/overseer/assertions.rb', line 97 def assert_instance_of(clazz, obj, =nil) ||= "Expected \"#{obj.inspect}\" to be an instance of \"#{clazz}\", not \"#{obj.class}\"" assert(obj.instance_of?(clazz), ) end |
#assert_kind_of(clazz, obj, message = nil) ⇒ Object
Verify if an object is a kind of a specified class Fails if obj isn’t a kind of clazz
Parameters
- clazz
-
the expected class which should
objbe a kind of - obj
-
the object which will be verified
- message<String>
-
the identifying message for the
Assertionexception
84 85 86 87 |
# File 'lib/overseer/assertions.rb', line 84 def assert_kind_of(clazz, obj, =nil) ||= "Expected \"#{obj.inspect}\" to be a kind of \"#{clazz}\", not \"#{obj.class}\"" assert(obj.kind_of?(clazz), ) end |
#assert_nil(obj, message = nil) ⇒ Object
Verify if an object is nil Fails if obj isn’t nil
Parameters
- obj
-
the object which will be verified
- message<String>
-
the identifying message for the
Assertionexception
47 48 49 50 |
# File 'lib/overseer/assertions.rb', line 47 def assert_nil(obj, =nil) ||= "Expected #{obj} to be nil" assert(obj.nil?, ) end |
#assert_respond_to(obj, method, message = nil) ⇒ Object
Verify if an object responds to a method. Fails if obj doesn’t respond to method
Parameters
- obj
-
the object which will be verified
- method
-
the name of the method which
objshould respond to - message<String>
-
the identifying message for the
Assertionexception
110 111 112 113 |
# File 'lib/overseer/assertions.rb', line 110 def assert_respond_to(obj, method, =nil) ||= "Expected \"#{obj.inspect}\" to respond to \"##{method}\"" assert(obj.respond_to?(method), ) end |
#assert_true(obj, message = nil) ⇒ Object
Verify if an object is true Fails if obj isn’t true
Parameters
- obj
-
the object which will be verified
- message<String>
-
the identifying message for the
Assertionexception
59 60 61 62 |
# File 'lib/overseer/assertions.rb', line 59 def assert_true(obj, =nil) ||= "Expected #{obj} to be true" assert(!!obj, ) end |