summary refs log tree commit diff
diff options
context:
space:
mode:
authorGabriel Horner <gabriel.horner@gmail.com>2010-03-20 04:19:18 -0400
committerGabriel Horner <gabriel.horner@gmail.com>2010-03-20 04:19:18 -0400
commit862244cf77543af841c67e380ef2ee160fed1d76 (patch)
tree045d2ce1722c3c5b5c6c6901fa3d8367d01b8a84
parent0aaf725af9c43ccc97597e6d4621bcc88b290367 (diff)
downloadbacon-862244cf77543af841c67e380ef2ee160fed1d76.tar.gz
bacon-862244cf77543af841c67e380ef2ee160fed1d76.tar.xz
bacon-862244cf77543af841c67e380ef2ee160fed1d76.zip
methods in a context should serve as behavior that is inherited by sibling contexts
-rw-r--r--lib/bacon.rb3
-rw-r--r--test/spec_bacon.rb16
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/bacon.rb b/lib/bacon.rb
index ad4df44..47dc31e 100644
--- a/lib/bacon.rb
+++ b/lib/bacon.rb
@@ -210,6 +210,9 @@ module Bacon
 
     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
diff --git a/test/spec_bacon.rb b/test/spec_bacon.rb
index b1360be..79cdeb1 100644
--- a/test/spec_bacon.rb
+++ b/test/spec_bacon.rb
@@ -344,6 +344,22 @@ describe "shared/behaves_like" do
   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)