Sha256: 0f5fe19f95aed58e818a72d9049d53f06681294b674952db226ce8fc2a2a36bb

Contents?: true

Size: 1.76 KB

Versions: 31

Compression:

Stored size: 1.76 KB

Contents

require 'spec_helper'

describe Ridley::Logging::Logger do
  subject { described_class.new("/dev/null") }
  let(:message) { "my message" }
  let(:filtered_param) { "message" }

  describe "::initialize" do
    it "defaults to info" do
      expect(subject.level).to eq(Logger::WARN)
    end
  end

  describe "#info" do

    before do
      subject.level = Logger::INFO
      subject.filter_param filtered_param
    end

    it "supports filtering" do
      expect(subject).to receive(:filter).with("my message").and_return("my FILTERED")
      subject.info message
    end
  end

  describe "#filter_params" do
    it "returns an array" do
      expect(subject.filter_params).to be_a(Array)
    end
  end

  describe "#filter_param" do
    let(:param) { "hello" }

    before do
      subject.clear_filter_params
    end

    it "adds an element to the array" do
      subject.filter_param(param)
      expect(subject.filter_params).to include(param)
      expect(subject.filter_params.size).to eq(1)
    end

    context "when the element is already in the array" do

      before do
        subject.filter_param(param)
      end
      it "does not duplicate the element" do
        subject.filter_param(param)
        expect(subject.filter_params.size).to eq(1)
      end
    end
  end

  describe "#filter" do

    before do
      subject.filter_param(filtered_param)
    end

    it "replaces entries in filter_params" do
      expect(subject.filter(message)).to eq("my FILTERED")
    end

    context "when there are multiple filter_params" do
      before do
        subject.filter_param("fake param")
        subject.filter_param(filtered_param) 
      end

      it "replaces only matching filter_params" do
        expect(subject.filter(message)).to eq("my FILTERED")
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
ridley-5.1.0 spec/unit/ridley/logger_spec.rb
ridley-5.0.0 spec/unit/ridley/logger_spec.rb
ridley-4.6.1 spec/unit/ridley/logger_spec.rb
ridley-4.6.0 spec/unit/ridley/logger_spec.rb
ridley-4.5.1 spec/unit/ridley/logger_spec.rb
ridley-4.5.0 spec/unit/ridley/logger_spec.rb
ridley-4.4.3 spec/unit/ridley/logger_spec.rb
ridley-4.4.2 spec/unit/ridley/logger_spec.rb
ridley-4.4.1 spec/unit/ridley/logger_spec.rb
ridley-4.4.0 spec/unit/ridley/logger_spec.rb
ridley-4.3.2 spec/unit/ridley/logger_spec.rb
ridley-4.3.1 spec/unit/ridley/logger_spec.rb
ridley-4.3.0 spec/unit/ridley/logger_spec.rb
ridley-4.2.0 spec/unit/ridley/logger_spec.rb
ridley-4.1.2 spec/unit/ridley/logger_spec.rb
ridley-4.1.1 spec/unit/ridley/logger_spec.rb
ridley-4.1.0 spec/unit/ridley/logger_spec.rb
ridley-4.0.0 spec/unit/ridley/logger_spec.rb
ridley-3.1.0 spec/unit/ridley/logger_spec.rb
ridley-3.0.0 spec/unit/ridley/logger_spec.rb