Skip to content

Commit

Permalink
Don't use @Injector in tests.
Browse files Browse the repository at this point in the history
I'm frankly unsure why the tests pass with a separate Injector instance as the class methods all still use the Singleton. In any case, this should now protect against any bleed-over between tests as it resets the singleton before each one.
  • Loading branch information
stesla committed Aug 2, 2009
1 parent 478154e commit f47d2f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/injector.rb
Expand Up @@ -31,6 +31,10 @@ def method_missing(name, *args)
def instance
@instance ||= self.new
end

def reset_instance
@instance = nil
end
end

def [] (of)
Expand Down
8 changes: 4 additions & 4 deletions spec/injector_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f47d2f2

Please sign in to comment.