Latest 0.3.0
Homepage https://github.com/Nisemono/NISERuntimeFake
License MIT
Authors

Version
Platform

What is it?

NISERuntimeFake is an NSObject category which creates fake objects at runtime.

What is does?

It makes fake objects which can have different behaviour than real objects.
You can define different behaviour by overriding implemented instance methods.

How does it work?

  • Create fake object
  • Override instance methods with your implementation
  • Use your fake object in tests

Example:

//Creating fake object
YourClass *fakeObject = [YourClass fake]; 

//Overriding instance method
__block NSString *capturedString;
[fakeObject overrideInstanceMethod:@selector(doSomethingWithString:) withImplementation:^(YourClass *_self, NSString *string){
  capturedString = string;
}];

//Use your fake object as you would normally use a real object
[fakeObject doSomethingWithString:@"Whatever"];

NSLog(@"%@", capturedString); //Output will be "Whatever"

//If you want to make new fake object with original implementation just create new one 
fakeObject = [YourClass fake];

Fake object with protocol example:

//Create fake object with protocol methods
YourClass *fakeObjectWithProtocol = [YourClass fakeObjectWithProtocol:@protocol(YourProtocol) includeOptionalMethods:YES];

Fake class example:

//Create fake class
Class *fakeClass = [YourClass fakeClass];

//Create fake object with cusotm initializer
YourClass *fakeObject = [[fakeYourClass alloc] initWithWhatever:whatever];

Latest podspec

{
    "name": "NISERuntimeFake",
    "version": "0.3.0",
    "license": "MIT",
    "summary": "Library to make fake objects.",
    "description": "This library lets you create fake objects of any class at runtime, which can have different behaviour than real objects. You can define different behaviour by overriding implemented instace methods.",
    "homepage": "https://github.com/Nisemono/NISERuntimeFake",
    "authors": {
        "u0141ukasz Wolau0144czyk": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Nisemono/NISERuntimeFake.git",
        "tag": "0.3.0"
    },
    "source_files": "NISERuntimeFake",
    "requires_arc": true
}

Pin It on Pinterest

Share This