Sha256: 104c8bad3357627f414334e749a9363e52ca6356a1e09feac6480ebd0d27059a

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

RSpec.describe HTTParty::Logger do
  describe ".build" do
    subject { HTTParty::Logger }

    it "defaults level to :info" do
      logger_double = double
      expect(subject.build(logger_double, nil, nil).level).to eq(:info)
    end

    it "defaults format to :apache" do
      logger_double = double
      expect(subject.build(logger_double, nil, nil)).to be_an_instance_of(HTTParty::Logger::ApacheFormatter)
    end

    it "builds :curl style logger" do
      logger_double = double
      expect(subject.build(logger_double, nil, :curl)).to be_an_instance_of(HTTParty::Logger::CurlFormatter)
    end

    it "builds :logstash style logger" do
      logger_double = double
      expect(subject.build(logger_double, nil, :logstash)).to be_an_instance_of(HTTParty::Logger::LogstashFormatter)
    end

    it "builds :custom style logger" do
      CustomFormatter = Class.new(HTTParty::Logger::CurlFormatter)
      HTTParty::Logger.add_formatter(:custom, CustomFormatter)

      logger_double = double
      expect(subject.build(logger_double, nil, :custom)).
        to be_an_instance_of(CustomFormatter)
    end
    it "raises error when formatter exists" do
      CustomFormatter2= Class.new(HTTParty::Logger::CurlFormatter)
      HTTParty::Logger.add_formatter(:custom2, CustomFormatter2)

      expect{ HTTParty::Logger.add_formatter(:custom2, CustomFormatter2) }.
        to raise_error HTTParty::Error
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
httparty-0.17.0 spec/httparty/logger/logger_spec.rb
httparty-0.16.4 spec/httparty/logger/logger_spec.rb
httparty-0.16.3 spec/httparty/logger/logger_spec.rb