jonreid / OCMockito

Mockito for Objective-C: creation, verification and stubbing of mock objects
MIT License
991 stars 118 forks source link

Stubs return nil when verifying #165

Closed dalef84 closed 2 years ago

dalef84 commented 2 years ago

Stubs return nil when verifying

Introduced by https://github.com/jonreid/OCMockito/pull/164. Release v7.0.0

Please see test below for an example.

#import "OCMockito.h"

#import "MockTestCase.h"
#import <OCHamcrest/OCHamcrest.h>
@import XCTest;

@interface C: NSObject
@property (nonatomic, copy) NSString *text;
@end

@implementation C
@end

@interface B: NSObject
- (void)processStringFromC:(NSString *)string;
@end

@implementation B
- (void)processStringFromC:(NSString *)string { }
@end

@interface VerifyAndStubTests : XCTestCase
@end

@implementation VerifyAndStubTests
{
    MockTestCase *mockTestCase;
}

- (void)setUp
{
    [super setUp];
    mockTestCase = [[MockTestCase alloc] init];
}

- (void)testStub_whileVerify
{
    // Given
    B *b = mock(B.class);
    C *c = mock(C.class);

    [given(c.text) willReturn:@"test"];

    // When
    [b processStringFromC:c.text];

    // Then
    [verifyWithMockTestCase(b, mockTestCase) processStringFromC:c.text];
    assertThat(@(mockTestCase.failureCount), is(@0));
    NSLog(@"mockTestCase.failureDescription: %@", mockTestCase.failureDescription);
}

@end
dalef84 commented 2 years ago

Sorry @jonreid I don't have time ATM to take a deeper look into the code and understand how my fix caused this issue. Maybe I'll be able to in a couple of weeks.

dalef84 commented 2 years ago

@jonreid thanks for checking this out. When do you estimate there'll be a new release with this change, and others, included?

jonreid commented 2 years ago

It's out! https://github.com/jonreid/OCMockito/releases/tag/v7.0.1