Skip to content

Instantly share code, notes, and snippets.

@epologee
Last active January 3, 2016 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epologee/8518443 to your computer and use it in GitHub Desktop.
Save epologee/8518443 to your computer and use it in GitHub Desktop.
I deleted the fork of allending/Kiwi that this patch was originally created with, because the pull request was not merged and there was no use to keep the fork around. In case someone cares to have a look at it, here's the patch.
From 4cde2c8b86131466ba6902b08b037d689eb44f8f Mon Sep 17 00:00:00 2001
From: Eric-Paul Lecluse <...>
Date: Fri, 10 Jan 2014 11:01:48 +0100
Subject: [PATCH] Re-introduced a property to check whether an argument was
captured on KWCaptureSpy
---
Classes/Core/KWCaptureSpy.h | 1 +
Classes/Core/KWCaptureSpy.m | 5 ++++-
Tests/KWCaptureTest.m | 11 +++++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/Classes/Core/KWCaptureSpy.h b/Classes/Core/KWCaptureSpy.h
index de5b657..3a4afec 100644
--- a/Classes/Core/KWCaptureSpy.h
+++ b/Classes/Core/KWCaptureSpy.h
@@ -3,6 +3,7 @@
@interface KWCaptureSpy : NSObject<KWMessageSpying>
@property (nonatomic, strong, readonly) id argument;
+@property (nonatomic, readonly, getter=isCaptured) BOOL captured;
- (id)initWithArgumentIndex:(NSUInteger)index;
diff --git a/Classes/Core/KWCaptureSpy.m b/Classes/Core/KWCaptureSpy.m
index a90af61..dd95190 100644
--- a/Classes/Core/KWCaptureSpy.m
+++ b/Classes/Core/KWCaptureSpy.m
@@ -9,6 +9,7 @@
@interface KWCaptureSpy()
@property (nonatomic, strong) id argument;
+@property (nonatomic, readwrite, getter=isCaptured) BOOL captured;
@end
@@ -25,7 +26,7 @@
}
- (id)argument {
- if (!_argument) {
+ if (!_captured) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Argument requested has yet to be captured." userInfo:nil];
}
@@ -58,6 +59,8 @@
NSData *data = [anInvocation messageArgumentDataAtIndex:_argumentIndex];
_argument = [KWValue valueWithBytes:[data bytes] objCType:objCType];
}
+
+ _captured = YES;
}
}
diff --git a/Tests/KWCaptureTest.m b/Tests/KWCaptureTest.m
index 8f1a93f..73eff07 100644
--- a/Tests/KWCaptureTest.m
+++ b/Tests/KWCaptureTest.m
@@ -92,6 +92,17 @@
STAssertThrows([spy argument], @"Should have raised an exception");
}
+- (void)testShouldTellWhetherAnArgumentIsCaptured {
+ id robotMock = [KWMock nullMockForClass:[Robot class]];
+ KWCaptureSpy *spy = [robotMock captureArgument:@selector(speak:afterDelay:whenDone:) atIndex:1];
+
+ STAssertEquals([spy isCaptured], NO, @"Captured flag should be 'NO'");
+ [robotMock speak:@"Hello" afterDelay:2 whenDone:^{}];
+
+ STAssertEquals([spy isCaptured], YES, @"isCaptured flag should be 'YES'");
+ STAssertNotNil(spy.argument, @"Captured argument should not be nil");
+}
+
- (void)testAddSpyConvenienceMethodOnNSObject {
Robot *robot = [[Robot alloc] init];
KWCaptureSpy *spy = [robot captureArgument:@selector(speak:) atIndex:0];
--
1.8.3.4 (Apple Git-47)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment