Skip to content

Commit

Permalink
Made nested contexts w/o a subject block be able to refer to its pare…
Browse files Browse the repository at this point in the history
…nt subject block

Signed-off-by: Joshua Clayton <[email protected]>
  • Loading branch information
joshuaclayton committed Sep 22, 2009
1 parent 61f16a3 commit 2e85562
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/shoulda/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/other/context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e85562

Please sign in to comment.