Source

OCMock-dld-patches / responds-to.patch

diff --git a/Source/OCClassMockObject.m b/Source/OCClassMockObject.m
--- a/Source/OCClassMockObject.m
+++ b/Source/OCClassMockObject.m
@@ -39,4 +39,9 @@
 	return [mockedClass instanceMethodSignatureForSelector:aSelector];
 }
 
+- (BOOL)respondsToSelector:(SEL)selector
+{
+    return [mockedClass instancesRespondToSelector:selector];
+}
+
 @end
diff --git a/Source/OCMockObject.m b/Source/OCMockObject.m
--- a/Source/OCMockObject.m
+++ b/Source/OCMockObject.m
@@ -163,7 +163,6 @@
 	
 }
 
-
 //---------------------------------------------------------------------------------------
 //	descriptions
 //---------------------------------------------------------------------------------------
diff --git a/Source/OCMockObjectTests.m b/Source/OCMockObjectTests.m
--- a/Source/OCMockObjectTests.m
+++ b/Source/OCMockObjectTests.m
@@ -9,6 +9,8 @@
 
 @protocol TestProtocol
 - (int)primitiveValue;
+@optional
+- (id)objectValue;
 @end
 
 @protocol ProtocolWithTypeQualifierMethod
@@ -29,7 +31,6 @@
 	[[mock stub] lowercaseString];
 	[mock lowercaseString];
 }
-
 
 - (void)testRaisesExceptionWhenUnknownMethodIsCalled
 {
@@ -293,6 +294,15 @@
 	STAssertEqualObjects(@"SomeValue", returnValue, @"Should have returned value that was set up.");
 }
 
+- (void)testRespondsToValidSelector
+{
+    STAssertTrue([mock respondsToSelector:@selector(lowercaseString)], nil);
+}
+
+- (void)testDoesNotRespondToInvalidSelector
+{
+    STAssertFalse([mock respondsToSelector:@selector(fooBar)], nil);
+}
 
 - (void)testCanMockFormalProtocol
 {
@@ -347,6 +357,24 @@
 	STAssertThrows([mock verify], @"Should have raised an exception because method was not called.");
 }
 
+- (void)testRespondsToValidProtocolRequiredSelector
+{
+	mock = [OCMockObject niceMockForProtocol:@protocol(TestProtocol)];	
+    STAssertTrue([mock respondsToSelector:@selector(primitiveValue)], nil);
+}
+
+- (void)testRespondsToValidProtocolOptionalSelector
+{
+	mock = [OCMockObject niceMockForProtocol:@protocol(TestProtocol)];	
+    STAssertTrue([mock respondsToSelector:@selector(objectValue)], nil);
+}
+
+- (void)testDoesNotRespondToInvalidProtocolSelector
+{
+	mock = [OCMockObject niceMockForProtocol:@protocol(TestProtocol)];	
+    STAssertFalse([mock respondsToSelector:@selector(fooBar)], nil);
+}
+
 - (void)testReRaisesFailFastExceptionsOnVerify
 {
 	@try