OCHamcrest
|
Matchers that inspect objects.
Defines | |
#define | conformsTo HC_conformsTo |
conformsTo(aProtocol) - Matches if object conforms to a given protocol. | |
#define | hasDescription HC_hasDescription |
hasDescription(aMatcher) - Matches if object's -description satisfies a given matcher. | |
#define | hasProperty HC_hasProperty |
hasProperty(name, valueMatcher) - Matches if object has a method of a given name whose return value satisfies a given matcher. | |
#define | equalTo HC_equalTo |
equalTo(anObject) - Matches if object is equal to a given object. | |
#define | instanceOf HC_instanceOf |
instanceOf(aClass) - Matches if object is an instance of, or inherits from, a given class. | |
#define | nilValue() HC_nilValue() |
Matches if object is nil . | |
#define | notNilValue() HC_notNilValue() |
Matches if object is not nil . | |
#define | sameInstance HC_sameInstance |
sameInstance(anObject) - Matches if evaluated object is the same instance as a given object. | |
#define | isA HC_isA |
isA(aClass) - Matches if object is an instance of a given class (but not of a subclass). |
Matchers that inspect objects.
#define conformsTo HC_conformsTo |
conformsTo(aProtocol) - Matches if object conforms to a given protocol.
aProtocol | The protocol to compare against as the expected protocol. |
This matcher checks whether the evaluated object conforms to aProtocol.
Example:
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_conformsTo
instead.)
#define equalTo HC_equalTo |
equalTo(anObject) - Matches if object is equal to a given object.
anObject | The object to compare against as the expected value. |
This matcher compares the evaluated object to anObject for equality, as determined by the -isEqual
: method.
If anObject is nil
, the matcher will successfully match nil
.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_equalTo
instead.)
#define hasDescription HC_hasDescription |
hasDescription(aMatcher) - Matches if object's -description
satisfies a given matcher.
aMatcher | The matcher to satisfy, or an expected value for equalTo matching. |
This matcher invokes -description
on the evaluated object to get its description, passing the result to a given matcher for evaluation. If the aMatcher argument is not a matcher, it is implicitly wrapped in an equalTo matcher to check for equality.
Examples:
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_hasDescription
instead.)
#define hasProperty HC_hasProperty |
hasProperty(name, valueMatcher) - Matches if object has a method of a given name whose return value satisfies a given matcher.
name | The name of a method without arguments that returns an object. |
valueMatcher | The matcher to satisfy for the return value, or an expected value for equalTo matching. |
This matcher first checks if the evaluated object has a method with a name matching the given name
. If so, it invokes the method and sees if the returned value satisfies valueMatcher
.
While this matcher is called "hasProperty", it's useful for checking the results of any simple methods, not just properties.
Examples:
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_hasProperty
instead.)
#define instanceOf HC_instanceOf |
instanceOf(aClass) - Matches if object is an instance of, or inherits from, a given class.
aClass | The class to compare against as the expected class. |
This matcher checks whether the evaluated object is an instance of aClass or an instance of any class that inherits from aClass.
Example:
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_instanceOf
instead.)
isA(aClass) - Matches if object is an instance of a given class (but not of a subclass).
aClass | The class to compare against as the expected class. |
This matcher checks whether the evaluated object is an instance of aClass.
Example:
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_isA
instead.)
#define nilValue | ( | ) | HC_nilValue() |
Matches if object is nil
.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_nilValue
instead.)
#define notNilValue | ( | ) | HC_notNilValue() |
Matches if object is not nil
.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_notNilValue
instead.)
#define sameInstance HC_sameInstance |
sameInstance(anObject) - Matches if evaluated object is the same instance as a given object.
anObject | The object to compare against as the expected value. |
This matcher compares the address of the evaluated object to determine if it is the same object as anObject.
(In the event of a name clash, don't #define HC_SHORTHAND
and use the synonym HC_sameInstance
instead.)