main
 1describe Spank::IOC do
 2  after :each do
 3    Spank::IOC.unbind
 4  end
 5
 6  context "when bound to a container" do
 7    let(:container) { double }
 8    let(:component) { double }
 9    let(:jeans) { double }
10    let(:dress_pants) { double }
11
12    before :each do
13      allow(container).to receive(:resolve).
14        with(:dbconnection).
15        and_return(component)
16      allow(container).to receive(:resolve_all).
17        with(:pants).
18        and_return([jeans, dress_pants])
19      Spank::IOC.bind_to(container)
20    end
21
22    it "resolves the item from the container" do
23      expect(Spank::IOC.resolve(:dbconnection)).to eq(component)
24    end
25
26    it "resolves all items from the container" do
27      expect(Spank::IOC.resolve_all(:pants)).to match_array([
28        jeans,
29        dress_pants
30      ])
31    end
32  end
33
34  context "when nothing is bound" do
35    it "raises a meaningful exception" do
36      expect { Spank::IOC.resolve(:food) }.to raise_error(Spank::ContainerError)
37      expect do
38        Spank::IOC.resolve_all(:pants)
39      end.to raise_error(Spank::ContainerError)
40    end
41  end
42end