diff --git a/lib/shoulda/context.rb b/lib/shoulda/context.rb index 64aa3b6d..25606935 100644 --- a/lib/shoulda/context.rb +++ b/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 diff --git a/test/other/context_test.rb b/test/other/context_test.rb index c4d696e1..0a5feecf 100644 --- a/test/other/context_test.rb +++ b/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