RSpec 2: uninitialized constant - mocking belongs_to AR relation

gems/ruby-1.9.2-head/bundler/gems/rspec-
core-2398fcadf5beb256bed9c548c59445d3b4c8a047-master/lib/rspec/core/
backward_compatibility.rb:26:in const_missing': uninitialized constant Message::User (NameError) from /Users/kristianconsult/.rvm/gems/ruby-1.9.2-head/bundler/gems/ rspec-expectations-996c752171a0a0e16347e934dadc25767e31186c-master/lib/ rspec/expectations/backward_compatibility.rb:6:inconst_missing’
from /Users/kristianconsult/Development/Languages/Ruby/Apps/Web-apps/
Rails/Rails-3/Experimental/views_example/app/models/message.rb:2:in
<class:Message>' from /Users/kristianconsult/Development/Languages/Ruby/Apps/Web-apps/ Rails/Rails-3/Experimental/views_example/app/models/message.rb:1:in<top (required)>’

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

validates_presence_of :title, :text, :recipient
end

require ‘spec_helper’

class User
end

describe Message do
before(:each) do
@message = Message.new(
:title => “foo”,
:text => “bar”,
:recipient => mock_model(User)
)
end

If I uncomment the :class_name option on the belongs_to relation of
Message:

Failure/Error: @message = Message.new(
uninitialized constant Message::Recipient

Hmm??

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”