Latest 0.0.4
Homepage https://github.com/feliperuzg/Mimic
License MIT
Platforms ios 10.0
Authors

Mimic is a simple library for stubbing network request.

Integration

Mimic currently only support integration with Cocoapods.

To integrate Mimic into your Xcode project, add the following to your Podfile.

    pod Mimic, ~> '0.0.3'

Usage

Adding new stub

To create a new stub use

@discardableResult public class func mimic(
    request: @escaping MimicRequest,
    delay: TimeInterval = 0,
    response: @escaping MimicResponse
) -> MimicObject

Where MimicRequest is constructed like:

request(with method: MimicHTTPMethod, url: String)

And MimicResponse is constructed like:

response(with json: Any status: Int = 200, headers: String : String]? = nil)

Example:

let stub = Mimic.mimic(
    request: request(with: .get, url: "http://example.com"),
    delay: 2,
    response: response(with: ["response": true], status: 200, headers: ["SomeHeader": "SomeValue"]) 
)

You could also prefer not to store the MimicObject that’s returned, like:

Mimic.mimic(
    request: request(with: .get, url: "http://example.com"),
    delay: 2,
    response: response(with: ["response": true], status: 200, headers: ["SomeHeader": "SomeValue"]) 
)

Removing stubs

To remove a single stub you can use

public class func stopMimic(_ mimic: MimicObject)

For Example:

This will add a new stub

let stub = Mimic(
    request: request(with: .get, url: "http://example.com"),
    delay: 2,
    response: response(with: ["response": true))
)

For removing it you would do:

Mimic.stopMimic(stub)

For removing all stubs call:

Mimic.stopAllMimics()

Testing

To ensure the URLSessionConfiguration swizzle is performed before the request it’s recommended to initialize Mimic first

class myTests: XCTests {
    ...
    // Test properties here
    override func setUp() {
        super.setUp()
        Mimic.start()
        ...
        // Other initializers
    }
    ...
    // Other tests functions
}

Limitations

Mimic only support simple request, it doesn’t support downloading or uploading tasks yet.

Request methods are limited to:

  • GET
  • POST
  • DELETE
  • PUT

Latest podspec

{
    "name": "Mimic",
    "version": "0.0.4",
    "summary": "Networking Stub Solution",
    "description": "Mocking Metwork Solution",
    "homepage": "https://github.com/feliperuzg/Mimic",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Felipe Ruz": "[email protected]"
    },
    "platforms": {
        "ios": "10.0"
    },
    "swift_version": "4.2",
    "source": {
        "git": "https://github.com/feliperuzg/Mimic.git",
        "tag": "0.0.4"
    },
    "source_files": "Mimic/**/*.{swift}"
}

Pin It on Pinterest

Share This