diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2008-10-25 12:30:00 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2008-10-25 12:30:00 +0200 |
commit | 8055e791eae194733fc31cc3687b9a30b8413515 (patch) | |
tree | a4ddf09d184b0bd8f374b83692b51402ea754f33 | |
parent | 072975b523a5ce6c76a3e826876ae358060b60ce (diff) | |
download | bacon-8055e791eae194733fc31cc3687b9a30b8413515.tar.gz bacon-8055e791eae194733fc31cc3687b9a30b8413515.tar.xz bacon-8055e791eae194733fc31cc3687b9a30b8413515.zip |
De-metaprogram and document nested before/after
-rw-r--r-- | README | 5 | ||||
-rw-r--r-- | lib/bacon.rb | 21 |
2 files changed, 15 insertions, 11 deletions
diff --git a/README b/README index b9aacaa..a8050e4 100644 --- a/README +++ b/README @@ -132,6 +132,8 @@ It also supports TAP: before and after need to be defined before the first specification in a context and are run before and after each specification. +As of Bacon 1.1, before and after do nest in nested contexts. + == Shared contexts @@ -232,7 +234,8 @@ It can be found at http://opensource.thinkrelevance.com/wiki/spec_converter. * Bug fixes. * XXX, 2008: Third public release 1.1. - * Add -Q/--no-backtraces to not details about failed specifications. + * Add -Q/--no-backtraces to not show details about failed specifications. + * Nested before/after == Contact 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 |