<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/caricature/clr/expectation.rb</filename>
    </added>
    <added>
      <filename>lib/caricature/core_ext.rb</filename>
    </added>
    <added>
      <filename>lib/caricature/core_ext/array.rb</filename>
    </added>
    <added>
      <filename>lib/caricature/core_ext/class.rb</filename>
    </added>
    <added>
      <filename>lib/caricature/core_ext/hash.rb</filename>
    </added>
    <added>
      <filename>lib/caricature/core_ext/module.rb</filename>
    </added>
    <added>
      <filename>lib/caricature/core_ext/object.rb</filename>
    </added>
    <added>
      <filename>lib/caricature/core_ext/string.rb</filename>
    </added>
    <added>
      <filename>lib/caricature/core_ext/system/string.rb</filename>
    </added>
    <added>
      <filename>lib/caricature/core_ext/system/type.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,12 @@
+*** 16/10/2009 ***
+  * Adds raising events
+
 *** 15/10/2009 ***
   * Adds support for partial Hash matching
 
+*** 02/10/2009 ***
+  * Adds subscribing to events
+
 *** 30/09/2009 ***
 
   * Start keeping track of history</diff>
      <filename>History.txt</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,7 @@ module Caricature
 #
 end
 
-require 'core_ext/core_ext'   
+require 'caricature/core_ext'   
 require 'caricature/version'
 require 'caricature/isolation'     
 require 'caricature/clr' if defined? IRONRUBY_VERSION </diff>
      <filename>lib/caricature.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 require File.dirname(__FILE__) + &quot;/clr/descriptor&quot;
 require File.dirname(__FILE__) + &quot;/clr/messenger&quot;
 require File.dirname(__FILE__) + &quot;/clr/isolator&quot;
+require File.dirname(__FILE__) + &quot;/clr/expectation&quot;
 require File.dirname(__FILE__) + &quot;/clr/isolation&quot;
\ No newline at end of file</diff>
      <filename>lib/caricature/clr.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
-load_assembly 'System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
-load_assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
-load_assembly 'System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
+load_assembly 'System.Web.Routing'
+load_assembly 'System.Web.Mvc'
+load_assembly 'System.Web.Abstractions'
 
 include System::Web
 include System::Web::Routing</diff>
      <filename>lib/caricature/clr/aspnet_mvc.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,17 +1,23 @@
 module Caricature
+  
+  
 
-  class Isolation
+  class Isolation # :nodoc:
 
+    # the event subscriptions collected at runtime
     attr_reader :events
-
+    
+    # the event subscriptions collected at runtime
     def events
       @events ||= {}
     end
 
+    # adds an event subscription
     def add_event_subscription(event_name, handler)
       (events[event_name_for(event_name)] ||=[]) &lt;&lt; handler
     end
 
+    # removes an event subscription
     def remove_event_subscription(event_name, handler)
       (events[event_name_for(event_name)] ||=[]).delete(handler)
     end
@@ -40,20 +46,10 @@ module Caricature
           ClrIsolator
         end
     end 
-    
-    protected
-    
-      def internal_create_override(method_name, mode=:instance, &amp;block)
-        builder = ExpectationBuilder.new method_name
-        block.call builder unless block.nil?
-        exp = builder.build           
-        expectations.add_expectation exp, mode
-        exp
-      end
 
     private
 
-    def event_name_for(method_name)
+    def event_name_for(method_name) #:nodoc:
       method_name.gsub(/^(add|remove)_/, '').underscore.to_sym
     end
 </diff>
      <filename>lib/caricature/clr/isolation.rb</filename>
    </modified>
    <modified>
      <diff>@@ -27,7 +27,7 @@ module Caricature
       # You will most likely use this method when you want to verify logic in an event handler
       # You will most likely use this method when you want to verify logic in an event handler
       def raise_event(event_name, *args, &amp;block)
