CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.

Stubborn 0.7.3

Stubborn 0.7.3

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2018
SPMSupports SPM

Maintained by Mattias Eriksson.



Stubborn 0.7.3

  • By
  • Mattias Eriksson

Simple HTTP mocking framework.

Install

pod 'Stubborn'

Usage

Start

This is done automatically when you add a stub

Stubborn.start()

Success

Stubborn.add(url: ".*/users") { request in
    print(request.method)
    print(request.url)
    print(request.body)
    print(request.headers)
    print(request.queryString)
    print(request.numberOfRequests)

    return [
        "users": [
            [
                "id": 123,
                "username": "materik"
            ],
            [
                "id": 124,
                "username": "leo"
            ]
        ]
    ]
}

Failure

Stubborn.add(url: ".*/users", error: Stubborn.Error(400, "Something went wrong"))

Delayed

Wait a second before responding

1  Stubborn.add(url: ".*/users", dictionary: ["success": true])

From JSON file

Stubborn.add(url: ".*/users", resource: "MyResponse")

Handle unhandled requests

Stubborn.unhandledRequest { request in
    print(request.method)
    print(request.url)
    print(request.body)
    print(request.headers)
    print(request.queryString)
}

Reset

Stubborn.reset()

Example

QueryString(key: "page", value: "1")  Stubborn.add(url: ".*/get", dictionary: ["result": 1])
QueryString(key: "page", value: "2")  Stubborn.add(url: ".*/get", dictionary: ["result": 2])

Alamofire.request("https://httpbin.org/get?page=1").responseJSON {
print($0.value) // ["result": 1]
}

Alamofire.request("https://httpbin.org/get?page=2").responseJSON {
print($0.value) // ["result": 2]    
}