Skip to content

Library for unifying the approach to network mocking in iOS unit- & UI-tests.

License

Notifications You must be signed in to change notification settings

tinkoff-mobile-tech/TinkoffMockStrapping

Repository files navigation

TinkoffMockStrapping

Version License Platform

How to install?

TinkoffMockStrapping is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'TinkoffMockStrapping', :git => 'https://github.com/tinkoff-mobile-tech/TinkoffMockStrapping.git'

If you want to use TinkoffMockStrapping with Swifter, add the following line to your Podfile:

pod 'TinkoffMockStrapping/Swifter', :git => 'https://github.com/tinkoff-mobile-tech/TinkoffMockStrapping.git'

How to init the server?

lazy var mockServer = MockNetworkServer()

How to init the request?

let stubRequest = NetworkStubRequest(url: "someUrlAsString", httpMethod: .GET)

GET method is written above as an examle. We support all http methods, and you can use any of them. You can see them here. ANY is a default parameter and means that method doesn't matter for you.

How to init the response?

let stubResponse = NetworkStubResponse.json(json)

We use SwiftyJSON, so json from the example above is an instance of JSON.

If you need to create a response with pdf, png etc, simply use data case instead.

How to init the stub?

let stub = NetworkStub(request: stubRequest, response: stubResponse)
mockServer.setStub(stub)

Query? Sure

let query = ["query1": "1", "query2": "2"]
let stubRequest = NetworkStubRequest(url: "someUrlAsString",
                                     query: query,
                                     httpMethod: .GET)

Also we provide excludedQuery. If you don't want to see some parameters in your request, use this option.

Delay? Yes

let delayInSeconds: TimeInterval = 5
let stub = NetworkStub(request: stubRequest, response: stubResponse, delay: delayInSeconds)

History

If you want to know which requests were called, you can use history. Simply use functions from MockNetworkHistoryProtocol

Authors

License

TinkoffMockStrapping is available under the Apache License 2.0. See the LICENSE file for more info.

About

Library for unifying the approach to network mocking in iOS unit- & UI-tests.

Resources

License

Stars

Watchers

Forks

Packages

No packages published