-        isolation_context.raise_event event_name, *args, &amp;block
+        isolation_context.add_event_subscription event_name, *args, &amp;block
       end
 
     end
@@ -51,7 +51,7 @@ module Caricature
     #
     # You will most likely use this method when you want to verify logic in an event handler
     def raise_event(event_name, *args, &amp;block)
-      isolation_context.raise_event event_name, *args, &amp;block
+      isolation_context.add_event_subscription event_name, *args, &amp;block
     end
 
     # Raises an event on the isolation
@@ -76,7 +76,10 @@ module Caricature
       isolation_context.class.raise_event event_name, *args, &amp;block
     end
 
-    
+    # Verifies whether the specified event was raised
+    #
+    # You will probably be using this method only when you're interested in whether an event has been raised
+    # during the course of the test you're running.
     def did_raise_event?(event_name)
       isolation_context.verify_event_raised event_name
     end</diff>
      <filename>lib/caricature/clr/isolator.rb</filename>
    </modified>
    <modified>
      <diff>@@ -35,58 +35,66 @@ module Caricature
   # contains the syntax for building up an expectation
   # This is shared between the +ExpecationBuilder+ and the +Expectation+
   module ExpectationSyntax
+    
     # tell the expection which arguments it needs to respond to
     # there is a magic argument here +any+ which configures
     # the expectation to respond to any arguments
-    def with(*args, &amp;b)
-      @any_args = args.first.is_a?(Symbol) and args.first == :any
-      @args = args   
-      @callback = b unless b.nil?
+    def with(*ags, &amp;b)
+      collected[:any_args] = ags.first.is_a?(Symbol) and ags.first == :any
+      collected[:args] = ags   
+      collected[:callback] = b unless b.nil?
       self
     end
 
     # tell the expectation it nees to return this value or the value returned by the block
     # you provide to this method.
     def return(value=nil, &amp;b)
-      @return_value = value
-      @return_callback = b if b
+      collected[:return_value] = value
+      collected[:return_callback] = b if b
       self
     end
 
     # Sets up arguments for the block that is being passed into the isolated method call
-    def pass_block(*args, &amp;b)
-      @any_block_args = args.first.is_a?(Symbol) and args.first == :any
-      @block_args = args
-      @block_callback = b unless b.nil?
+    def pass_block(*ags, &amp;b)
+      collected[:any_block_args] = ags.first.is_a?(Symbol) and args.first == :any
+      collected[:block_args] = ags
+      collected[:block_callback] = b unless b.nil?
       self
     end
 
     # tell the expectation it needs to raise an error with the specified arguments
     alias_method :actual_raise, :raise
     def raise(*args)
-      @error_args = args
+      collected[:error_args] = args
       self
     end
-
+    
     # tell the expecation it needs to call the super before the expectation exectution
     def super_before(&amp;b)
-      @super = :before
-      @block = b if b
+      collected[:super] = :before
+      collected[:block] = b if b
       self
     end
-
+    
     # tell the expectation it needs to call the super after the expecation execution
     def super_after(&amp;b)
-      @super = :after
-      @block = b if b
+      collected[:super] = :after
+      collected[:block] = b if b
       self
     end
 
     # indicates whether this expectation should match with any arguments
     # or only for the specified arguments
     def any_args?
-      @any_args
+      collected[:any_args]
     end
+    
+    
+    private
+    
+      def collected
+        @collected ||= {}
+      end
   end
 
   # A description of an expectation.
@@ -95,106 +103,140 @@ module Caricature
 
     include ExpectationSyntax
 
-    # gets the method_name to which this expectation needs to listen to
-    attr_reader :method_name
-
-    # the arguments that this expectation needs to be constrained by
-    attr_reader :args
-
     # the error_args that this expectation will raise an error with
-    attr_reader :error_args
+    def error_args
+      collected[:error_args]
+    end
 
     # the value that this expecation will return when executed
