diff --git a/.rubocop.yml b/.rubocop.yml index 82a8d4e8..e5ed0589 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -55,6 +55,9 @@ Style/EachWithObject: Style/Encoding: Enabled: false +Style/EmptyCaseCondition: + Enabled: false + Style/HashSyntax: EnforcedStyle: hash_rockets diff --git a/Gemfile b/Gemfile index 6beced55..288076c9 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,7 @@ group :test do gem "coveralls" gem "simplecov", ">= 0.9" gem "json", ">= 1.8.1" - gem "rubocop", "= 0.39.0" + gem "rubocop", "= 0.40.0" gem "rspec", "~> 3.0" gem "rspec-its" gem "yardstick" diff --git a/lib/http.rb b/lib/http.rb index ab4a94c2..4e17d2ea 100644 --- a/lib/http.rb +++ b/lib/http.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "http/parser" require "http/errors" diff --git a/lib/http/content_type.rb b/lib/http/content_type.rb index 056ca4b9..a7318861 100644 --- a/lib/http/content_type.rb +++ b/lib/http/content_type.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module HTTP ContentType = Struct.new(:mime_type, :charset) do MIME_TYPE_RE = %r{^([^/]+/[^;]+)(?:$|;)} diff --git a/lib/http/errors.rb b/lib/http/errors.rb index 199fff1e..8a1fc260 100644 --- a/lib/http/errors.rb +++ b/lib/http/errors.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module HTTP # Generic error class Error < StandardError; end diff --git a/lib/http/headers.rb b/lib/http/headers.rb index 97229182..fce7027f 100644 --- a/lib/http/headers.rb +++ b/lib/http/headers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "forwardable" require "http/errors" diff --git a/lib/http/headers/mixin.rb b/lib/http/headers/mixin.rb index 1a947002..9aa95136 100644 --- a/lib/http/headers/mixin.rb +++ b/lib/http/headers/mixin.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "forwardable" module HTTP diff --git a/lib/http/mime_type.rb b/lib/http/mime_type.rb index 3cefba1a..47a1f145 100644 --- a/lib/http/mime_type.rb +++ b/lib/http/mime_type.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module HTTP # MIME type encode/decode adapters module MimeType diff --git a/lib/http/mime_type/adapter.rb b/lib/http/mime_type/adapter.rb index ed6c4989..14668969 100644 --- a/lib/http/mime_type/adapter.rb +++ b/lib/http/mime_type/adapter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "forwardable" require "singleton" diff --git a/lib/http/mime_type/json.rb b/lib/http/mime_type/json.rb index 1e2cf2d6..f2d56cde 100644 --- a/lib/http/mime_type/json.rb +++ b/lib/http/mime_type/json.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "json" require "http/mime_type/adapter" diff --git a/lib/http/options.rb b/lib/http/options.rb index 1b2e1c45..a69834c3 100644 --- a/lib/http/options.rb +++ b/lib/http/options.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "http/headers" require "openssl" require "socket" diff --git a/lib/http/redirector.rb b/lib/http/redirector.rb index 783273ea..86028ec8 100644 --- a/lib/http/redirector.rb +++ b/lib/http/redirector.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "set" require "http/headers" diff --git a/lib/http/response.rb b/lib/http/response.rb index 44969f09..f49b7fc8 100644 --- a/lib/http/response.rb +++ b/lib/http/response.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "forwardable" require "http/headers" diff --git a/lib/http/response/body.rb b/lib/http/response/body.rb index 89c0cec5..79404eff 100644 --- a/lib/http/response/body.rb +++ b/lib/http/response/body.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "forwardable" require "http/client" @@ -43,8 +44,9 @@ def to_s end begin - @streaming = false - @contents = "".force_encoding(encoding) + @streaming = false + @contents = String.new("").force_encoding(encoding) + while (chunk = @client.readpartial) @contents << chunk.force_encoding(encoding) end diff --git a/lib/http/response/parser.rb b/lib/http/response/parser.rb index 3c7e1d58..38b1925a 100644 --- a/lib/http/response/parser.rb +++ b/lib/http/response/parser.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module HTTP class Response class Parser diff --git a/lib/http/response/status.rb b/lib/http/response/status.rb index 73fb3444..7a68d94c 100644 --- a/lib/http/response/status.rb +++ b/lib/http/response/status.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "delegate" require "http/response/status/reasons" diff --git a/lib/http/response/status/reasons.rb b/lib/http/response/status/reasons.rb index 119c53ba..ed2f8883 100644 --- a/lib/http/response/status/reasons.rb +++ b/lib/http/response/status/reasons.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # AUTO-GENERATED FILE, DO NOT CHANGE IT MANUALLY require "delegate" diff --git a/lib/http/timeout/global.rb b/lib/http/timeout/global.rb index 01a41934..1a3731a8 100644 --- a/lib/http/timeout/global.rb +++ b/lib/http/timeout/global.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "timeout" require "io/wait" diff --git a/lib/http/timeout/null.rb b/lib/http/timeout/null.rb index 5167251c..8d798807 100644 --- a/lib/http/timeout/null.rb +++ b/lib/http/timeout/null.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "forwardable" require "io/wait" diff --git a/lib/http/timeout/per_operation.rb b/lib/http/timeout/per_operation.rb index 6d23b6cd..0c277fe1 100644 --- a/lib/http/timeout/per_operation.rb +++ b/lib/http/timeout/per_operation.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "timeout" require "http/timeout/null" diff --git a/spec/lib/http/client_spec.rb b/spec/lib/http/client_spec.rb index f6dd46f9..7e1b6383 100644 --- a/spec/lib/http/client_spec.rb +++ b/spec/lib/http/client_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # coding: utf-8 require "support/http_handling_shared" diff --git a/spec/lib/http/content_type_spec.rb b/spec/lib/http/content_type_spec.rb index a5fc55ff..bb4da960 100644 --- a/spec/lib/http/content_type_spec.rb +++ b/spec/lib/http/content_type_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::ContentType do describe ".parse" do context "with text/plain" do diff --git a/spec/lib/http/headers/mixin_spec.rb b/spec/lib/http/headers/mixin_spec.rb index c45b5634..95bde7c4 100644 --- a/spec/lib/http/headers/mixin_spec.rb +++ b/spec/lib/http/headers/mixin_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Headers::Mixin do let :dummy_class do Class.new do diff --git a/spec/lib/http/headers_spec.rb b/spec/lib/http/headers_spec.rb index a71bf9a1..ab6fccd7 100644 --- a/spec/lib/http/headers_spec.rb +++ b/spec/lib/http/headers_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Headers do subject(:headers) { described_class.new } diff --git a/spec/lib/http/options/body_spec.rb b/spec/lib/http/options/body_spec.rb index 5e437e47..ad4166aa 100644 --- a/spec/lib/http/options/body_spec.rb +++ b/spec/lib/http/options/body_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Options, "body" do let(:opts) { HTTP::Options.new } diff --git a/spec/lib/http/options/form_spec.rb b/spec/lib/http/options/form_spec.rb index 1997958b..09237ae1 100644 --- a/spec/lib/http/options/form_spec.rb +++ b/spec/lib/http/options/form_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Options, "form" do let(:opts) { HTTP::Options.new } diff --git a/spec/lib/http/options/headers_spec.rb b/spec/lib/http/options/headers_spec.rb index c2864e7f..2c3cae71 100644 --- a/spec/lib/http/options/headers_spec.rb +++ b/spec/lib/http/options/headers_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Options, "headers" do let(:opts) { HTTP::Options.new } diff --git a/spec/lib/http/options/json_spec.rb b/spec/lib/http/options/json_spec.rb index 861ffa44..60e22342 100644 --- a/spec/lib/http/options/json_spec.rb +++ b/spec/lib/http/options/json_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Options, "json" do let(:opts) { HTTP::Options.new } diff --git a/spec/lib/http/options/merge_spec.rb b/spec/lib/http/options/merge_spec.rb index d3703266..bc55c55e 100644 --- a/spec/lib/http/options/merge_spec.rb +++ b/spec/lib/http/options/merge_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Options, "merge" do let(:opts) { HTTP::Options.new } @@ -23,7 +24,8 @@ :body => "body-foo", :json => {:foo => "foo"}, :headers => {:accept => "json", :foo => "foo"}, - :proxy => {}) + :proxy => {} + ) bar = HTTP::Options.new( :response => :parsed_body, @@ -36,27 +38,29 @@ :headers => {:accept => "xml", :bar => "bar"}, :timeout_options => {:foo => :bar}, :ssl => {:foo => "bar"}, - :proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080}) + :proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080} + ) expect(foo.merge(bar).to_hash).to eq( - :response => :parsed_body, - :timeout_class => described_class.default_timeout_class, - :timeout_options => {:foo => :bar}, - :params => {:plop => "plip"}, - :form => {:bar => "bar"}, - :body => "body-bar", - :json => {:bar => "bar"}, - :persistent => "https://www.googe.com", + :response => :parsed_body, + :timeout_class => described_class.default_timeout_class, + :timeout_options => {:foo => :bar}, + :params => {:plop => "plip"}, + :form => {:bar => "bar"}, + :body => "body-bar", + :json => {:bar => "bar"}, + :persistent => "https://www.googe.com", :keep_alive_timeout => 10, - :ssl => {:foo => "bar"}, - :headers => {"Foo" => "foo", "Accept" => "xml", "Bar" => "bar"}, - :proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080}, - :follow => nil, - :socket_class => described_class.default_socket_class, - :nodelay => false, - :ssl_socket_class => described_class.default_ssl_socket_class, - :ssl_context => nil, - :cookies => {}, - :encoding => nil) + :ssl => {:foo => "bar"}, + :headers => {"Foo" => "foo", "Accept" => "xml", "Bar" => "bar"}, + :proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080}, + :follow => nil, + :socket_class => described_class.default_socket_class, + :nodelay => false, + :ssl_socket_class => described_class.default_ssl_socket_class, + :ssl_context => nil, + :cookies => {}, + :encoding => nil + ) end end diff --git a/spec/lib/http/options/new_spec.rb b/spec/lib/http/options/new_spec.rb index 123545fd..eef76898 100644 --- a/spec/lib/http/options/new_spec.rb +++ b/spec/lib/http/options/new_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Options, "new" do it "supports a Options instance" do opts = HTTP::Options.new diff --git a/spec/lib/http/options/proxy_spec.rb b/spec/lib/http/options/proxy_spec.rb index 41fafd9f..b120a202 100644 --- a/spec/lib/http/options/proxy_spec.rb +++ b/spec/lib/http/options/proxy_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Options, "proxy" do let(:opts) { HTTP::Options.new } diff --git a/spec/lib/http/options_spec.rb b/spec/lib/http/options_spec.rb index 1ab21920..c901ef50 100644 --- a/spec/lib/http/options_spec.rb +++ b/spec/lib/http/options_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Options do subject { described_class.new(:response => :body) } diff --git a/spec/lib/http/redirector_spec.rb b/spec/lib/http/redirector_spec.rb index 0c1ba3ac..ab966c3d 100644 --- a/spec/lib/http/redirector_spec.rb +++ b/spec/lib/http/redirector_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Redirector do def simple_response(status, body = "", headers = {}) HTTP::Response.new( diff --git a/spec/lib/http/request/writer_spec.rb b/spec/lib/http/request/writer_spec.rb index a90de13b..ac7ed1f8 100644 --- a/spec/lib/http/request/writer_spec.rb +++ b/spec/lib/http/request/writer_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # coding: utf-8 RSpec.describe HTTP::Request::Writer do diff --git a/spec/lib/http/request_spec.rb b/spec/lib/http/request_spec.rb index dcba943c..40d38b77 100644 --- a/spec/lib/http/request_spec.rb +++ b/spec/lib/http/request_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # coding: utf-8 RSpec.describe HTTP::Request do diff --git a/spec/lib/http/response/body_spec.rb b/spec/lib/http/response/body_spec.rb index 6e1488d0..4fca7a70 100644 --- a/spec/lib/http/response/body_spec.rb +++ b/spec/lib/http/response/body_spec.rb @@ -1,17 +1,18 @@ +# frozen_string_literal: true RSpec.describe HTTP::Response::Body do let(:client) { double(:sequence_id => 0) } - let(:chunks) { ["Hello, ", "World!"] } + let(:chunks) { [String.new("Hello, "), String.new("World!")] } before { allow(client).to receive(:readpartial) { chunks.shift } } - subject(:body) { described_class.new client, Encoding::UTF_8 } + subject(:body) { described_class.new(client, Encoding::UTF_8) } it "streams bodies from responses" do - expect(subject.to_s).to eq "Hello, World!" + expect(subject.to_s).to eq("Hello, World!") end context "when body empty" do - let(:chunks) { [""] } + let(:chunks) { [String.new("")] } it "returns responds to empty? with true" do expect(subject).to be_empty diff --git a/spec/lib/http/response/status_spec.rb b/spec/lib/http/response/status_spec.rb index 4db54939..b8a457a8 100644 --- a/spec/lib/http/response/status_spec.rb +++ b/spec/lib/http/response/status_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Response::Status do describe ".new" do it "fails if given value does not respond to #to_i" do diff --git a/spec/lib/http/response_spec.rb b/spec/lib/http/response_spec.rb index cb2c5781..2842ba4b 100644 --- a/spec/lib/http/response_spec.rb +++ b/spec/lib/http/response_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::Response do let(:body) { "Hello world!" } let(:uri) { "http://example.com/" } diff --git a/spec/lib/http/uri_spec.rb b/spec/lib/http/uri_spec.rb index ab9111f5..f402bbde 100644 --- a/spec/lib/http/uri_spec.rb +++ b/spec/lib/http/uri_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.describe HTTP::URI do let(:example_http_uri_string) { "http://example.com" } let(:example_https_uri_string) { "https://example.com" } diff --git a/spec/lib/http_spec.rb b/spec/lib/http_spec.rb index a58aa959..5765c1d7 100644 --- a/spec/lib/http_spec.rb +++ b/spec/lib/http_spec.rb @@ -1,4 +1,5 @@ -# encoding: UTF-8 +# frozen_string_literal: true +# encoding: utf-8 require "json" diff --git a/spec/regression_specs.rb b/spec/regression_specs.rb index ac84f86d..bb4af170 100644 --- a/spec/regression_specs.rb +++ b/spec/regression_specs.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "spec_helper" RSpec.describe "Regression testing" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4c4e4eee..328f7106 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # coding: utf-8 require "simplecov" diff --git a/spec/support/black_hole.rb b/spec/support/black_hole.rb index a9df555b..38304a87 100644 --- a/spec/support/black_hole.rb +++ b/spec/support/black_hole.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module BlackHole def self.method_missing(*) self diff --git a/spec/support/capture_warning.rb b/spec/support/capture_warning.rb index c39da4c6..502f9417 100644 --- a/spec/support/capture_warning.rb +++ b/spec/support/capture_warning.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true def capture_warning old_stderr = $stderr $stderr = StringIO.new diff --git a/spec/support/dummy_server.rb b/spec/support/dummy_server.rb index 6aee8417..671fbeb3 100644 --- a/spec/support/dummy_server.rb +++ b/spec/support/dummy_server.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "webrick" require "webrick/ssl" diff --git a/spec/support/dummy_server/servlet.rb b/spec/support/dummy_server/servlet.rb index 55fb30f1..d09abbc4 100644 --- a/spec/support/dummy_server/servlet.rb +++ b/spec/support/dummy_server/servlet.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # encoding: UTF-8 class DummyServer < WEBrick::HTTPServer diff --git a/spec/support/http_handling_shared.rb b/spec/support/http_handling_shared.rb index 3d188d81..4a239629 100644 --- a/spec/support/http_handling_shared.rb +++ b/spec/support/http_handling_shared.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true RSpec.shared_context "HTTP handling" do describe "timeouts" do let(:conn_timeout) { 1 } diff --git a/spec/support/proxy_server.rb b/spec/support/proxy_server.rb index b268291a..a3886340 100644 --- a/spec/support/proxy_server.rb +++ b/spec/support/proxy_server.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "webrick/httpproxy" require "support/black_hole" diff --git a/spec/support/servers/config.rb b/spec/support/servers/config.rb index 527a5d51..0630b42e 100644 --- a/spec/support/servers/config.rb +++ b/spec/support/servers/config.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ServerConfig def addr config[:BindAddress] diff --git a/spec/support/servers/runner.rb b/spec/support/servers/runner.rb index 6c9f1100..0e0170e7 100644 --- a/spec/support/servers/runner.rb +++ b/spec/support/servers/runner.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ServerRunner def run_server(name) let! name do diff --git a/spec/support/ssl_helper.rb b/spec/support/ssl_helper.rb index 18945360..afb16bc8 100644 --- a/spec/support/ssl_helper.rb +++ b/spec/support/ssl_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "pathname" require "certificate_authority"