diff --git a/lib/injector.rb b/lib/injector.rb index 99d3a7a..edd73f6 100644 --- a/lib/injector.rb +++ b/lib/injector.rb @@ -31,6 +31,10 @@ def method_missing(name, *args) def instance @instance ||= self.new end + + def reset_instance + @instance = nil + end end def [] (of) diff --git a/spec/injector_spec.rb b/spec/injector_spec.rb index bb2e164..f441022 100644 --- a/spec/injector_spec.rb +++ b/spec/injector_spec.rb @@ -2,16 +2,16 @@ describe Injector do before (:each) do - @injector = Injector.new + Injector.reset_instance end it 'should blow up if there is no binding for a class' do - lambda { @injector[String] }.should raise_error(Injector::NotFound) + lambda { Injector[String] }.should raise_error(Injector::NotFound) end it 'should find a class that has used the inject keyword' do klass = Class.new { inject } - @injector[klass].class.should == klass + Injector[klass].class.should == klass end it 'should pass in dependencies' do @@ -23,7 +23,7 @@ attr_reader :foo, :bar end - k = @injector[klass] + k = Injector[klass] k.class.should == klass k.foo.should_not be_nil k.foo.class.should == dep_foo