Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Xcode 10.1, Swift 4.1, install [Mockingjay](https://github.com/kylef/Mockingjay) with Cocoapods
// XCTestCase+Stub.swift
import Foundation
import XCTest
import Mockingjay
extension XCTestCase {
/// Web API のリクエストをテストプロジェクトの json でスタブする
///
/// - Parameters:
/// - uriStr: URI
/// - status: ステータスコード
/// - with: 拡張子なしのファイル名
func stub(uri uriStr: String, status: Int = 200, with resource: String) {
let testBundle = Bundle(for: type(of: self))
let path = testBundle.url(forResource: resource, withExtension: "json")
let data: NSData? = try? NSData(contentsOf: path!, options: .uncached)
self.stub(uri(uriStr), jsonData(data! as Data, status: status))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.