Skip to content

Add Absolute url matcher#254

Merged
Liquidsoul merged 8 commits into
AliSoftware:masterfrom
victorg1991:master
Jun 12, 2017
Merged

Add Absolute url matcher#254
Liquidsoul merged 8 commits into
AliSoftware:masterfrom
victorg1991:master

Conversation

@victorg1991

@victorg1991 victorg1991 commented Jun 9, 2017

Copy link
Copy Markdown
Contributor

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

This PR adds a matcher for the url matcher

Motivation and Context

Sometimes it's useful to match urls by the absolute url

I've created a test to changes the changes and run all the test 100% success

@Liquidsoul Liquidsoul left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @victorg1991

Thank you for your contribution following the guidelines and templates 🎉

I am wondering if we should add this new function as-is or if it should be renamed.
Let's summon @AliSoftware to see what he thinks about that 😁

Comment thread CHANGELOG.md Outdated
# OHHTTPStubs — CHANGELOG

## Master
Added absoulte url matcher.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo here ✏️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Comment thread CHANGELOG.md Outdated
## Master
Added absoulte url matcher.
[@victorg1991](https://github.com/victorg1991
[#252](https://github.com/AliSoftware/OHHTTPStubs/pull/252)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of this PR is 254 😉

*
* - Returns: a matcher (OHHTTPStubsTestBlock) that succeeds only if the request
* has the given absolute url
*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if this should not be called isAbsoluteString to match the URL member we call underneath, because there is a URL.absoluteURL
🤔

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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 😉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that isAbsoluteUrl has more meaning than the other option, but its up to you.
Do I have to change to isAbsoluteString? I could also do something like URL.absoluteURL.absoluteString ¯_(ツ)_/¯ haha
What do you think?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with isAbsoluteUrl is also that it doesn't follow the Swift naming convention, letting us believe that the expected parameter is an URL and not a String.
Otoh just "isAbsoluteString" without context (as it's a free function, not a method on a tour) is also ambiguous… maybe isAbsoluteURLString? But might be too long. Tbh I honestly don't know what's best suited (especially at 0:30am 😅)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer isAbsoluteURLString over isAbsoluteString, it doesn't sound too bad :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I rename to isAbsoluteURLString? @AliSoftware

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah seems like a good compromise 👍

Comment thread CHANGELOG.md Outdated

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget the * to create a bullet point

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a more contrived example like with x=1&y=2#anchor query + anchor?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter url:

*
* - Returns: a matcher (OHHTTPStubsTestBlock) that succeeds only if the request
* has the given absolute url
*/

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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 😉

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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

@victorg1991

Copy link
Copy Markdown
Contributor Author

Done!

@Liquidsoul Liquidsoul left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a typo in the CHANGELOG I missed earlier and I think we should be good to go 😃

Comment thread CHANGELOG.md Outdated

## Master
* Added absolute url matcher.
[@victorg1991](https://github.com/victorg1991

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here, missing closing parenthesis ✏️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dish! I'll fix tha in a minute : D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

#if swift(>=3.0)
let req = URLRequest(url: URL(string: url)!)
#else
let req = NSURLRequest(URL: NSURL(string: url)!)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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 func request(from string: String) -> URLRequest helper function for our tests, responsible for handling Swift 2/3 compatibility, and use that in our test cases to avoid repeating those #if Swift(>=3.0) everywhere? (Might be a separate PR though)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. But I think this should be in another PR.

@Liquidsoul Liquidsoul merged commit 499c505 into AliSoftware:master Jun 12, 2017
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.

3 participants