spec/integration/array_spec.rb in transproc-0.1.2 vs spec/integration/array_spec.rb in transproc-0.1.3
- old
+ new
@@ -1,11 +1,11 @@
require 'spec_helper'
describe 'Array transformations with Transproc' do
describe 'map_array' do
it 'applies funtions to all values' do
- map = Transproc(:map_array, Transproc(:symbolize_keys))
+ map = t(:map_array, t(:symbolize_keys))
original = [
{ 'name' => 'Jane', 'title' => 'One' },
{ 'name' => 'Jane', 'title' => 'Two' }
]
@@ -22,11 +22,11 @@
end
end
describe 'map_array!' do
it 'updates array with the result of the function applied to each value' do
- map = Transproc(:map_array!, Transproc(:symbolize_keys))
+ map = t(:map_array!, t(:symbolize_keys))
input = [
{ 'name' => 'Jane', 'title' => 'One' },
{ 'name' => 'Jane', 'title' => 'Two' }
]
@@ -42,24 +42,24 @@
end
end
describe 'wrap' do
it 'returns a new array with wrapped hashes' do
- wrap = Transproc(:wrap, :task, [:title])
+ wrap = t(:wrap, :task, [:title])
input = [{ name: 'Jane', title: 'One' }]
output = [{ name: 'Jane', task: { title: 'One' } }]
expect(wrap[input]).to eql(output)
end
it 'returns a array new with deeply wrapped hashes' do
wrap =
- Transproc(
+ t(
:map_array,
- Transproc(:nest, :user, [:name, :title]),
- Transproc(:map_key, :user, Transproc(:nest, :task, [:title]))
+ t(:nest, :user, [:name, :title]),
+ t(:map_key, :user, t(:nest, :task, [:title]))
)
input = [{ name: 'Jane', title: 'One' }]
output = [{ user: { name: 'Jane', task: { title: 'One' } } }]
@@ -67,31 +67,31 @@
end
end
describe 'group' do
it 'returns a new array with grouped hashes' do
- group = Transproc(:group, :tasks, [:title])
+ group = t(:group, :tasks, [:title])
input = [{ name: 'Jane', title: 'One' }, { name: 'Jane', title: 'Two' }]
output = [{ name: 'Jane', tasks: [{ title: 'One' }, { title: 'Two' }] }]
expect(group[input]).to eql(output)
end
end
describe 'composition' do
it 'allows composing transformations' do
- map = Transproc(:map_array, Transproc(:symbolize_keys))
- group = Transproc(:group, :tasks, [:title])
+ map = t(:map_array, t(:symbolize_keys))
+ group = t(:group, :tasks, [:title])
input = [
{ 'name' => 'Jane', 'title' => 'One' },
{ 'name' => 'Jane', 'title' => 'Two' }
]
output = [{ name: 'Jane', tasks: [{ title: 'One' }, { title: 'Two' }] }]
- transformation = map + group
+ transformation = map >> group
expect(transformation[input]).to eql(output)
end
end
end