Sha256: 9586115e08f53112771552d01ceced16009735a165da56af9035dcdd8374c0a2

Contents?: true

Size: 1.84 KB

Versions: 58

Compression:

Stored size: 1.84 KB

Contents

# encoding: utf-8
require 'spec_helper'

require "logstash/util"

class ClassNameTest
end

module TestingClassName
  class TestKlass
  end
end

describe LogStash::Util do

  subject { described_class }

  context "stringify_keys" do
    it "should convert hash symbol keys to strings" do
      expect(LogStash::Util.stringify_symbols({:a => 1, "b" => 2})).to eq({"a" => 1, "b" => 2})
    end

    it "should keep non symbolic hash keys as is" do
      expect(LogStash::Util.stringify_symbols({1 => 1, 2.0 => 2})).to eq({1 => 1, 2.0 => 2})
    end

    it "should convert inner hash keys to strings" do
      expect(LogStash::Util.stringify_symbols({:a => 1, "b" => {:c => 3}})).to eq({"a" => 1, "b" => {"c" => 3}})
      expect(LogStash::Util.stringify_symbols([:a, 1, "b", {:c => 3}])).to eq(["a", 1, "b", {"c" => 3}])
    end

    it "should convert hash symbol values to strings" do
      expect(LogStash::Util.stringify_symbols({:a => :a, "b" => :b})).to eq({"a" => "a", "b" => "b"})
    end

    it "should convert array symbol values to strings" do
      expect(LogStash::Util.stringify_symbols([1, :a])).to eq([1, "a"])
    end

    it "should convert innner array symbol values to strings" do
      expect(LogStash::Util.stringify_symbols({:a => [1, :b]})).to eq({"a" => [1, "b"]})
      expect(LogStash::Util.stringify_symbols([:a, [1, :b]])).to eq(["a", [1, "b"]])
    end
  end

  describe ".class_name" do
    context "when the class is a top level class" do
      let(:klass) { ClassNameTest.new }

      it "returns the name of the class" do
        expect(subject.class_name(klass)).to eq("ClassNameTest")
      end
    end

    context "when the class is nested inside modules" do
      let(:klass) { TestingClassName::TestKlass.new }

      it "returns the name of the class" do
        expect(subject.class_name(klass)).to eq("TestKlass")
      end
    end
  end
end

Version data entries

58 entries across 57 versions & 9 rubygems

Version Path
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/logstash-core-5.2.1-java/spec/logstash/util_spec.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/logstash-core-5.2.1-java/spec/logstash/util_spec.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/logstash-core-5.0.0-java/spec/logstash/util_spec.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/logstash-core-5.2.1-java/spec/logstash/util_spec.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/logstash-core-5.2.1-java/spec/logstash/util_spec.rb
logstash-filter-csharp-0.1.0 vendor/bundle/jruby/2.3.0/gems/logstash-core-5.2.1-java/spec/logstash/util_spec.rb
logstash-core-5.3.3-java spec/logstash/util_spec.rb
logstash-output-icinga-1.0.0 vendor/jruby/1.9/gems/logstash-core-5.2.1-java/spec/logstash/util_spec.rb
logstash-core-5.3.2-java spec/logstash/util_spec.rb
logstash-core-5.3.1-java spec/logstash/util_spec.rb
logstash-core-5.3.0-java spec/logstash/util_spec.rb
logstash-core-5.2.2-java spec/logstash/util_spec.rb
logstash-input-fifo-0.9.1 vendor/bundle/jruby/1.9/gems/logstash-core-5.1.1.1-java/spec/logstash/util_spec.rb
logstash-input-fifo-0.9.0 vendor/bundle/jruby/1.9/gems/logstash-core-5.1.1.1-java/spec/logstash/util_spec.rb
logstash-core-5.2.1-java spec/logstash/util_spec.rb
logstash-core-5.2.0-java spec/logstash/util_spec.rb
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/logstash-core-5.1.1.1-java/spec/logstash/util_spec.rb
logstash-core-5.1.2-java spec/logstash/util_spec.rb
logstash-core-5.1.1.1-java spec/logstash/util_spec.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/logstash-core-5.1.2.snapshot1-java/spec/logstash/util_spec.rb