diff --git a/spec/integration/_lib.rb b/spec/integration/_lib.rb new file mode 100644 index 0000000..935238d --- /dev/null +++ b/spec/integration/_lib.rb @@ -0,0 +1 @@ +require_relative '../spec_helper' diff --git a/spec/integration/integration_spec.rb b/spec/integration/integration_spec.rb index 5327614..23eb5c3 100644 --- a/spec/integration/integration_spec.rb +++ b/spec/integration/integration_spec.rb @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -require 'spec_helper' +require_relative '_lib' describe RestClient do @@ -69,5 +69,22 @@ describe RestClient do }.should raise_error(Encoding::UndefinedConversionError) response.valid_encoding?.should eq true end + + it 'handles euc-jp' do + body = "\xA4\xA2\xA4\xA4\xA4\xA6\xA4\xA8\xA4\xAA". + force_encoding(Encoding::BINARY) + body_utf8 = 'あいうえお' + body_utf8.encoding.should eq Encoding::UTF_8 + + stub_request(:get, 'www.example.com').to_return( + :body => body, :status => 200, :headers => { + 'Content-Type' => 'text/plain; charset=EUC-JP' + }) + response = RestClient.get 'www.example.com' + response.encoding.should eq Encoding::EUC_JP + response.valid_encoding?.should eq true + response.length.should eq 5 + response.encode('utf-8').should eq body_utf8 + end end end diff --git a/spec/integration/request_spec.rb b/spec/integration/request_spec.rb index 629c0a7..b95e26f 100644 --- a/spec/integration/request_spec.rb +++ b/spec/integration/request_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require_relative '_lib' describe RestClient::Request do before(:all) do