-    attr_reader :return_value
+    def return_value
+      collected[:return_value]
+    end
 
     # indicator for the mode to call the super +:before+, +:after+ and +nil+
-    attr_reader :super   
-                         
+    def super 
+      collected[:super]
+    end  
+
     # contains the callback if one is given
-    attr_reader :callback
+    def callback
+      collected[:callback]
+    end
 
     # contains the callback that is used to return the value when this expectation
     # is executed
-    attr_reader :return_callback
+    def return_callback
+      collected[:return_callback]
+    end
 
     # contains the arguments that will be passed on to the block
-    attr_reader :block_args
+    def block_args
+      collected[:block_args]
+    end
 
     # The block that will be used as value provider for the block in the method
-    attr_reader :block_callback
+    def block_callback
+      collected[:block_callback]
+    end
 
     # the block that will be used
-    attr_accessor :block
-
-
+    def block
+      collected[:block]
+    end
+    
+    # sets the block callback 
+    def block=(val)
+      collected[:block] = val
+    end
+    
+    # gets the method_name to which this expectation needs to listen to
+    def method_name 
+      collected[:method_name]
+    end
+    
+    # the arguments that this expectation needs to be constrained by
+    def args
+      collected[:args]
+    end
+    
     # Initializes a new instance of an expectation
-    def initialize(*args)
-      @method_name, @args, @error_args, @return_value, @return_callback,
-              @super, @callback, @block_args, @block_callback, @block = *args
-      @any_args = true
+    def initialize(options={})
+      collected[:any_args] = true
+      collected.merge!(options)
     end
-
+    
     # indicates whether this expecation will raise an event.
     def has_error_args?
-      !@error_args.nil?
+      !collected[:error_args].nil?
     end
 
     # indicates whether this expectation will return a value.
     def has_return_value?
-      !@return_value.nil?
+      !collected[:return_value].nil?
     end
 
     # call the super before the expectation
     def super_before?
-      @super == :before
+      collected[:super] == :before
     end
 
     # indicates whether super needs to be called somewhere
     def call_super?
-      !@super.nil?
+      !collected[:super].nil?
     end      
     
     # indicates whether this expecation has a callback it needs to execute
     def has_callback? 
-      !@callback.nil?
+      !collected[:callback].nil?
     end
-
+    
     # indicates whether this expectation has a block as value provider for the method call block
     def has_block_callback?
-      !@block_callback.nil?
+      !collected[:block_callback].nil?
     end
 
     # a flag to indicate it has a return value callback
     def has_return_callback?
-      !@return_callback.nil?
+      !collected[:return_callback].nil?
     end
     
     # executes this expectation with its configuration
     def execute(*margs,&amp;b)
-      ags = any_args? ? (margs.empty? ? :any : margs) : args
-      actual_raise *@error_args if has_error_args?    
-      callback.call(*ags) if has_callback?
-
-      if b
-        if has_block_callback?
-          b.call(*@block_callback.call)
-        else
-          b.call(*@block_args)
-        end
-      end
+      ags = any_args? ? :any : (margs.empty? ? collected[:args] : margs)
+      do_raise_error
+      do_callback(ags)
+      do_block_callback(&amp;b)
+      do_event_raise if respond_to?(:events)
 
-      return @return_callback.call(*margs) if has_return_callback?
+      return collected[:return_callback].call(*margs) if has_return_callback?
       return return_value if has_return_value? 
       nil
     end
 
-    def to_s
+    def to_s #:nodoc:
       &quot;&lt;Caricature::Expecation, method_name: #{method_name}, args: #{args}, error args: #{error_args}&gt;&quot;
     end
-
-    def inspect
-      to_s
+    alias :inspect :to_s
+    
+    
+    private 
+    
+    def do_raise_error #:nodoc:
+      actual_raise *collected[:error_args] if has_error_args?
+    end
+    
+    def do_callback(ags) #:nodoc:
+      callback.call(*ags) if has_callback?
     end
