Created
March 30, 2015 09:51
-
-
Save maetl/df441f02370ec3100423 to your computer and use it in GitHub Desktop.
Interesting quirk with Structs in Transproc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/integration/hash_spec.rb | |
describe 'combining transformations' do | |
it 'applies functions to a struct' do | |
symbolize_keys = Transproc(:symbolize_keys) | |
map = Transproc(:map_hash, user_name: :name, user_email: :email) | |
transformation = symbolize_keys + map | |
InputUser = Struct.new(:user_name, :user_email) | |
input = InputUser.new('Jade', '[email protected]') | |
output = { name: 'Jade', email: '[email protected]' } | |
result = transformation[input] | |
expect(result).to eql(output) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Failures: | |
1) Hash mapping with Transproc combining transformations applies functions to a struct | |
Failure/Error: result = transformation[input] | |
ArgumentError: | |
odd number of arguments for Hash | |
# ./lib/transproc/hash.rb:3:in `[]' | |
# ./lib/transproc/hash.rb:3:in `block in <module:Transproc>' | |
# ./lib/transproc/function.rb:16:in `[]' | |
# ./lib/transproc/function.rb:16:in `block in compose' | |
# ./lib/transproc/function.rb:11:in `[]' | |
# ./lib/transproc/function.rb:11:in `call' | |
# ./spec/integration/hash_spec.rb:157:in `block (3 levels) in <top (required)>' | |
Finished in 0.06424 seconds (files took 1.66 seconds to load) | |
52 examples, 1 failure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is expected behaviour. Only hashes are fully supported. Structs just happen to work in some cases because they declare the
[]
method as an alternative way of accessing attributes.