summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorYossef Mendelssohn <ymendel@pobox.com>2008-10-24 17:01:51 -0500
committerYossef Mendelssohn <ymendel@pobox.com>2008-10-24 17:15:01 -0500
commita52cbeac0162b6f786f0ee9fc8b34d74cf4abc6e (patch)
tree50441067f9eb425aa790d60538be52ef284e8ed8 /lib
parent3271c1d2c4fe469301274a04a7b28b372f68913c (diff)
downloadbacon-a52cbeac0162b6f786f0ee9fc8b34d74cf4abc6e.tar.gz
bacon-a52cbeac0162b6f786f0ee9fc8b34d74cf4abc6e.tar.xz
bacon-a52cbeac0162b6f786f0ee9fc8b34d74cf4abc6e.zip
Letting before blocks be run from higher levels in nested context
Split up Context#initialize to let running be a separate step.
Added attr_reader for Context name and block to let the running step have access
to them without resorting to instance variables.
Diffstat (limited to 'lib')
-rw-r--r--lib/bacon.rb17
1 files changed, 15 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