diff options
Diffstat (limited to 'lib/bacon.rb')
-rw-r--r-- | lib/bacon.rb | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/bacon.rb b/lib/bacon.rb index 0288987..627f79d 100644 --- a/lib/bacon.rb +++ b/lib/bacon.rb @@ -6,6 +6,9 @@ module Bacon Counter = Hash.new(0) ErrorLog = "" + Shared = Hash.new { |_, name| + raise NameError, "no such context: #{name.inspect}" + } module SpecDoxOutput def handle_specification(name) @@ -104,15 +107,19 @@ module Bacon instance_eval(&block) end end - + def before(&block); @before << block; end def after(&block); @after << block; end - + + def behaves_like(name) + instance_eval &Bacon::Shared[name] + end + def it(description, &block) Bacon::Counter[:specifications] += 1 run_requirement description, block end - + def run_requirement(description, spec) Bacon.handle_requirement description do begin @@ -191,6 +198,10 @@ module Kernel def describe(name, &block) Bacon::Context.new(name, &block) end + + def shared(name, &block) + Bacon::Shared[name] = block + end end |