Permalink
Browse files

Implement `its` using new `subject` powers

  • Loading branch information...
1 parent f7ab113 commit f43027844e818dcea8da72e96c7f7863e38f485c @exviva exviva committed with myronmarston Jan 4, 2013
Showing with 8 additions and 19 deletions.
  1. +8 −19 lib/rspec/core/memoized_helpers.rb
View
27 lib/rspec/core/memoized_helpers.rb
@@ -73,16 +73,6 @@ def should_not(matcher=nil, message=nil)
private
- def _attribute_chain(attribute)
- attribute.to_s.split('.')
- end
-
- def _nested_attribute(subject, attribute)
- _attribute_chain(attribute).inject(subject) do |inner_subject, attr|
- inner_subject.send(attr)
- end
- end
-
# @private
def __memoized
@__memoized ||= {}
@@ -341,18 +331,17 @@ def subject!(name=nil, &block)
# end
def its(attribute, &block)
describe(attribute) do
- example do
- self.class.class_eval do
- define_method(:subject) do
- if defined?(@_subject)
- @_subject
- else
- @_subject = Array === attribute ? super()[*attribute] : _nested_attribute(super(), attribute)
- end
+ if Array === attribute
+ subject { super()[*attribute] }
+ else
+ subject do
+ attribute_chain = attribute.to_s.split('.')
+ attribute_chain.inject(super()) do |inner_subject, attr|
+ inner_subject.send(attr)
end
end
- instance_eval(&block)
end
+ example(&block)
end
end
end

0 comments on commit f430278

Please sign in to comment.