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
249:     def subject
250:       @shoulda_subject ||= construct_subject
251:     end

Private Instance Methods

construct_subject() click to toggle source
     # File lib/shoulda/context.rb, line 271
271:     def construct_subject
272:       if subject_block
273:         instance_eval(&subject_block)
274:       else
275:         get_instance_of(self.class.described_type)
276:       end
277:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.