Sha256: 09727de20106e3a2ad631ac223286d30137ba60be4062e074ede203503970f9b
Contents?: true
Size: 1.82 KB
Versions: 13
Compression:
Stored size: 1.82 KB
Contents
require 'spec_helper' describe Services::Base::CallLogger do it 'logs start with args and end with duration' do service = EmptyService.new logs = [] allow(service).to receive(:log) do |message, *| logs << message end service.call 'foo', 'bar' expect(logs.first).to eq('START with args ["foo", "bar"]') expect(logs.last).to eq('END after 0.0 seconds') end it 'logs the caller' do service_calling_service, called_service = ServiceCallingService.new, EmptyService.new logs = [] allow(called_service).to receive(:log) do |message, *| logs << message end # When Rails is not defined, the complete caller path should be logged service_calling_service.call called_service expect(logs).to include(/\ACALLED BY #{Regexp.escape PROJECT_ROOT.join(TEST_SERVICES_PATH).to_s}:\d+/) # When Rails is defined, only the caller path relative to Rails.root is logged class Rails def self.root; PROJECT_ROOT; end end logs = [] service_calling_service.call called_service expect(logs).to include(/\ACALLED BY #{Regexp.escape TEST_SERVICES_PATH.to_s}:\d+/) Object.send :remove_const, :Rails # Caller paths from services lib folder should be filtered require 'services/call_proxy' logs = [] Services::CallProxy.call(called_service, :call) expect(logs).to include(/\ACALLED BY #{Regexp.escape __FILE__}:\d+/) end if RUBY_VERSION > '2.1' it 'logs exceptions and exception causes' do service = NestedExceptionService.new logs = [] allow(service).to receive(:log) do |message, *| logs << message end expect { service.call }.to raise_error(service.class::Error) %w(NestedError1 NestedError2).each do |error| expect(logs).to include(/\Acaused by: #{service.class}::#{error}/) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems