Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / spec / spec / dsl / composite_proc_builder_spec.rb
blobeacec3f65e13a0ee12c33276a0b15e4022b42468
1 require File.dirname(__FILE__) + '/../../spec_helper'
3 module Spec
4   module DSL
5     describe CompositeProcBuilder do
6       before(:each) do
7         @klass = Class.new do
8           attr_reader :an_attribute
10           def an_attribute_setter
11             @an_attribute = :the_value
12           end
13         end
15         @parent = @klass.new
16         @builder = CompositeProcBuilder.new {}
17       end
19       it "calls all of its child procs" do
20         @builder << proc {:proc1}
21         @builder << proc {:proc2}
22         @builder.proc.call.should == [:proc1, :proc2]
23       end
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}
32         errors = []
33         @builder.proc {|e| errors << e }.call.should == [exception1, exception2, :successful]
35         errors.should == [exception1, exception2]
36       end
38       it "evals procs in the caller's instance" do
39         the_proc = proc do
40           @an_attribute = :the_value
41         end
42         the_proc.class.should == Proc
43         @builder << the_proc
44         @parent.instance_eval &@builder.proc
45         @parent.an_attribute.should == :the_value
46       end
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
54       end
55     end
56   end
57 end