Forum: RSpec Accessing the model class from within an rspec-rails spec

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cameron B. (Guest)
on 2008-10-30 05:38
(Received via mailing list)
Hi everybody,

New to the list, so apologies if this has been answered elsewhere, but
I didn't find it. I'm trying to build up a plugin of useful rspec
macros for rails development, eg. things like:

it_should_return_success
it_should_redirect_to { some_url }

I'm basing my ideas off of some stuff technoweenie has done, as well
as a few others.

One thing I'd love to do is be able to figure out the model class in a
rails model spec, so I can do something like:

describe User do
    it_should_validate_presence_of :name
end

I can get it working if I pass in User as an argument:

describe User do
    it_should_validate_presence_of User, :name
end

but that feels redundant. Is there a way to access the class itself
that I'm missing? On the controller spec side, I see there is
controller_class_name, but that needs to be set with the
controller_name method. I could go for something like that if
required, but somehow it seems like it would be overkill.

Any advice would be greatly appreciated, thanks!!

Cameron
This topic is locked and can not be replied to.