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-core-5.0.0.alpha5.snapshot1-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha4.snapshot3-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha4.snapshot2-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha4.snapshot1-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha3-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha3.snapshot8-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha3.snapshot7-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha3.snapshot6-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha3.snapshot5-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha3.snapshot4-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha3.snapshot2-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha3.snapshot1-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha2-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha2.snapshot2-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha2.snapshot1-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha1-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha1.snapshot2-java spec/logstash/util_spec.rb
logstash-core-5.0.0.alpha1.snapshot1-java spec/logstash/util_spec.rb