Sha256: 4d8a370a0a95930b5c591a637f66a0245edff4b9fe0a56830331cf9ba62b0a32
Contents?: true
Size: 1.33 KB
Versions: 3
Compression:
Stored size: 1.33 KB
Contents
require 'rspec' require 'hyperion' require 'stringio' describe Hyperion::Logger do include Hyperion::Logger it 'logs to $stdout by default' do output = StringIO.new with_stdout(output) do logger.debug 'xyzzy' logger.debug 'qwerty' end output_str = output.string expect(output_str).to include 'xyzzy' expect(output_str).to include 'qwerty' end it 'logs to Rails.logger if present' do rails, logger = double, double allow(rails).to receive(:logger).and_return(logger) expect(logger).to receive(:debug).with('xyzzy') with_rails(rails) do logger.debug 'xyzzy' end end it 'respects the log level' do output = StringIO.new with_stdout(output) do Logatron.level = Logatron::ERROR logger.debug 'xyzzy' logger.error 'qwerty' Logatron.level = Logatron::DEBUG end output_str = output.string expect(output_str).to include 'qwert' expect(output_str).to_not include 'xyzzy' end def with_stdout(io) set_log_io(io) begin yield ensure set_log_io($stdout) end end def set_log_io(io) Logatron.configure do |c| c.logger = Logger.new(io) end end def with_rails(rails) Kernel.const_set(:Rails, rails) begin yield ensure Kernel.send(:remove_const, :Rails) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hyperion_http-0.1.7 | spec/lib/hyperion/logger_spec.rb |
hyperion_http-0.1.6 | spec/lib/hyperion/logger_spec.rb |
hyperion_http-0.1.5 | spec/lib/hyperion/logger_spec.rb |