summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--lib/bacon.rb17
-rw-r--r--test/spec_bacon.rb19
2 files changed, 34 insertions, 2 deletions
diff --git a/lib/bacon.rb b/lib/bacon.rb
index b34a9f2..26079e3 100644
--- a/lib/bacon.rb
+++ b/lib/bacon.rb
@@ -109,10 +109,15 @@ module Bacon
   end
 
   class Context
+    attr_reader :name, :block
+    
     def initialize(name, &block)
       @name = name
       @before, @after = [], []
-
+      @block = block
+    end
+    
+    def run
       return  unless name =~ RestrictContext
       Bacon.handle_specification(name) { instance_eval(&block) }
     end
@@ -251,7 +256,15 @@ end
 
 module Kernel
   private
-  def describe(*args, &block)  Bacon::Context.new(args.join(' '), &block) end
+  def describe(*args, &block)
+    befores = instance_variable_get('@before') || []
+    context = Bacon::Context.new(args.join(' '), &block)
+    befores.each do |b|
+      context.before &b
+    end
+    context.run
+    context
+  end
   def shared(name, &block)     Bacon::Shared[name] = block                end
 end
 
diff --git a/test/spec_bacon.rb b/test/spec_bacon.rb
index 1779704..fd3e09b 100644
--- a/test/spec_bacon.rb
+++ b/test/spec_bacon.rb
@@ -278,6 +278,25 @@ describe "before/after" do
     @a.should.equal 2
     @b.should.equal 2
   end
+  
+  describe "when nested" do
+    before do
+      @c = 5
+    end
+    
+    it "should run from higher level" do
+      @a.should.equal 2
+      @b.should.equal 2
+    end
+    
+    it "should run at the nested level" do
+      @c.should.equal 5
+    end
+  end
+  
+  it "should not run from lower level" do
+    @c.should.be.nil
+  end
 end
 
 shared "a shared context" do