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

Add precondition assertions in scheme, host matchers #248

Merged
merged 4 commits into from
May 17, 2017

Conversation

Liquidsoul
Copy link
Collaborator

Also added an explanation of which part it is in an example URL.

Checklist

  • I've checked that all new and existing tests pass
  • I've updated the documentation if necessary
  • I've added an entry in the CHANGELOG to credit myself

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).

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://'")
Copy link
Owner

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?

#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

Copy link
Collaborator Author

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 😉

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

Successfully merging this pull request may close these issues.

2 participants