Skip to content

Commit

Permalink
forces encoding to UTF for a spec fix
Browse files Browse the repository at this point in the history
  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.
  • Loading branch information
davidbegin committed Dec 23, 2015
1 parent ea6bde3 commit 4016323
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
7 changes: 0 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,3 @@ end
platforms :jruby do
gem 'jruby-openssl'
end

if (RUBY_VERSION > '1.8.7' && (defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby")) ||
(defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby")
gem 'addressable', '>= 2.3.6'
else
gem 'addressable', '< 2.4.0'
end
13 changes: 11 additions & 2 deletions spec/acceptance/shared/allowing_and_disabling_net_connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@

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
if result.respond_to? :encode
result = result.encode(
'UTF-8',
'binary',
:invalid => :replace,
:undef => :replace,
:replace => ''
)
end
expect(result).to match(/.*google.*/)
end
end

Expand Down
10 changes: 8 additions & 2 deletions webmock.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ Gem::Specification.new do |s|

s.rubyforge_project = 'webmock'

patron_version = (RUBY_VERSION <= '1.8.7') ? '0.4.18' : '>= 0.4.18'
addressable_version = if RUBY_VERSION > '1.8.7' || (defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby")
'>= 2.3.6'
else
'< 2.4.0'
end

s.add_dependency 'addressable', addressable_version
s.add_dependency 'crack', '>=0.3.2'
s.add_dependency 'hashdiff'

patron_version = (RUBY_VERSION <= '1.8.7') ? '0.4.18' : '>= 0.4.18'

s.add_development_dependency 'rspec', '>= 3.1.0'
s.add_development_dependency 'httpclient', '>= 2.2.4'
s.add_development_dependency('patron', patron_version) unless RUBY_PLATFORM =~ /java/
Expand Down

0 comments on commit 4016323

Please sign in to comment.