Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Evaluate explicit subject block in instance context

  • Loading branch information...
commit 2ab053d148dd7865acac059fc0eff1829e31dd63 1 parent 8000a34
@spohlenz authored
View
18 features/subject/explicit_subject.feature
@@ -33,3 +33,21 @@ Feature: explicit subject
"""
When I run "rspec nested_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"
View
7 lib/rspec/core/example_group_subject.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.