-
Notifications
You must be signed in to change notification settings - Fork 553
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
UTF-8 Encoding error when matcher fails #668
Comments
@andywatson00 I'm not getting that problem. What http client and what ruby version do you use? Could you please provide a failing code example? |
I am seeing this issue, and I've been working for a few hours to make a failing test case, with little success. The conditions in my app that trigger the problem don't seem to reproduce the problem in the webmock test suite. I have gained some insight, however. So I'd like to share it in case someone can suggest how to construct a failing test for this. During a single test example (I'm using rspec) there may be several requests mocked. If any of them fails to meet the matcher criterion, a text message is shown which accumulates all the stubs and all the actual requests that occurred. This is accumulated in the RequestRegistry#to_s method. Within this error message are included the body contents of post requests. Here is the problem: Encoding::CompatibilityError: It appears to be data dependent, however. In irb I can concatenate utf8 and ascii strings, but I think there may be some strings for which a common encoding is not possible? Does that make sense? I'll keep trying to make a test case, but this triggers anyone's insight, please let me know. |
No sooner did I write the previous comment than I found a way to reproduce the problem. It's not as compact as one might like, I had to incorporate ActiveSupport, and I'm pulling in a utf8 string for post body from a file, just b/c I know it triggers the problem and I haven't found anything shorter to do the same. The failing test is in my fork at https://github.com/lazylester/webmock.git, run rake test to show the problem. Let me know if I can be of any assistance fixing it. Or maybe you'll decide not to fix it as it is really just a misleading error message. |
@lazylester Thank you for investigating this issue. Great job. It would be great to fix this issue, assuming the problem is in WebMock, Unfortunately I don't have time to investigate it any further these days, |
#705 fixes the problem. I decided to fix this as I'm running into it yet again. It comes up in the context of integration testing when there are certain contents in post messages. It's a legitimate question whether this is actually a webmock problem. I'm assuming here that webmock should be able to correctly display a diagnostic message regardless of what is in the body of the post requests. Happy to hear any thoughts to the contrary. |
Not a major bug but I lost a lot of time trying to figure out why my spec was failing, so decided it was worth posting.
So I have a spec using
expect(WebMock).to have_requested(:post, url).with(body: hash_including(expected_values))
and my body included a string with an 'à' character.So my spec was failing due to a completely mundane reason but I had no idea because i kept getting this error
After a lot of debugging it turned out that the problem was not in the matcher as I expected but actually in request_execution_verifier.rb here
Specifically
text << self.class.executed_requests_message
.Before that line is executed
text.encoding = #<Encoding:UTF-8>
andself.class.executed_requests_message.encoding = #<Encoding:ASCII-8BIT>
hence the error.It may be worth catching this or possibly forcing the encoding.
The text was updated successfully, but these errors were encountered: