spec/unit/function_spec.rb in transproc-0.4.2 vs spec/unit/function_spec.rb in transproc-1.0.0

- old
+ new

@@ -1,15 +1,21 @@ require 'spec_helper' describe Transproc::Function do - let(:hashes) { Transproc::HashTransformations } + let(:container) do + Module.new do + extend Transproc::Registry + import Transproc::HashTransformations + end + end + describe '#name' do let(:block) { proc { |v| v } } it 'returns the name of the module function' do - expect(hashes[:symbolize_keys].name).to eql :symbolize_keys + expect(container[:symbolize_keys].name).to eql :symbolize_keys end it 'returns the explicitly assigned name' do expect(described_class.new(block, name: :identity).name).to eql :identity end @@ -19,12 +25,12 @@ end end describe '#>>' do it 'composes named functions' do - f1 = hashes[:symbolize_keys] - f2 = hashes[:rename_keys, user_name: :name] + f1 = container[:symbolize_keys] + f2 = container[:rename_keys, user_name: :name] f3 = f1 >> f2 expect(f3.to_ast).to eql( [ @@ -35,11 +41,11 @@ ] ) expect(f3['user_name' => 'Jane']).to eql(name: 'Jane') - f4 = f3 >> hashes[:nest, :details, [:name]] + f4 = f3 >> container[:nest, :details, [:name]] expect(f4.to_ast).to eql( [ :symbolize_keys, [], [ @@ -53,13 +59,12 @@ expect(f4['user_name' => 'Jane']).to eql(details: { name: 'Jane' }) end it 'composes anonymous functions' do - # TODO: Use Transproc -> (v) { v.to_s } after release of jruby-9k - f1 = Transproc proc { |v, m| v * m }, 2 - f2 = Transproc proc(&:to_s) + f1 = container[->(v, m) { v * m }, 2] + f2 = container[:to_s.to_proc] f3 = f1 >> f2 expect(f3.to_ast).to eql( [ @@ -70,12 +75,12 @@ ] ) end it 'plays well with registered compositions' do - Transproc.register(:user_names, hashes[:symbolize_keys] + hashes[:rename_keys, user_name: :name]) - f = t(:user_names) + container.register(:user_names, container[:symbolize_keys] + container[:rename_keys, user_name: :name]) + f = container[:user_names] expect(f['user_name' => 'Jane']).to eql(name: 'Jane') expect(f.to_ast).to eql( [ :symbolize_keys, [], @@ -85,11 +90,11 @@ ] ) end it 'plays well with registered functions' do - Transproc.register(:to_s, t(:to_string)) - fn = t(:to_s) + container.register(:to_string, Transproc::Coercions.t(:to_string)) + fn = container.t(:to_string) expect(fn[:ok]).to eql('ok') expect(fn.to_ast).to eql([:to_string, []]) end end