Commit 5daf5f9
Changed files (4)
lib/spank/ioc.rb
@@ -6,16 +6,27 @@ module Spank
end
def resolve(symbol)
- raise create_error unless class_variable_defined?(:@@container)
+ ensure_initialized!
@@container.resolve(symbol)
end
+ def resolve_all(symbol)
+ ensure_initialized!
+ @@container.resolve_all(symbol)
+ end
+
def unbind
- remove_class_variable(:@@container) if class_variable_defined?(:@@container)
+ if class_variable_defined?(:@@container)
+ remove_class_variable(:@@container)
+ end
end
private
+ def ensure_initialized!
+ raise create_error unless class_variable_defined?(:@@container)
+ end
+
def create_error
ContainerError.new("Spank::IOC.bind_to(container) has not been called.")
end
spec/unit/ioc_spec.rb
@@ -6,22 +6,37 @@ describe Spank::IOC do
context "when bound to a container" do
let(:container) { double }
let(:component) { double }
+ let(:jeans) { double }
+ let(:dress_pants) { double }
before :each do
allow(container).to receive(:resolve).
with(:dbconnection).
and_return(component)
+ allow(container).to receive(:resolve_all).
+ with(:pants).
+ and_return([jeans, dress_pants])
Spank::IOC.bind_to(container)
end
it "resolves the item from the container" do
expect(Spank::IOC.resolve(:dbconnection)).to eq(component)
end
+
+ it "resolves all items from the container" do
+ expect(Spank::IOC.resolve_all(:pants)).to match_array([
+ jeans,
+ dress_pants
+ ])
+ end
end
context "when nothing is bound" do
it "raises a meaningful exception" do
expect { Spank::IOC.resolve(:food) }.to raise_error(Spank::ContainerError)
+ expect do
+ Spank::IOC.resolve_all(:pants)
+ end.to raise_error(Spank::ContainerError)
end
end
end
spec/unit/proxy_spec.rb
@@ -31,14 +31,14 @@ module Spank
proxy.each do |x|
raise StandardError
end
- end.to raise_error
+ end.to raise_error(StandardError)
end
end
end
context "when invoking a method that is not defined on the target" do
it "raises an error" do
- expect { Proxy.new("blah").goodbye }.to raise_error
+ expect { Proxy.new("blah").goodbye }.to raise_error(NoMethodError)
end
end
end
.travis.yml
@@ -2,6 +2,8 @@ language: ruby
rvm:
- 2.0.0
- 2.2.0
+- 2.2.3
+- jruby-9.0.0.0
sudo: false
deploy:
provider: rubygems