require 'spec_helper' describe Hash do describe "#except" do it "to be {}" do expect({}.except(:foo)).to eq({}) end it "to be { :foo => 1 }" do expect({ :foo => 1, :baz => 2, :bar => 3 }.except(:baz, :bar)).to eq({ :foo => 1 }) expect({ foo: 1, baz: 2, bar: 3 }.except(:baz, :bar)).to eq({ foo: 1 }) end it "to be { :baz => 2, :bar => 3 }" do expect({ :foo => 1, :baz => 2, :bar => 3 }.except(:foo)).to eq({ :baz => 2, :bar => 3 }) expect({ foo: 1, baz: 2, bar: 3 }.except(:foo)).to eq({ baz: 2, bar: 3 }) end end describe "#only" do it "to be {}" do expect({}.only(:foo)).to eq({}) end it "to be { :foo => 1 }" do expect({ :foo => 1, :baz => 2, :bar => 3 }.only(:foo)).to eq({ :foo => 1 }) expect({ foo: 1, baz: 2, bar: 3 }.only(:foo)).to eq({ foo: 1 }) end it "to be { :baz => 2, :bar => 3 }" do expect({ :foo => 1, :baz => 2, :bar => 3 }.only(:baz, :bar)).to eq({ :baz => 2, :bar => 3 }) expect({ foo: 1, baz: 2, bar: 3 }.only(:baz, :bar)).to eq({ baz: 2, bar: 3 }) end end describe "#rename_keys(!)" do it "to be [:baz, :bar]" do expect({ foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar).keys).to eq([:baz, :bar]) 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']) 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]) 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']) 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