Permalink
Browse files

Evaluate explicit subject block in instance context

Closes #17.
  • Loading branch information...
1 parent 0aca341 commit 3b1a992bcd8de3fd51b793a30fa3537a2366f91d @spohlenz spohlenz committed with dchelimsky Apr 3, 2010
Showing with 19 additions and 5 deletions.
  1. +17 −0 features/subject/explicit_subject.feature
  2. +2 −5 lib/rspec/core/example_group_subject.rb
@@ -49,3 +49,20 @@ Feature: explicit subject
When I run "spec top_level_subject_spec.rb"
Then I should see "1 example, 0 failures"
+ Scenario: subject using helper method
+ Given a file named "helper_subject_spec.rb" with:
+ """
+ require 'rspec/expectations'
+
+ describe Array do
+ def prepared_array; [1,2,3] end
+ subject { prepared_array }
+ describe "with some elements" do
+ it "should have the prescribed elements" do
+ subject.should == [1,2,3]
+ end
+ end
+ end
+ """
+ When I run "rspec helper_subject_spec.rb"
+ Then I should see "1 example, 0 failures"
@@ -9,7 +9,7 @@ def self.included(kls)
end
def subject
- @subject ||= self.class.subject.call
+ @subject ||= instance_eval(&self.class.subject)
end
# When +should+ is called with no explicit receiver, the call is
@@ -69,12 +69,9 @@ def explicit_subject
end
def implicit_subject
+ described = describes || description
Class === described ? lambda { described.new } : lambda { described }
end
-
- def described
- @described ||= describes || description
- end
end
end
end

0 comments on commit 3b1a992

Please sign in to comment.