module RSpec::Core::Subject
def self.included(kls)
def self.included(kls) kls.extend ClassMethods kls.__send__ :alias_method, :__should_for_example_group__, :should kls.__send__ :alias_method, :__should_not_for_example_group__, :should_not end
def attribute_of_subject
def attribute_of_subject original_subject.send(example.description) if using_attribute? end
def original_subject
def original_subject @original_subject ||= instance_eval(&self.class.subject) end
def should(matcher=nil, message=nil)
it { should be_eligible_to_vote }
describe Person do
== Examples
expressions.
an implicit subject (see +subject+), this supports very concise
delegated to the object returned by +subject+. Combined with
When +should+ is called with no explicit receiver, the call is
def should(matcher=nil, message=nil) self == subject ? self.__should_for_example_group__(matcher) : subject.should(matcher,message) end
def should_not(matcher=nil, message=nil)
it { should_not be_eligible_to_vote }
describe Person do
== Examples
explicit) of the example group.
Just like +should+, +should_not+ delegates to the subject (implicit or
def should_not(matcher=nil, message=nil) self == subject ? self.__should_not_for_example_group__(matcher) : subject.should_not(matcher,message) end
def subject
def subject using_attribute? ? attribute_of_subject : original_subject end
def using_attribute?
def using_attribute? example.in_block? && example.metadata[:attribute_of_subject] end