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
can't stub request #787
Comments
@Asdfif - Great question, I think you may have identified an edge case where the matching to stubs is overly strict that we should probably fix up. When that stub is created, it parses the URL and it looks like it interprets the path as being a blank string, whereas when the call is made it defaults to a path of I can work on a patch some time in the near future, but in the mean time you can also work around this problem by being explicit with the path when you create the stub (by adding a Hope that helps, let me know if you have questions and I'll update this if/when I get a chance to fix and release. |
@geemus It works. Thank you! |
@geemus but if i need to stub request like this |
i try to use Regexp |
@Asdfif great question. The stubs are setup so that if you specify a nil value, it will match anything. So that might be the easiest. So one option would be something like:
By specifying host/scheme/port directly it avoids the URI parsing (which is where we ended up with the path issues before). This particular example say that anything matching that host/scheme/port should get that response (and since path is not specified, ANY path should get that response). Conversely, you can use a regex here, but similarly I think you need to do it in the context of the parsed params (instead of the url). So in that case it might look like:
That should match anything that matches the host/scheme/port and has a path containing one or more digits. Does that answer your question? |
it works, thank you <3 |
@Asdfif glad that got you what you needed. Thanks for asking and discussing. I think I have a bug to fix for the first case (I would expect a url with no path to match there, and I think most other people would too). I can try to find some time soon, I'll have to think about how best to do it. Since there is a pretty straightforward work around, I'm also not as worried or hurried. That and your subsequent questions make me feel like we probably have a lot of room to improve the documentation around stubs in the README as well though. I'd certainly welcome your help there. I'd love to hear if you have suggestions on how we could make that clearer and more accurate, or would love even more if you would be up for helping us with a pull request to improve the documentation. Thanks! |
This issue has been marked inactive and will be closed if no further activity occurs. |
I stub request
Excon.stub({url: 'http://example.com'}, {:body => 'body', :status => 200})
Then i send request
Excon.get('http://example.com', mock: true)
And i got an error
Excon::Error::StubNotFound: no stubs matched
Why? I can't find answer on stack over flow.
Help me please
The text was updated successfully, but these errors were encountered: