Sha256: 9932a5178994e469a4a8220aa052561391bf990c857ff769dd99fdc8d8b7c12f

Contents?: true

Size: 1.53 KB

Versions: 17

Compression:

Stored size: 1.53 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))

RSpec.describe HTTParty::Logger::ApacheFormatter do
  let(:subject) { described_class.new(logger_double, :info) }
  let(:logger_double) { double('Logger') }
  let(:request_double) { double('Request', http_method: Net::HTTP::Get, path: "http://my.domain.com/my_path") }
  let(:request_time) { Time.new.strftime("%Y-%m-%d %H:%M:%S %z") }

  before do
    subject.current_time = request_time
    expect(logger_double).to receive(:info).with(log_message)
  end

  describe "#format" do
    let(:log_message) { "[HTTParty] [#{request_time}] 302 \"GET http://my.domain.com/my_path\" - " }

    it "formats a response in a style that resembles apache's access log" do
      response_double = double(
        code: 302,
        :[] => nil
      )

      subject.format(request_double, response_double)
    end

    context 'when there is a parsed response' do
      let(:log_message) { "[HTTParty] [#{request_time}] 200 \"GET http://my.domain.com/my_path\" 512 "}

      it "can handle the Content-Length header" do
        # Simulate a parsed response that is an array, where accessing a string key will raise an error. See Issue #299.
        response_double = double(
            code: 200,
            headers: { 'Content-Length' => 512 }
        )
        allow(response_double).to receive(:[]).with('Content-Length').and_raise(TypeError.new('no implicit conversion of String into Integer'))

        subject.format(request_double, response_double)
      end
    end
  end
end

Version data entries

17 entries across 16 versions & 3 rubygems

Version Path
httparty-0.16.2 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.16.1 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.16.0 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.15.7 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.15.6 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.15.5 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.15.4 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.15.3 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.15.2 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.15.1 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.15.0 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.14.0 spec/httparty/logger/apache_formatter_spec.rb
simplenet-client-0.2.0 ./vendor/bundle/ruby/2.0.0/gems/httparty-0.13.7/spec/httparty/logger/apache_formatter_spec.rb
simplenet-client-0.2.0 ./vendor/bundle/ruby/1.9.1/gems/httparty-0.13.7/spec/httparty/logger/apache_formatter_spec.rb
httparty-0.13.7 spec/httparty/logger/apache_formatter_spec.rb
httparty-0.13.6 spec/httparty/logger/apache_formatter_spec.rb
httpserious-0.13.5.lstoll1 spec/httparty/logger/apache_formatter_spec.rb