main
 1require "spec_helper"
 2
 3module Nasty
 4  describe Lazy do
 5    context "when lazy loading an item from a factory" do
 6      context "when invoking a method on the proxy" do
 7        let(:factory) { double }
 8        let(:blackbook) { double }
 9
10        before :each do
11          blackbook.stub(:find).and_return("nasty")
12          Lazy.bind_factory do |key|
13            blackbook if key == :blackbook
14          end
15        end
16
17        it "should invoke the target" do
18          Lazy.load(:blackbook).find(:booty).should == "nasty"
19        end
20      end
21
22      context "before invocation" do
23        let(:factory) { ->(*args) { @called = true } }
24
25        before :each do
26          Lazy.load(:blackbook, factory)
27        end
28
29        it "does not resolve the component from the factory" do
30          @called.should be_false
31        end
32      end
33    end
34  end
35end