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
Assertion
exception if the given object isn’ttrue
. -
#assert_equal(expected, actual, message = nil) ⇒ Object
Compare two given objects if they are equal Fails if
actual
isn’t equal toexpected
. -
#assert_false(obj, message = nil) ⇒ Object
Verify if an object is
false
Fails ifobj
isn’tfalse
. -
#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 ofclazz
. -
#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 ofclazz
. -
#assert_nil(obj, message = nil) ⇒ Object
Verify if an object is
nil
Fails ifobj
isn’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
true
Fails ifobj
isn’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
Assertion
excpetion
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
Assertion
exception
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
Assertion
exception
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
obj
be an instance of - obj
-
the object which will be verified
- message<String>
-
the identifying message for the
Assertion
exception
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
obj
be a kind of - obj
-
the object which will be verified
- message<String>
-
the identifying message for the
Assertion
exception
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
Assertion
exception
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
obj
should respond to - message<String>
-
the identifying message for the
Assertion
exception
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
Assertion
exception
59 60 61 62 |
# File 'lib/overseer/assertions.rb', line 59 def assert_true(obj, =nil) ||= "Expected #{obj} to be true" assert(!!obj, ) end |