Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom matcher runs twice if matcher returns true #115

Open
trinhhunganh opened this issue Sep 10, 2019 · 0 comments
Open

Custom matcher runs twice if matcher returns true #115

trinhhunganh opened this issue Sep 10, 2019 · 0 comments

Comments

@trinhhunganh
Copy link

trinhhunganh commented Sep 10, 2019

I am running stub request test in XCTest and my case is as following:

func testExample() {
        func matchPath(request: URLRequest) -> Bool {
            let path = request.url?.path
            return path != nil // setup a breakpoint on this line and you can see it runs twice
        }

        var responseBodyJson: [String: String] = [:]
        responseBodyJson["appId"] = "1"
        stub(matchPath, json(responseBodyJson, status: 200, headers: nil))
        
        let urlPath: String = "http://www.stackoverflow.com"
        let url: URL = URL(string: urlPath)!
        let request1: URLRequest = URLRequest(url: url)
        let response: AutoreleasingUnsafeMutablePointer<URLResponse?>? = nil
        do{
            let dataVal = try NSURLConnection.sendSynchronousRequest(request1, returning: response)
            print(response)
            do {
                if let jsonResult = try JSONSerialization.jsonObject(with: dataVal, options: []) as? NSDictionary {
                    print("Synchronous\(jsonResult)")
                }
            } catch let error as NSError {
                print(error.localizedDescription)
            }
        }catch let error as NSError
        {
            print(error.localizedDescription)
        }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant