Skip to content

Commit

Permalink
Fixed crash with HCArgumentCaptor capturing blocks
Browse files Browse the repository at this point in the history
The fix is to copy the captured argument.
  • Loading branch information
jonreid committed Mar 22, 2018
1 parent 7c18bca commit 4a40c4a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
NEXT RELEASE
------------

**Features:**

- Made OCHamcrest/OCHamcrestIOS into modules, so you can @import them.

**Fixes:**

- Fixed crash with HCArgumentCaptor capturing blocks.


Version 7.0.2
-------------
Expand Down
2 changes: 1 addition & 1 deletion Source/Library/Object/HCArgumentCaptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (void)capture:(id)item
if (self.captureEnabled)
{
id value = item ?: [NSNull null];
[self.values addObject:value];
[self.values addObject:[value copy]];
}
}

Expand Down
11 changes: 10 additions & 1 deletion Source/Tests/Object/HCArgumentCaptorTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)tearDown
- (void)testMatcher_ShouldAlwaysEvaluateToTrue
{
assertMatches(@"nil", sut, nil);
assertMatches(@"unknown object", sut, [[NSObject alloc] init]);
assertMatches(@"some object", sut, @123);
}

- (void)testMatcher_ShouldHaveReadableDescription
Expand All @@ -45,6 +45,15 @@ - (void)testValue_ShouldBeLastCapturedValue
XCTAssertEqualObjects(sut.value, @"BAR");
}

- (void)testValue_ShouldBeCopyIfItCanBeCopied
{
NSMutableString *original = [@"FOO" mutableCopy];

[sut matches:original];

XCTAssertFalse(sut.value == original);
}

- (void)testValue_WithNothingCaptured_ShouldReturnNil
{
XCTAssertNil(sut.value);
Expand Down

0 comments on commit 4a40c4a

Please sign in to comment.