spec/unit/loga/rack/logger_spec.rb in loga-1.4.0 vs spec/unit/loga/rack/logger_spec.rb in loga-2.0.0

- old
+ new

@@ -3,19 +3,27 @@ describe Loga::Rack::Logger do let(:env) { Rack::MockRequest.env_for('/about_us?limit=1', options) } let(:options) { {} } let(:app) { ->(_env) { [response_status, {}, ''] } } - let(:logger) { double(:logger) } + let(:logger) { instance_double(Logger, info: nil, error: nil) } + let(:tags) { [] } - subject { described_class.new(app, logger) } - - before do - allow(logger).to receive(:info) - allow(logger).to receive(:error) + let(:configuration) do + instance_double( + Loga::Configuration, + filter_exceptions: %w(ActionController::RoutingError), + filter_parameters: [], + logger: logger, + tags: tags, + ) end + subject { described_class.new(app) } + + before { Loga.instance_variable_set(:@configuration, configuration) } + shared_examples 'logs the event' do |details| let(:level) { details[:level] } before do allow(subject).to receive(:started_at).and_return(:timestamp) @@ -101,14 +109,18 @@ allow(logger).to receive(:tagged).with('hello') do |&block| block.call end end - it 'yields the app with tags' do - expect(logger).to receive(:tagged).with(:tag) do |&block| - expect(block.call).to eq(:response) + context 'when tags are present' do + let(:tags) { [:foo] } + + it 'yields the app with tags' do + expect(logger).to receive(:tagged).with(:tag) do |&block| + expect(block.call).to eq(:response) + end + subject.call(env) end - subject.call(env) end end end end