Skip to content

Commit

Permalink
Deprecated MKTArgumentCaptor and MKTCapturingMatcher; use HCArgumentC…
Browse files Browse the repository at this point in the history
…aptor from OCHamcrest v4.3.0 for capturing arguments.
  • Loading branch information
jonreid committed Oct 14, 2015
1 parent 0b66cd1 commit ac76599
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ NEXT VERSION - breaking change
prevents retain cycles and crashes during test clean-up. See StopMockingTests.m for an example.
- NSInvocation+OCMockito.h is now imported by OCMockito.h, so it no longer needs a separate import.

**Deprecated:**

- Deprecated MKTArgumentCaptor and MKTCapturingMatcher; use HCArgumentCaptor from OCHamcrest for
capturing arguments.


Version 1.4.0
-------------
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,18 @@ In some situations though, it's helpful to assert on certain arguments after the
actual verification. For example:
```obj-c
MKTArgumentCaptor *argument = [[MKTArgumentCaptor alloc] init];
[verify(mockObject) doSomething:[argument capture]];
assertThat([[argument value] nameAtIndex:0], is(@"Jon"));
HCArgumentCaptor *argument = [[HCArgumentCaptor alloc] init];
[verify(mockObject) doSomething:(id)argument];
assertThat([argument.value nameAtIndex:0], is(@"Jon"));
```

Capturing arguments is especially handy for block arguments. You can capture a
block, then invoke it within your test:

```obj-c
MKTArgumentCaptor *argument = [[MKTArgumentCaptor alloc] init];
[verify(mockArray) sortUsingComparator:[argument capture]];
NSComparator block = [argument value];
HCArgumentCaptor *argument = [[HCArgumentCaptor alloc] init];
[verify(mockArray) sortUsingComparator:(id)argument];
NSComparator block = argument.value;
assertThat(@(block(@"a", @"z")), is(@(NSOrderedAscending)));
```
Expand Down
4 changes: 4 additions & 0 deletions Source/OCMockito/Matchers/MKTArgumentCaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#import <Foundation/Foundation.h>


/*!
* @deprecated Version 2.0.0 Use HCArgumentCaptor instead.
*/
__attribute__ ((deprecated))
@interface MKTArgumentCaptor : NSObject

- (id)capture;
Expand Down
4 changes: 4 additions & 0 deletions Source/OCMockito/Matchers/MKTCapturingMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#import <OCHamcrest/HCIsAnything.h>


/*!
* @deprecated Version 2.0.0 Use HCArgumentCaptor instead.
*/
__attribute__ ((deprecated))
@interface MKTCapturingMatcher : HCIsAnything

- (NSArray *)allValues;
Expand Down
6 changes: 3 additions & 3 deletions Source/Tests/BlockMatchingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ - (void)testMockingMethodWithBlockArg_WithNotNilValueMatcher_ShouldMatchBlock

- (void)testMockingMethodWithBlockArg_WithArgumentCaptor_ShouldLetYouExecuteCapturedBlock
{
MKTArgumentCaptor *argument = [[MKTArgumentCaptor alloc] init];
HCArgumentCaptor *argument = [[HCArgumentCaptor alloc] init];

[mockObj doBlock:^NSString * {
return @"SUCCESS";
}];
[verify(mockObj) doBlock:[argument capture]];
[verify(mockObj) doBlock:(id)argument];

BlockReturningString block = [argument value];
BlockReturningString block = argument.value;
assertThat(block(), is(@"SUCCESS"));
}

Expand Down

0 comments on commit ac76599

Please sign in to comment.