module Shoulda::Context::DSL::InstanceMethods

def construct_subject

def construct_subject
  if subject_block
    instance_eval(&subject_block)
  else
    get_instance_of(self.class.described_type)
  end
end

def get_instance_of(object_or_klass) # :nodoc:

:nodoc:
def get_instance_of(object_or_klass) # :nodoc:
  if object_or_klass.is_a?(Class)
    object_or_klass.new
  else
    object_or_klass
  end
end

def instance_variable_name_for(klass) # :nodoc:

:nodoc:
def instance_variable_name_for(klass) # :nodoc:
  klass.to_s.split('::').last.underscore
end

def subject

being tested.
The subject is used by all macros that require an instance of the class

end
end
assert !subject.new_record? # uses the first user
should "be an existing user" do
subject { User.first }
class UserTest

The subject can be explicitly set using the subject class method:

end
end
assert_kind_of User, subject # passes
should "be a user" do
class UserTest

Returns an instance of the class under test.
def subject
  @shoulda_subject ||= construct_subject
end

def subject_block # :nodoc:

:nodoc:
def subject_block # :nodoc:
  (@shoulda_context && @shoulda_context.subject_block) || self.class.subject_block
end