<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>wheel/before_and_after_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -2,6 +2,15 @@
 
 RSpec lite. Smaller, faster. Really just an experiment for now, but we'll see where it goes.
 
+== Installation
+
+Install gemcutter
+  ~$ gem install gemcutter
+Add gemcutter.org to your gem remote sources
+  ~$ gem tumble
+Download and install this gem
+  ~$ gem install wheel
+
 == Copyright
 
 Copyright (c) 2009 Michael Berkowitz. See LICENSE for details.</diff>
      <filename>README.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@ begin
   require 'rubygems'
   require 'mikowitz-color'
 rescue
-  module Color
+  module Color #:nodoc:
     def self.method_missing(method, *args)
       if args[1] == false
         print args.first</diff>
      <filename>lib/wheel.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,11 +2,9 @@ module Wheel
   class Example
     include CustomMatchers
     attr_reader :name, :parent_name, :backtrace, :block
-    attr_reader :parent_group
     
-    def initialize(name, parent_name, parent_group, &amp;block)
+    def initialize(name, parent_name, &amp;block)
       @backtrace = caller(0)
-      @parent_group = parent_group
       @name, @parent_name = name, parent_name, (block || lambda { raise PendingExpectation.new(name, &quot;Not Yet Implemented&quot;)})
       if block.nil? or block.empty?
         @block = lambda { raise PendingExpectation.new(name, &quot;Not Yet Implemented&quot;)}
@@ -15,8 +13,8 @@ module Wheel
       end
     end
     
-    def run_example
-      parent_group.instance_eval(&amp;@block)
+    def run_example(example_group)
+      example_group.instance_eval(&amp;@block)
     end
     
     def full_name</diff>
      <filename>lib/wheel/example.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,12 +3,13 @@ module Wheel
     include CustomMatchers    
 
     attr_reader :name, :parent_name, :examples, :example_groups
-    attr_accessor :before_all_block, :before_each_block
-    attr_accessor :after_all_block, :after_each_block
+    attr_accessor :before_all_blocks, :before_each_blocks
+    attr_accessor :after_all_blocks, :after_each_blocks
 
     def initialize(name, parent_name, &amp;block)
       @name, @parent_name = name, parent_name
       @examples, @example_groups = [], []
+      @before_all_blocks, @before_each_blocks, @after_all_blocks, @after_each_blocks = [], [], [], []
       instance_eval(&amp;block)
     end
     
@@ -22,17 +23,25 @@ module Wheel
     end
     
     def it(name, &amp;block)
-      self.examples &lt;&lt; Example.new(name, self.full_name, self, &amp;block)
+      self.examples &lt;&lt; Example.new(name, self.full_name, &amp;block)
     end
     
     def before(frequency = :all, &amp;block)
       if frequency == :all
-        @before_all_block = block
+        before_all_blocks &lt;&lt; block
       else
-        @before_each_block = block
+        before_each_blocks &lt;&lt; block
       end
     end
     
+    def after(frequency = :all, &amp;block)
+      if frequency == :all
+        after_all_blocks &lt;&lt; block
+      else
+        after_each_blocks &lt;&lt; block
+      end      
+    end
+    
     def pending(name, &amp;block)
       self.examples &lt;&lt; Example.new(name, self.full_name)
     end</diff>
      <filename>lib/wheel/example_group.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,6 +4,8 @@ module Wheel
     @@errors = []
     @@pending = []
     @@examples = 0
+    @@current_parent_example_group = nil
+    
     
     def self.failures; @@failures; end
     def self.errors; @@errors; end
@@ -24,22 +26,35 @@ module Wheel
     end
     
     def self.run_example_group(eg)
+      @@current_parent_example_group ||= eg
       formatter.print_suite_name(eg.full_name) unless eg.examples.empty?
-      eg.instance_eval(&amp;eg.before_all_block) if eg.before_all_block
+      run_setup_or_teardown_blocks(eg, @@current_parent_example_group, :before_all)
       eg.examples.each do |ex|
-        eg.instance_eval(&amp;eg.before_each_block) if eg.before_each_block
-        self._pass_or_die(ex, eg.before_each_block)
+        run_setup_or_teardown_blocks(eg, @@current_parent_example_group, :before_each)
+        _pass_or_die(ex, @@current_parent_example_group)
+        run_setup_or_teardown_blocks(eg, @@current_parent_example_group, :after_each)
       end
       eg.example_groups.each do |sub_eg|
-        sub_eg.instance_eval(&amp;eg.before_all_block) if eg.before_all_block
+        sub_eg.before_each_blocks += (@@current_parent_example_group.before_each_blocks + eg.before_each_blocks).uniq
+        sub_eg.after_each_blocks += (@@current_parent_example_group.after_each_blocks + eg.after_each_blocks).uniq
         run_example_group(sub_eg)
+        sub_eg.after_each_blocks-= (@@current_parent_example_group.after_each_blocks + eg.after_each_blocks).uniq
+        sub_eg.before_each_blocks -= (@@current_parent_example_group.before_each_blocks + eg.before_each_blocks).uniq
+      end
+      run_setup_or_teardown_blocks(eg, @@current_parent_example_group, :after_all)
+      @@current_parent_example_group = nil if eg.parent_name.nil?
+    end
+    
+    def self.run_setup_or_teardown_blocks(source, target, block_type)
+      source.send(&quot;#{block_type.to_s}_blocks&quot;).each do |b|
+        target.instance_eval(&amp;b)
       end
     end
     
-    def self._pass_or_die(ex, proc)
+    def self._pass_or_die(ex, eg)
       self.examples += 1
       begin
-        ex.run_example
+        ex.run_example(eg)
         formatter.print_success(ex.name)
       rescue FailedExpectation =&gt; err
         self.failures &lt;&lt; [err, ex]</diff>
      <filename>lib/wheel/test_runner.rb</filename>
    </modified>
    <modified>
      <diff>@@ -19,7 +19,7 @@
 describe &quot;Wheel&quot; do
   before do
     @ex_group = Wheel::ExampleGroup.new(&quot;group name&quot;, &quot;group parent name&quot;) do; end
-    @example = Wheel::Example.new(&quot;example name&quot;, &quot;group name&quot;, @ex_group) do; end
+    @example = Wheel::Example.new(&quot;example name&quot;, &quot;group name&quot;) do; end
     @failure = [Wheel::FailedExpectation.new(&quot;test name&quot;, &quot;message&quot;), @example]
     @pending = [Wheel::PendingExpectation.new(&quot;test name&quot;, &quot;pending message&quot;), @example]
     @error = [SyntaxError.new, @example]</diff>
      <filename>wheel/formatting_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ae4878277a99fbce392dfc0f0b9a53f5c224aa5d</id>
    </parent>
  </parents>
  <author>
    <name>Michael Berkowitz</name>
    <email>michael.berkowitz@gmail.com</email>
  </author>
  <url>http://github.com/mikowitz/wheel/commit/6f11a79591f533356100e709013a6f65300d5d85</url>
  <id>6f11a79591f533356100e709013a6f65300d5d85</id>
  <committed-date>2009-11-08T20:11:01-08:00</committed-date>
  <authored-date>2009-11-08T20:11:01-08:00</authored-date>
  <message>before and after blocks work correctly.</message>
  <tree>f0b52136a1092f46412b28e1133705c64cec6d8f</tree>
  <committer>
    <name>Michael Berkowitz</name>
    <email>michael.berkowitz@gmail.com</email>
  </committer>
</commit>
