Sha256: 9bae734100137934091096071d30dcfd0aeb01eb98ad834449cd3441357d1df2

Contents?: true

Size: 1.87 KB

Versions: 2

Compression:

Stored size: 1.87 KB

Contents

RSpec.describe Dry::Events::Filter do
  subject(:filter) { described_class.new(query) }

  context 'nested hash' do
    let(:query) do
      { logger: { level: :info } }
    end

    specify do
      expect(filter.()).to be false
      expect(filter.(logger: { level: :info, output: :stdin })).to be true
      expect(filter.(logger: { level: :debug })).to be false
      expect(filter.(logger: :debug)).to be false
    end
  end

  context 'multi-value check' do
    let(:query) do
      { logger: { level: :info, output: :stdin } }
    end

    specify do
      expect(filter.()).to be false
      expect(filter.(logger: { level: :info, output: :stdin })).to be true
      expect(filter.(logger: { level: :info })).to be false
    end
  end

  context 'top-level array' do
    let(:query) { %i(error fatal) }

    specify do
      expect(filter.()).to be false
      expect(filter.(random: :hash)).to be false
      expect(filter.(:error)).to be true
    end
  end

  context 'nested array' do
    let(:query) do
      { logger: { level: %i(info warn error fatal) } }
    end

    specify do
      expect(filter.()).to be false
      expect(filter.(logger: { level: :info, output: :stdin })).to be true
      expect(filter.(logger: { level: :fatal })).to be true
      expect(filter.(logger: { level: :debug })).to be false
      expect(filter.(level: :debug)).to be false
    end
  end

  context 'nested proc' do
    let(:query) do
      { logger: { level: -> level { %i(error fatal).include?(level) } } }
    end

    specify do
      expect(filter.()).to be false
      expect(filter.(logger: { level: :error, output: :stdin })).to be true
    end
  end

  context 'top-level proc' do
    let(:query) do
      -> level: :debug, ** { %i(error fatal).include?(level) }
    end

    specify do
      expect(filter.()).to be false
      expect(filter.(level: :error, output: :stdin)).to be true
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-events-0.2.0 spec/unit/dry/events/filter_spec.rb
dry-events-0.1.1 spec/unit/dry/events/filter_spec.rb