Browse files

Made nested contexts w/o a subject block be able to refer to its pare…

…nt subject block

Signed-off-by: Joshua Clayton <jclayton@thoughtbot.com>
  • Loading branch information...
1 parent 61f16a3 commit 2e855629f2b04c63dc3cfd2383e581e52a6cd046 @joshuaclayton joshuaclayton committed Sep 22, 2009
Showing with 13 additions and 2 deletions.
  1. +7 −2 lib/shoulda/context.rb
  2. +6 −0 test/other/context_test.rb
View
9 lib/shoulda/context.rb
@@ -258,9 +258,9 @@ def get_instance_of(object_or_klass) # :nodoc:
def instance_variable_name_for(klass) # :nodoc:
klass.to_s.split('::').last.underscore
end
-
+
private
-
+
def construct_subject
if subject_block
instance_eval(&subject_block)
@@ -327,6 +327,11 @@ def subject(&block)
self.subject_block = block
end
+ def subject_block
+ return @subject_block if @subject_block
+ parent.subject_block
+ end
+
def full_name
parent_name = parent.full_name if am_subcontext?
return [parent_name, name].join(" ").strip
View
6 test/other/context_test.rb
@@ -169,6 +169,12 @@ class ::SomeModel; end
should "return the result of the block as the subject" do
assert_equal @expected, subject
end
+
+ context "nested context block without a subject block" do
+ should "return the result of the parent context's subject block" do
+ assert_equal @expected, subject
+ end
+ end
end
end
end

0 comments on commit 2e85562

Please sign in to comment.