test/dependency_injection_test.rb in invokr-0.9.3 vs test/dependency_injection_test.rb in invokr-0.9.4

- old
+ new

@@ -14,27 +14,52 @@ assert_equal 'farmhouse', obj.album assert_equal 'trey', obj.guitarist end def test_injecting_a_proc - my_proc = -> foo do OpenStruct.new foo: foo end + my_proc = -> (foo,bar) do OpenStruct.new foo: foo, bar: bar end obj = Invokr.inject( my_proc, :using => { :foo => 'bar', + :bar => 'baz', :ping => 'pong', } ) assert_equal 'bar', obj.foo + assert_equal 'baz', obj.bar end + def test_injecting_proc_duck_type + obj = Invokr.inject( + TestProcDuckType.new, + :using => { + :foo => 'FOO', + :bar => 'BAZ', + }, + ) + + assert_equal 'FOO', obj.foo + assert_equal 'BAZ', obj.bar + end + class TestObject attr :album, :guitarist def initialize album, guitarist: 'jimmy' @album = album @guitarist = guitarist + end + end + + class TestProcDuckType + def parameters + [[:req, :foo],[:req, :bar]] + end + + def call(foo, bar) + OpenStruct.new foo: foo, bar: bar end end end