Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stubbing the protocol return as Nil #151

Open
AyeChanPyaeSone opened this issue Oct 1, 2018 · 3 comments
Open

Stubbing the protocol return as Nil #151

AyeChanPyaeSone opened this issue Oct 1, 2018 · 3 comments

Comments

@AyeChanPyaeSone
Copy link

I've tried to stub the protocol method but it return as nil. Please check the following code.

@protocol Client
- (Account* _Nullable) login:(nullable NSString*)username
                                        password:(nonnull NSData*)login;

And I have a object called ClientImplementation that implements Client protocol.

In my testcase, I mock the class like this in setup().

@property(nonatomic, strong) ClientImplementation<Client> *mockClient;
 self.mockClient =  mockObjectAndProtocol([ClientImplementation class],@protocol(Client));

But when i Stub the method it return as nil.

Account *account = [[Account alloc]init];
    account.name = @"fdsafdsfs";
    [given([self.mockClient login:@""passwrod:anything()]) willReturn:account];

May I know what did i do wrong?

@jonreid
Copy link
Owner

jonreid commented Dec 31, 2018

I'm sorry you've waited so long for an answer — I don't seem to be receiving any notifications from GitHub.

For all mocked methods, nil is returned unless the given condition is met. My guess is that there's something about your given that doesn't match what your code calls. You are using anything() to match any password argument, so that's fine. Is the code passing empty string for login?

@jasongrlicky
Copy link

I just wanted to mention that I've had the same problem when the matched-against or returned objects are typedefs. Might give a clue about what's going on?

@jonreid
Copy link
Owner

jonreid commented Feb 8, 2020

Thank you, @jasongrlicky. If you get a chance and are able to boil it down to an executable example, that would be really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants