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
Stubbing With String or Regex #317
Comments
Also note: I realize I could have used |
It was intended, though unfortunate behaviour. Matching requests using If you are using regexp to match uri, WebMock basically tries match uri string against the regexp. It does it in a robust way, which matches uris with different order of params etc, but that's not relevant. When you are using string to match uri, WebMock also does it in a robust way, but expects full uri, including params. Early version of WebMock assumed that the only way to match uri is to pass the whole uri to It's one of the things that I'd like to change in the next major release of WebMock. Many people were already confuses about this behaviour. Unfortunately I don't have much time to work on WebMock 2.0 on my own. maybe it's time to move project under github.com/webmock/webmock |
Yeah. For now, I'm just using regexes when I need to do something dynamic with queries. Some context: What I need, ideally, is some way to capture a query parameter that my app sends out and make sure that it's used in subsequent requests. Imagine that it's an id value from a SQL table for a new row (and so doesn't exist to predict prior to the test running). What I'd love to be able to do is something like: WebMock.stub_request(:post, "http://example.com/resources").with do |request|
@uid = request.uri.query_values['uid']
request.uri.query_values.keys.sort == ['uid', 'name']
end
WebMock.stub_request(:get, "http://example.com/resources/#{@uid}/subresources") ...and have the uid thing lazily interpolated... but right now (with regex instead of string), |
@benhamill Wrap your ID generator in a class/method that you stub for testing, e.g. UUID generates random UUIDs, but for testing purposes, I stub it out to a static string. Then you know the ID a priori. |
using
with
with a block seems to behave differently when you pass a regexp versus a string. Example script:The output:
Is this intended behavior? If not, shall I see if I can solve it and turn this into a Pull Request?
The text was updated successfully, but these errors were encountered: