Module: Shoulda::InstanceMethods

### Home Classes Methods

### In Files

- lib/shoulda/context.rb

### Methods

- #subject

### Files

- CONTRIBUTION_GUIDELINES.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- Shoulda
- Shoulda::ActionController
- Shoulda::ActionController::Macros
- Shoulda::ActionController::Matchers
- Shoulda::ActionMailer
- Shoulda::ActionMailer::Assertions
- Shoulda::ActionMailer::Matchers
- Shoulda::ActiveRecord
- Shoulda::ActiveRecord::Assertions
- Shoulda::ActiveRecord::Helpers
- Shoulda::ActiveRecord::Macros
- Shoulda::ActiveRecord::Matchers
- Shoulda::Assertions
- Shoulda::ClassMethods
- Shoulda::Helpers
- Shoulda::InstanceMethods
- Shoulda::Macros
- ActionController
- Test

No matching classes.

# Shoulda::InstanceMethods

### Public Instance Methods

subject() click to toggle source

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

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

    # File lib/shoulda/context.rb, line 249
    def subject
      @shoulda_subject ||= construct_subject
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.