Sha256: 585fa71b9f80d46f99edd6d17f8e8f1f62b96f8e0ff2d24e4eb88728486d8dff
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
require 'ostruct' class DependencyInjectionExampleTest < Minitest::Test def test_dependency_injection obj = Invokr.inject( TestObject, :using => { :album => 'farmhouse', :guitarist => 'trey', :drummer => 'fishman', }, ) assert_equal 'farmhouse', obj.album assert_equal 'trey', obj.guitarist end def test_injecting_a_proc my_proc = lambda { |foo,bar| OpenStruct.new foo: foo, bar: bar } 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 def to_proc method :call end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
invokr-0.9.7 | test/dependency_injection_test.rb |