+    
+    def do_block_callback(&amp;b) #:nodoc:
+      if b
+        ags = has_block_callback? ? collected[:block_callback].call : collected[:block_args]
+        b.call(*ags)
+      end
+    end
+    
+    
   end
 
   # Constructs the expecation object.
@@ -207,14 +249,14 @@ module Caricature
     # this builder is passed into the block to allow only certain
     # operations in the block.
     def initialize(method_name)
-      @method_name, @args, @any_args = method_name, [], true
+      @collected = { :method_name =&gt; method_name, :args =&gt; [], :any_args =&gt; true }
     end
 
 
 
     # build up the expectation with the provided arguments
     def build
-      Expectation.new @method_name, @args, @error_args, @return_value, @return_callback, @super, @callback, @block_args, @block_callback, @block
+      Expectation.new collected
     end
 
   end</diff>
      <filename>lib/caricature/expectation.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,10 +12,18 @@ describe &quot;CLR event handling&quot; do
       lambda { ClrModels::ExposedChangedSubscriber.new(@proxy) }.should.not.raise
     end
 
-#    it &quot;should have 1 event subscription&quot; do
-#
-#    end
+    describe &quot;subscriptions&quot; do
 
+      before do
+        @subscriber = ClrModels::ExposedChangedSubscriber.new(@proxy)
+      end
+
+
+
+      it &quot;should have 1 event subscription&quot; do
+        @proxy.isolation_context.events.size.should == 1
+      end
+    end
   end
 
 end
\ No newline at end of file</diff>
      <filename>spec/bacon/integration/event_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -208,9 +208,9 @@ describe &quot;Caricature::ExpectationBuilder&quot; do
     before do
       builder = Caricature::ExpectationBuilder.new :some_method
       @counter, @args = 0, []
-      builder.with(5) do |*args| 
+      builder.with(5) do |*ags| 
         @counter += 1 
-        @args = args
+        @args = ags
       end
       @expectation = builder.build
     end</diff>
      <filename>spec/bacon/unit/expectation_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -83,5 +83,5 @@ describe &quot;Caricature::Isolation&quot; do
     end
 
   end
-
+  
 end
\ No newline at end of file</diff>
      <filename>spec/bacon/unit/isolation_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>lib/core_ext/array.rb</filename>
    </removed>
    <removed>
      <filename>lib/core_ext/class.rb</filename>
    </removed>
    <removed>
      <filename>lib/core_ext/core_ext.rb</filename>
    </removed>
    <removed>
      <filename>lib/core_ext/hash.rb</filename>
    </removed>
    <removed>
      <filename>lib/core_ext/module.rb</filename>
    </removed>
    <removed>
      <filename>lib/core_ext/object.rb</filename>
    </removed>
    <removed>
      <filename>lib/core_ext/string.rb</filename>
    </removed>
    <removed>
      <filename>lib/core_ext/system/string.rb</filename>
    </removed>
    <removed>
      <filename>lib/core_ext/system/type.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>014a4588838d79825c73cf32481769fe6edb7f9b</id>
    </parent>
  </parents>
  <author>
    <name>Ivan Porto Carrero</name>
    <email>ivan@flanders.co.nz</email>
  </author>
  <url>http://github.com/casualjim/caricature/commit/16a2f4896646132c0ea296041ce444ec82e2702a</url>
  <id>16a2f4896646132c0ea296041ce444ec82e2702a</id>
  <committed-date>2009-10-16T08:26:01-07:00</committed-date>
  <authored-date>2009-10-16T08:19:28-07:00</authored-date>
  <message>Adds support for raising events</message>
  <tree>a010bf5d48cce18f3561302b07152202ed5fcac6</tree>
  <committer>
    <name>Ivan Porto Carrero</name>
    <email>ivan@flanders.co.nz</email>
  </committer>
</commit>
