Permalink
Browse files

Adds overrides to isolate

  • Loading branch information...
1 parent 9cb2247 commit b1129f7eb431d662b757efca821e1d75fbc77f7c Pawel Pierzchala committed Jul 23, 2012
Showing with 14 additions and 2 deletions.
  1. +3 −2 lib/dependor/isolate.rb
  2. +11 −0 spec/dependor/isolate_spec.rb
View
@@ -1,7 +1,8 @@
module Dependor::Isolate
- def isolate(klass)
+ def isolate(klass, overrides = {})
injector = Dependor::SendingInjector.new(self)
- instantiator = Dependor::Instantiator.new(injector)
+ customized_injector = Dependor::CustomizedInjector.new(injector, overrides)
+ instantiator = Dependor::Instantiator.new(customized_injector)
instantiator.instantiate(klass)
end
end
@@ -12,6 +12,10 @@ def subject
isolate(ExampleSubject)
end
+ def override
+ isolate(ExampleSubject, bar: "bar was overriden")
+ end
+
def foo
"the foo stub"
end
@@ -27,4 +31,11 @@ def bar
context.subject.foo.should == "the foo stub"
context.subject.bar.should == "the bar stub"
end
+
+ it "allows overriding dependencies" do
+ context = ExampleContext.new
+
+ context.override.bar.should == "bar was overriden"
+ context.override.foo.should == "the foo stub"
+ end
end

0 comments on commit b1129f7

Please sign in to comment.