[rspec-users] RSpec 2: uninitialized constant - mocking belongs_to AR relation

Kristian Mandrup kmandrup at gmail.com
Sun Jun 13 07:03:20 EDT 2010


Cause of error:

class Message < ActiveRecord::Base
  belongs_to :recipient #, :class_name => User.name
--
it then by convention expects there to be a model class called
Recipient.

should instead be

class Message < ActiveRecord::Base
  belongs_to :recipient, :class_name => User.name

But then the User class must be a subclass of ActiveRecord, or have a
name method that returns "User" or even more simple:

class Message < ActiveRecord::Base
  belongs_to :recipient, :class_name => "User"




More information about the rspec-users mailing list