Skip to content

Commit

Permalink
De-metaprogram and document nested before/after
Browse files Browse the repository at this point in the history
  • Loading branch information
leahneukirchen committed Oct 25, 2008
1 parent 072975b commit 8055e79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 4 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions lib/bacon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def initialize(name, &block)
def run
return unless name =~ RestrictContext
Bacon.handle_specification(name) { instance_eval(&block) }
self
end

def before(&block); @before << block; end
Expand Down Expand Up @@ -190,6 +191,13 @@ def run_requirement(description, spec)
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
Expand Down Expand Up @@ -251,20 +259,13 @@ def close?(to, delta)


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


Expand Down

0 comments on commit 8055e79

Please sign in to comment.