summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2008-10-25 12:30:00 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2008-10-25 12:30:00 +0200
commit8055e791eae194733fc31cc3687b9a30b8413515 (patch)
treea4ddf09d184b0bd8f374b83692b51402ea754f33 /lib
parent072975b523a5ce6c76a3e826876ae358060b60ce (diff)
downloadbacon-8055e791eae194733fc31cc3687b9a30b8413515.tar.gz
bacon-8055e791eae194733fc31cc3687b9a30b8413515.tar.xz
bacon-8055e791eae194733fc31cc3687b9a30b8413515.zip
De-metaprogram and document nested before/after
Diffstat (limited to 'lib')
-rw-r--r--lib/bacon.rb21
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/bacon.rb b/lib/bacon.rb
index 232b2df..b9774f7 100644
--- a/lib/bacon.rb
+++ b/lib/bacon.rb
@@ -120,6 +120,7 @@ module Bacon
     def run
       return  unless name =~ RestrictContext
       Bacon.handle_specification(name) { instance_eval(&block) }
+      self
     end
 
     def before(&block); @before << block; end
@@ -190,6 +191,13 @@ module Bacon
       end
     end
 
+    def describe(*args, &block)
+      context = Bacon::Context.new(args.join(' '), &block)
+      @before.each { |b| context.before(&b) }
+      @after.each { |b| context.after(&b) }
+      context.run
+    end
+
     def raise?(*args, &block); block.raise?(*args); end
     def throw?(*args, &block); block.throw?(*args); end
     def change?(*args, &block); block.change?(*args); end
@@ -251,20 +259,13 @@ end
 
 
 class Object
-  def should(*args, &block)    Should.new(self).be(*args, &block)         end
+  def should(*args, &block)    Should.new(self).be(*args, &block)             end
 end
 
 module Kernel
   private
-  def describe(*args, &block)
-    context = Bacon::Context.new(args.join(' '), &block)
-    %w[before after].each do |block_type|
-      (instance_variable_get("@#{block_type}") || []).each { |b|  context.send(block_type, &b) }
-    end
-    context.run
-    context
-  end
-  def shared(name, &block)     Bacon::Shared[name] = block                end
+  def describe(*args, &block) Bacon::Context.new(args.join(' '), &block).run  end
+  def shared(name, &block)    Bacon::Shared[name] = block                     end
 end