mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
the loggers are really formatters. Rename as such
This commit is contained in:
parent
66f60cd804
commit
4c6514f2a2
6 changed files with 18 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
|||
module HTTParty
|
||||
module Logger
|
||||
class ApacheLogger #:nodoc:
|
||||
class ApacheFormatter #:nodoc:
|
||||
TAG_NAME = HTTParty.name
|
||||
|
||||
attr_accessor :level, :logger, :current_time
|
|
@ -1,6 +1,6 @@
|
|||
module HTTParty
|
||||
module Logger
|
||||
class CurlLogger #:nodoc:
|
||||
class CurlFormatter #:nodoc:
|
||||
TAG_NAME = HTTParty.name
|
||||
OUT = ">"
|
||||
IN = "<"
|
|
@ -1,12 +1,12 @@
|
|||
require 'httparty/logger/apache_logger'
|
||||
require 'httparty/logger/curl_logger'
|
||||
require 'httparty/logger/apache_formatter'
|
||||
require 'httparty/logger/curl_formatter'
|
||||
|
||||
module HTTParty
|
||||
module Logger
|
||||
def self.formatters
|
||||
@formatters ||= {
|
||||
:curl => Logger::CurlLogger,
|
||||
:apache => Logger::ApacheLogger
|
||||
:curl => Logger::CurlFormatter,
|
||||
:apache => Logger::ApacheFormatter
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -19,7 +19,7 @@ module HTTParty
|
|||
level ||= :info
|
||||
formatter ||= :apache
|
||||
|
||||
logger_klass = formatters[formatter] || Logger::ApacheLogger
|
||||
logger_klass = formatters[formatter] || Logger::ApacheFormatter
|
||||
logger_klass.new(logger, level)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
|
||||
RSpec.describe HTTParty::Logger::ApacheLogger do
|
||||
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") }
|
|
@ -1,6 +1,6 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
||||
|
||||
RSpec.describe HTTParty::Logger::CurlLogger do
|
||||
RSpec.describe HTTParty::Logger::CurlFormatter do
|
||||
describe "#format" do
|
||||
it "formats a response in a style that resembles a -v curl" do
|
||||
logger_double = double
|
|
@ -11,27 +11,27 @@ RSpec.describe HTTParty::Logger do
|
|||
|
||||
it "defaults format to :apache" do
|
||||
logger_double = double
|
||||
expect(subject.build(logger_double, nil, nil)).to be_an_instance_of(HTTParty::Logger::ApacheLogger)
|
||||
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::CurlLogger)
|
||||
expect(subject.build(logger_double, nil, :curl)).to be_an_instance_of(HTTParty::Logger::CurlFormatter)
|
||||
end
|
||||
|
||||
it "builds custom style logger" do
|
||||
CustomLogger = Class.new(HTTParty::Logger::CurlLogger)
|
||||
HTTParty::Logger.add_formatter(:custom, CustomLogger)
|
||||
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(CustomLogger)
|
||||
to be_an_instance_of(CustomFormatter)
|
||||
end
|
||||
it "raises error when formatter exists" do
|
||||
CustomLogger2 = Class.new(HTTParty::Logger::CurlLogger)
|
||||
HTTParty::Logger.add_formatter(:custom2, CustomLogger2)
|
||||
CustomFormatter2= Class.new(HTTParty::Logger::CurlFormatter)
|
||||
HTTParty::Logger.add_formatter(:custom2, CustomFormatter2)
|
||||
|
||||
expect{ HTTParty::Logger.add_formatter(:custom2, CustomLogger2) }.
|
||||
expect{ HTTParty::Logger.add_formatter(:custom2, CustomFormatter2) }.
|
||||
to raise_error HTTParty::Error
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue