spec/integration/hash_spec.rb in transproc-0.1.0 vs spec/integration/hash_spec.rb in transproc-0.1.1
- old
+ new
@@ -24,15 +24,38 @@
expect(input).to eql(output)
end
end
- describe 'nest!' do
+ describe 'nest' do
it 'returns new hash with keys nested under a new key' do
- nest = Transproc(:nest!, :baz, ['foo'])
+ nest = Transproc(:nest, :baz, ['foo'])
input = { 'foo' => 'bar' }
output = { baz: { 'foo' => 'bar' } }
+
+ expect(nest[input]).to eql(output)
+ expect(input).to eql('foo' => 'bar')
+ end
+ end
+
+ describe 'nest!' do
+ it 'returns new hash with keys nested under a new key' do
+ nest = Transproc(:nest!, :baz, ['one', 'two', 'not-here'])
+
+ input = { 'foo' => 'bar', 'one' => nil, 'two' => false }
+ output = { 'foo' => 'bar', baz: { 'one' => nil, 'two' => false } }
+
+ nest[input]
+
+ expect(input).to eql(output)
+ end
+
+ it 'returns new hash with nil nested under a new key when nest-keys are missing' do
+ nest = Transproc(:nest!, :baz, ['foo'])
+
+ input = { 'bar' => 'foo' }
+ output = { 'bar' => 'foo', baz: nil }
nest[input]
expect(input).to eql(output)
end