diff options
-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 |