diff --git a/lib/laradi.rb b/lib/laradi.rb index e614bdc..0c8bcfa 100644 --- a/lib/laradi.rb +++ b/lib/laradi.rb @@ -8,9 +8,16 @@ module Laradi module Mixin def dependencies(*deps) + result = {} deps.each { |dep| - include $laradi_injector[dep] + instance = $laradi_injector[dep] + if instance.nil? + raise NoDependencyError, "No dependency found for #{dep}" + end + result[dep] = instance } + + result end end diff --git a/lib/laradi/exceptions.rb b/lib/laradi/exceptions.rb new file mode 100644 index 0000000..5ffc62c --- /dev/null +++ b/lib/laradi/exceptions.rb @@ -0,0 +1,9 @@ +module Laradi + + module Exceptions + class NoDependencyError < Exception + + end + end + +end \ No newline at end of file diff --git a/test/dummy/app/helpers/LogicUnitReceiver.rb b/test/dummy/app/helpers/LogicUnitReceiver.rb index c830d80..7ba53e8 100644 --- a/test/dummy/app/helpers/LogicUnitReceiver.rb +++ b/test/dummy/app/helpers/LogicUnitReceiver.rb @@ -2,7 +2,7 @@ class LogicUnitReceiver include Laradi::Mixin def get_unit - dependencies :logic_unit + dependencies(:logic_unit) => {logic_unit:} logic_unit end diff --git a/test/laradi_test.rb b/test/laradi_test.rb index 6815bd3..1e44a37 100644 --- a/test/laradi_test.rb +++ b/test/laradi_test.rb @@ -14,7 +14,11 @@ class LaradiTest < ActiveSupport::TestCase test "It can inject dependencies" do lur = LogicUnitReceiver.new - assert_not_nil lur.get_unit + result = lur.get_unit + + assert_not_nil result + + assert_kind_of(LogicUnit, result) end end