Sha256: a96fa8d4b5fb67c0ee7911635f018d81e0aa702f268920395319e8cb4d74f41e

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

RSpec.describe Dry::Monitor::SQL::Logger do
  subject(:logger) { sql_logger.new(Dry::Monitor::Logger.new(log_file_path)) }

  let(:notifications) do
    Dry::Monitor::Notifications.new(:test)
  end

  let(:log_file_path) do
    SPEC_ROOT.join('test_logs/sql.log')
  end

  let(:log_file_content) { File.read(log_file_path) }

  shared_context '#subscribe' do
    let(:query) do
      'SELECT id, name FROM users'
    end

    before do
      File.open(log_file_path, 'w').close

      logger.subscribe(notifications)

      notifications.instrument(:sql, name: 'users', query: query) do
        sleep 0.0025
      end
    end

    it 'writes sql query info' do
      expect(log_file_content).to include('Loaded "users" in')
    end
  end

  context 'without colors' do
    let(:sql_logger) do
      Class.new(Dry::Monitor::SQL::Logger) do
        configure do |config|
          config.colorize = false
        end
      end
    end

    include_context '#subscribe' do
      it 'writes sql query in logs' do
        expect(log_file_content).to include(query)
      end
    end
  end

  context 'without colors' do
    let(:sql_logger) do
      Dry::Monitor::SQL::Logger
    end

    include_context '#subscribe'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-monitor-0.1.2 spec/integration/sql_logger_spec.rb
dry-monitor-0.1.1 spec/integration/sql_logger_spec.rb