-
Notifications
You must be signed in to change notification settings - Fork 601
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
Add precondition assertions in scheme, host matchers #248
Conversation
Also added an explanation of which part it is in an example URL.
* - Parameter scheme: The scheme to match | ||
* | ||
* - Returns: a matcher (OHHTTPStubsTestBlock) that succeeds only if the request | ||
* has the given scheme | ||
*/ | ||
public func isScheme(_ scheme: String) -> OHHTTPStubsTestBlock { | ||
precondition(!scheme.contains("://"), "The scheme part of an URL never contains '://'. Only use strings like 'https' for this value, and not things like 'https://'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like contains
was not available in Swift 2.3 🙄 Maybe add an extension String
in the #if !swift(>=3.0)
block at the top of this file to add support for it?
OHHTTPStubs/OHHTTPStubs/Sources/Swift/OHHTTPStubsSwift.swift
Lines 30 to 55 in 5956336
#if !swift(>=3.0) | |
extension OHHTTPStubs { | |
private class func stubRequests(passingTest passingTest: OHHTTPStubsTestBlock, withStubResponse: OHHTTPStubsResponseBlock) -> OHHTTPStubsDescriptor { | |
return stubRequestsPassingTest(passingTest, withStubResponse: withStubResponse) | |
} | |
} | |
extension NSURLRequest { | |
var httpMethod: String? { return HTTPMethod } | |
var url: NSURL? { return URL } | |
} | |
extension NSURLComponents { | |
private convenience init?(url: NSURL, resolvingAgainstBaseURL: Bool) { | |
self.init(URL: url, resolvingAgainstBaseURL: resolvingAgainstBaseURL) | |
} | |
} | |
private typealias URLRequest = NSURLRequest | |
extension URLRequest { | |
private func value(forHTTPHeaderField key: String) -> String? { | |
return valueForHTTPHeaderField(key) | |
} | |
} | |
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup saw that, I'll look into it later as soon as I can 😉
This is because NSString.containsString is only available since OSX 10.10.
Also added an explanation of which part it is in an example URL.
Checklist
Description
Add preconditions so that user are better informed of why their requests are not stubbed.
This also adds information of what is a scheme, host or path in the documentation of each matcher.
Motivation and Context
This will help users see why their matchers setup does not work (see #247).