-
Notifications
You must be signed in to change notification settings - Fork 13
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 URL wildcard feature (fixes #47) #53
Conversation
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.
Here are my notes!
README.md
Outdated
@@ -218,6 +218,28 @@ WebValve.register FakeBank, url: ENV.fetch("SOME_CUSTOM_API_URL") | |||
WebValve.register FakeBank, url: "https://some-service.com" | |||
``` | |||
|
|||
## Mocking dynamic URLs with wildcards |
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.
Mocking is probably not the right word - what is?
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.
I might just say "Using wildcards for dynamic URLs"
Barring additional feedback on my newer changes, I think the major outstanding question is whether we're comfy with the level of grossness that the suffix pattern adds to every single URL pattern in webmock. How bad is it that |
mostly correctness repercussions, though, and if you have a couple similar domains/apps it could really mess you up until you figure out what's going on. |
Maybe it happens more around path suffixes honestly if you're treating a bunch of subtrees of an app as different webmock domains. |
Another sub-consideration: if we decide to keep the suffix pattern, since it's a breaking change that somebody might have been taking advantage of (e.g. including the static part of a dynamic token at the end of the URL) is it worth putting a fail-safe change management feature in there, e.g. encoding a Relatedly, you could make the case that the wildcard pattern is a breaking change worthy of a similar fail-safe upgrade pattern because you used to be able to use the |
ebd8901
to
c59fe26
Compare
I took a stab at a post_install_message that discloses both behavior changes and bumped version to 2.0 because of the breaking changes. |
c59fe26
to
6b9c8a9
Compare
If we wanted to go in an entirely different direction we could pursue Addressable templates instead, which would probably look cleaner and have some of the safety I had to engineer into this by default. Addressable templates (mostly? completely?) wrap their dynamic sections in curlies which are relatively unlikely to be present unencoded in URLs. |
Notably with URL templates we'd either have to suffix user-provided URL templates dynamically to enable them to support arbitrary suffixes, or people would have to provide their own suffixes. Could get finicky. The UX of wildcarding is probably easier to understand for somebody who doesn't slice and dice URLs at a framework level for a living. |
Oh maybe middle ground: use wildcard syntax but render as addressable templates? Might be quite a bit fancier on the inside because the template representation of |
I'm fine with being more restrictive. I think that adding the trailing * is a relatively easy fix for anyone in that situation. |
I consider the behavior a bug. Given that there will be a way to restore the behavior, I'm fine with making the breaking changes and doing a major version bump.
Agreed |
@@ -2,48 +2,76 @@ | |||
require 'addressable/template' | |||
|
|||
module WebValve | |||
# @api private |
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.
this reminds me, i gotta do a pass over this library to call private_constants
. will make a note for myself for that too
0d186e9
to
d1f8cb5
Compare
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.
domainlgtm platformlgtm
@ABaldwinHunter since you proposed issue #47 and @slondr since you upvoted, does this feature scratch the itch you're looking to scratch? We're ready to pull the trigger on it but want to do a final check that we didn't build the wrong thing. :) See the README diff for the TL;DR. |
* origin/main: Bump webvalve to 1.3.0 Drop support for older rails and rubies (#54)
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.
domainlgtm
|
Ok, this PR, back in |
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.
domainlgtm platformlgtm
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.
domainlgtm platformlgtm
/domain @samandmoore @Betterment/webvalve-core
/platform @samandmoore @Betterment/webvalve-core
Regexp felt too powerful and would've been a major breaking change, so here's an attempt to sneak in wildcard
*
support without changing the syntax too much. I'll call out some interesting bits in comments.