From 8055e791eae194733fc31cc3687b9a30b8413515 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Sat, 25 Oct 2008 12:30:00 +0200 Subject: De-metaprogram and document nested before/after --- lib/bacon.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lib/bacon.rb') 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 -- cgit 1.4.1