Sha256: ac295b01aa3a1ba27cc2b37d3260c8ce9ccfd52dfe01f056217feefb0b18c8a3

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

describe Hash do
  describe "#rename_keys" do
    it "to be [:baz, :bar]" do
      expect({ foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar).keys).to eq([:baz, :bar])
    end

    it "to be [:foo, 'tick']" do
      expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys('baz' => 'tick').keys).to eq([:foo, 'tick'])
    end

    it "to be [:bar, :tick]" do
      expect({ foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar, baz: :tick).keys).to eq([:bar, :tick])
    end

    it "to be [:bar, 'tick']" do
      expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys(foo: :bar, 'baz' => 'tick').keys).to eq([:bar, 'tick'])
    end
  end

  describe "#stringify_keys(!)" do
    it "to be ['foo', 'bar']" do
      expect({ foo: 'foo', 'bar' => 'bar' }.stringify_keys.keys).to eq(['foo', 'bar'])
      expect({ foo: 'foo', 'bar' => 'bar' }.stringify_keys!.keys).to eq(['foo', 'bar'])
    end
  end

  describe "#symbolize_keys(!)" do
    it "to be [:foo, :bar]" do
      expect({ foo: 'foo', 'bar' => 'bar' }.symbolize_keys.keys).to eq([:foo, :bar])
      expect({ foo: 'foo', 'bar' => 'bar' }.symbolize_keys!.keys).to eq([:foo, :bar])
    end
  end

  describe "#symbolize_and_underscore_keys(!)" do
    it "to be [:foo_bar, :baz_bar]" do
      expect({ 'foo_Bar' => 'example', bazBar: 'string' }.symbolize_and_underscore_keys.keys).to eq([:foo_bar, :baz_bar])
      expect({ 'foo_Bar' => 'example', bazBar: 'string' }.symbolize_and_underscore_keys.keys).to eq([:foo_bar, :baz_bar])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flash_extensions-0.0.1 spec/lib/hash_extension_spec.rb