Last active
January 30, 2019 03:47
-
-
Save enomoto/9e16bc34b70b616718bf91992406b9eb to your computer and use it in GitHub Desktop.
Xcode 10.1, Swift 4.1, install [Mockingjay](https://github.com/kylef/Mockingjay) with Cocoapods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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