spec/log_spec.rb in lookout-rack-utils-3.8.0.39 vs spec/log_spec.rb in lookout-rack-utils-4.0.0.44

- old
+ new

@@ -3,59 +3,61 @@ require 'timecop' require 'configatron' describe Lookout::Rack::Utils::Log do subject(:log) { described_class.instance } - subject(:log_message) { 'foo' } + let(:log_message) { 'foo' } let(:filename) { "log" } + let(:exclude_levels) { [] } - before :each do - configatron.logging.enabled = true - allow(configatron.logging).to receive(:file).and_return(filename) + around :each do |example| + configatron.temp do + configatron.logging.enabled = true + configatron.logging.file = filename + configatron.statsd.exclude_levels = exclude_levels + example.run + end end describe '.debug' do context 'if debug is in configatron.statsd.exclude_levels' do - before { configatron.statsd.exclude_levels = [:debug] } - after { configatron.statsd.exclude_levels = [] } + let(:exclude_levels) { [:debug] } it 'should not log a graphite stat' do - Lookout::Rack::Utils::Graphite.should_not_receive(:increment).with('log.debug') + expect(Lookout::Rack::Utils::Graphite).not_to receive(:increment).with('log.debug') log.debug log_message end end it 'should log a graphite stat' do - Lookout::Rack::Utils::Graphite.should_receive(:increment).with('log.debug') + expect(Lookout::Rack::Utils::Graphite).to receive(:increment).with('log.debug') log.debug log_message end end [:debug, :info, :warn, :error, :fatal].each do |method| describe ".#{method}" do + before { expect(log.instance_variable_get(:@logger)).to receive(method).with(log_message).and_call_original } + it 'should log a graphite stat' do - Lookout::Rack::Utils::Graphite.should_receive(:increment).with("log.#{method}") + expect(Lookout::Rack::Utils::Graphite).to receive(:increment).with("log.#{method}") - log.instance_variable_get(:@logger).should_receive(method).with(log_message).and_call_original - processed = false b = Proc.new { processed = true } log.send(method, log_message, &b) expect(processed).to be(true) end it 'should invoke the internal logger object with a given block' do - log.instance_variable_get(:@logger).should_receive(method).with(log_message).and_call_original processed = false b = Proc.new { processed = true } log.send(method, log_message, &b) expect(processed).to be(true) end it 'should invoke the internal logger object w/o a given block' do - log.instance_variable_get(:@logger).should_receive(method).with(log_message).and_call_original log.send(method, log_message) end end end @@ -90,12 +92,12 @@ describe Lookout::Rack::Utils::Log::LookoutFormatter do subject(:formatter) { described_class.new } let(:logger) do logger = double('Mock Logger') - logger.stub(:name).and_return('RSpec Logger') - logger.stub(:fullname).and_return('RSpec Logger') + expect(logger).to receive(:name).and_return('RSpec Logger') + expect(logger).to receive(:fullname).and_return('RSpec Logger') logger end let(:project_name) { 'some_project' } let(:basedir) { "/home/rspec/#{project_name}" } let(:tracer) do @@ -111,26 +113,26 @@ Log4r::RootLogger.instance end before :each do - formatter.stub(:basedir).and_return(basedir) + allow(formatter).to receive(:basedir).and_return(basedir) end describe '#event_filename' do subject(:filename) { formatter.event_filename(tracer[1]) } context 'with a normal MRI LogEvent' do - it { should eql('spec/log_spec.rb:9') } + it { is_expected.to eql('spec/log_spec.rb:9') } end # We have slightly different log formats under packaged .jar files context 'with a LogEvent from a packaged .jar' do let(:tracer) { [nil, "backend/metrics.rb:52:in `runloop'"] } let(:basedir) { 'file:/home/user/source/projects/stuff.jar!/project' } - it { should eql('backend/metrics.rb:52') } + it { is_expected.to eql('backend/metrics.rb:52') } end end describe '#format' do before :each do