-
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 Absolute url matcher #254
Changes from 3 commits
614683f
450b583
2c721f4
1d69b20
556154b
a5805ad
c2ae76f
54bbc4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# OHHTTPStubs — CHANGELOG | ||
|
||
## Master | ||
Added absoulte url matcher. | ||
[@victorg1991](https://github.com/victorg1991 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo here, missing closing parenthesis ✏️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dish! I'll fix tha in a minute : D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 👍 |
||
[#252](https://github.com/AliSoftware/OHHTTPStubs/pull/252) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of this PR is 254 😉 |
||
* Fixed up empty lines with whitespace inside test case classes. | ||
[@mikelupo](https://github.com/mikelupo | ||
[#251](https://github.com/AliSoftware/OHHTTPStubs/pull/251) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,20 @@ public func isMethodDELETE() -> OHHTTPStubsTestBlock { | |
return { $0.httpMethod == "DELETE" } | ||
} | ||
|
||
/** | ||
* Matcher for testing an `NSURLRequest`'s **absolute url**. | ||
* | ||
* e.g. the absolute url is `https://api.example.com/signin` in `https://api.example.com/signin` | ||
* | ||
* - Parameter scheme: The absolute url to match | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* - Returns: a matcher (OHHTTPStubsTestBlock) that succeeds only if the request | ||
* has the given absolute url | ||
*/ | ||
public func isAbsoluteUrl(_ url: String) -> OHHTTPStubsTestBlock { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering if this should not be called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally. We tried to name most if not all our matchers from the name of the method we call underneath to make the relationship clear, use common vocabulary and avoid confusion so let's try to continue that way 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I rename to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah seems like a good compromise 👍 |
||
return { req in req.url?.absoluteString == url } | ||
} | ||
|
||
/** | ||
* Matcher for testing an `NSURLRequest`'s **scheme**. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,28 @@ class SwiftHelpersTests : XCTestCase { | |
} | ||
} | ||
|
||
func testIsAbsoluteUrl() { | ||
let matcher = isAbsoluteUrl("foo://foo/bar") | ||
|
||
let urls = [ | ||
"foo:": false, | ||
"foo://foo/bar/baz": false, | ||
"foo://foo/bar": true, | ||
"bar://foo/bar": false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add one or two more complex examples, I'm especially thinking about URLs with query parameters and anchors etc |
||
"bar://foo/ba": false, | ||
"foobar://": false | ||
] | ||
|
||
for (url, result) in urls { | ||
#if swift(>=3.0) | ||
let req = URLRequest(url: URL(string: url)!) | ||
#else | ||
let req = NSURLRequest(URL: NSURL(string: url)!) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR directly, but I see we have that pattern on multiple tests: maybe we should add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree. But I think this should be in another PR. |
||
#endif | ||
XCTAssert(matcher(req) == result, "isAbsoluteUrl(\"foo://foo/bar\") matcher failed when testing url \(url)") | ||
} | ||
} | ||
|
||
func testIsScheme() { | ||
let matcher = isScheme("foo") | ||
|
||
|
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.
Small typo here ✏️
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.
done!