Module Shoulda::InstanceMethods
In: lib/shoulda/context.rb

Methods

subject  

Public Instance methods

Returns an instance of the class under test.

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

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

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

If an instance variable exists named after the described class, that instance variable will be used as the subject. This behavior is deprecated, and will be removed in a future version of Shoulda. The recommended approach for using a different subject is to use the subject class method.

  class UserTest
    should "be the existing user" do
      @user = User.new
      assert_equal @user, subject # passes
    end
  end

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

[Validate]