Sha256: af065a1b78f20426dbfd094d5f90a2c2c94cca6e0979ddfce648b98caf718d9b

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

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

4 entries across 4 versions & 1 rubygems

Version Path
dry-monitor-0.1.0 spec/integration/sql_logger_spec.rb
dry-monitor-0.0.3 spec/integration/sql_logger_spec.rb
dry-monitor-0.0.2 spec/integration/sql_logger_spec.rb
dry-monitor-0.0.1 spec/integration/sql_logger_spec.rb