module Shoulda::InstanceMethods
def subject
The subject is used by all macros that require an instance of the class
end
end
assert_equal @user, subject # passes
@user = User.new
should "be the existing user" do
class UserTest
class method.
recommended approach for using a different subject is to use the subject
deprecated, and will be removed in a future version of Shoulda. The
instance variable will be used as the subject. This behavior is
If an instance variable exists named after the described class, that
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 if subject_block instance_eval(&subject_block) else get_instance_of(self.class.described_type) end end