Skip to content

Commit

Permalink
Improves documentation around stubProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
jonreid committed Jun 26, 2016
1 parent 66af5da commit 41adbfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,14 @@ SomeStruct aStruct = {...};
How do you stub a property so that KVO works?
---------------------------------------------
Use `stubProperty(instance, property, value)`. For example:
Use `stubProperty(mock, property, stubbedValue)`. For example, say you have a mock object named `mockEmployee`. It has a property `firstName`. You want to stub it to return the value "FIRST-NAME":
```obj-c
stubProperty(mockEmployee, firstName, @"fake-firstname");
stubProperty(mockEmployee, firstName, @"FIRST-NAME");
```

This stubs the `firstName` property, `valueForKey:` and `valueForKeyPath:`.


Argument matchers
-----------------
Expand Down
12 changes: 6 additions & 6 deletions Source/OCMockito/Core/OCMockito.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ FOUNDATION_EXPORT MKTOngoingStubbing *MKTGivenVoidWithLocation(id testCase, cons
#endif


#define MKTStubProperty(instance, property, value) \
do { \
[MKTGiven([instance property]) willReturn:value]; \
[MKTGiven([instance valueForKey:@#property]) willReturn:value]; \
[MKTGiven([instance valueForKeyPath:@#property]) willReturn:value]; \
#define MKTStubProperty(mock, property, stubbedValue) \
do { \
[MKTGiven([mock property]) willReturn:stubbedValue]; \
[MKTGiven([mock valueForKey:@#property]) willReturn:stubbedValue]; \
[MKTGiven([mock valueForKeyPath:@#property]) willReturn:stubbedValue]; \
} while(0)

#ifndef MKT_DISABLE_SHORT_SYNTAX
Expand All @@ -188,7 +188,7 @@ FOUNDATION_EXPORT MKTOngoingStubbing *MKTGivenVoidWithLocation(id testCase, cons
* In the event of a name clash, <code>#define MKT_DISABLE_SHORT_SYNTAX</code> and use the synonym
* MKTStubProperty instead.
*/
#define stubProperty(instance, property, value) MKTStubProperty(instance, property, value)
#define stubProperty(mock, property, stubbedValue) MKTStubProperty(mock, property, stubbedValue)
#endif


Expand Down

0 comments on commit 41adbfe

Please sign in to comment.