Skip to content

Commit

Permalink
methods in a context should serve as behavior that is inherited by si…
Browse files Browse the repository at this point in the history
…bling contexts
  • Loading branch information
cldwalker committed Mar 20, 2010
1 parent 0aaf725 commit 862244c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/bacon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ def run_requirement(description, spec)

def describe(*args, &block)
context = Bacon::Context.new(args.join(' '), &block)
(parent_context = self).methods(false).each {|e|
class<<context; self end.send(:define_method, e) {|*args| parent_context.send(e, *args)}
}
@before.each { |b| context.before(&b) }
@after.each { |b| context.after(&b) }
context.run
Expand Down
16 changes: 16 additions & 0 deletions test/spec_bacon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,22 @@ def equal_string(x)
behaves_like "another shared context"
end

describe "Methods" do
def the_meaning_of_life
42
end

it "should be accessible in a test" do
the_meaning_of_life.should == 42
end

describe "when in a sibling context" do
it "should be accessible in a test" do
the_meaning_of_life.should == 42
end
end
end

describe 'describe arguments' do

def check(ctx,name)
Expand Down

0 comments on commit 862244c

Please sign in to comment.