1 require File.dirname(__FILE__) + '/../../spec_helper'
5 describe CompositeProcBuilder do
8 attr_reader :an_attribute
10 def an_attribute_setter
11 @an_attribute = :the_value
16 @builder = CompositeProcBuilder.new {}
19 it "calls all of its child procs" do
20 @builder << proc {:proc1}
21 @builder << proc {:proc2}
22 @builder.proc.call.should == [:proc1, :proc2]
25 it "calls block on exceptions" do
26 exception1 = Exception.new("Proc1 Error")
27 exception2 = Exception.new("Proc2 Error")
28 @builder << proc {raise exception1}
29 @builder << proc {raise exception2}
30 @builder << proc {:successful}
33 @builder.proc {|e| errors << e }.call.should == [exception1, exception2, :successful]
35 errors.should == [exception1, exception2]
38 it "evals procs in the caller's instance" do
40 @an_attribute = :the_value
42 the_proc.class.should == Proc
44 @parent.instance_eval &@builder.proc
45 @parent.an_attribute.should == :the_value
48 it "binds unbound methods to the parent" do
49 unbound_method = @klass.instance_method(:an_attribute_setter)
50 unbound_method.class.should == UnboundMethod
51 @builder << unbound_method
52 @parent.instance_eval &@builder.proc
53 @parent.an_attribute.should == :the_value