From e6b5764161f421704047a6155ab774d993acb522 Mon Sep 17 00:00:00 2001 From: David Begin Date: Wed, 23 Dec 2015 00:18:26 -0800 Subject: [PATCH] forces encoding to UTF for a spec fix For some reason on JRuby this spec started causing a ArgumentError: Invalid byte sequence in UTF-8 The failing spec is ensuring that when WebMock is off, it is possible to query to a real website, in this case google. The spec queries google, and then ensures the body of the response contains google. So all this fix does is force the response to be UTF, and get rid of any invalid characters. So now match can check for google in the provided string, without worrying about invalid characters it doesn't know how to handle. While knowing why we have to suddenly force encoding would be ideal, we know this change does not affect the integrity of the spec. --- .../shared/allowing_and_disabling_net_connect.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/shared/allowing_and_disabling_net_connect.rb b/spec/acceptance/shared/allowing_and_disabling_net_connect.rb index b049281bf..cf38e58d4 100644 --- a/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +++ b/spec/acceptance/shared/allowing_and_disabling_net_connect.rb @@ -11,8 +11,15 @@ it "should make a real https request if request is not stubbed" do unless http_library == :httpclient - expect(http_request(:get, "https://www.google.com/"). - body).to match(/.*google.*/) + result = http_request(:get, "https://www.google.com/").body + result = result.encode( + 'UTF-8', + 'binary', + :invalid => :replace, + :undef => :replace, + :replace => '' + ) + expect(result).to match(/.*google.*/) end end