Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

memoize subject with its\n\n- Closes #292

  • Loading branch information...
commit 599c0c9878adf7818f2a29e1b7bc5cb53a5348ca 1 parent 56b6a65
@dchelimsky dchelimsky authored
View
14 lib/rspec/core/subject.rb
@@ -124,13 +124,13 @@ def its(attribute, &block)
example do
self.class.class_eval do
define_method(:subject) do
- if super().is_a?(Hash) && attribute.is_a?(Array)
- OpenStruct.new(super()).send(attribute.first)
- else
- attribute.to_s.split('.').inject(super()) do |target, method|
- target.send(method)
- end
- end
+ @_subject ||= if super().is_a?(Hash) && attribute.is_a?(Array)
+ OpenStruct.new(super()).send(attribute.first)
+ else
+ attribute.to_s.split('.').inject(super()) do |target, method|
+ target.send(method)
+ end
+ end
end
end
instance_eval(&block)
View
4 spec/rspec/core/example_group_spec.rb
@@ -646,7 +646,9 @@ def attribute_call_count
end
end.new
end
- its(:attribute_call_count) { should_not == 2 }
+
+ its(:attribute_call_count) { should eq(1) }
+
context "with nil value" do
subject do
Class.new do
Please sign in to comment.
Something went wrong with that request. Please try again.