How do I mock a model that is given to me by a Rails plugin? I’m
trying to mock Session from the restful_authentication plugin but I
get a number of errors telling me RSpec doesn’t recognize Session.
NameError in ‘SessionsController handling GET /sessions/new should be
successful’
uninitialized constant Session
An example of my usage:
before do @session = mock_model(Session)
Session.stub!(:new).and_return(@session)
end
You can stick that in spec_helper.rb if you use Session in a lot of
places.
I think you can also do Session.class_eval {} somewhere and that’ll
load up the actual Session class instead of the dummy implementation I
just showed. It won’t use the implementation in your specs of course,
but it loads the provided class into memory.
How do I mock a model that is given to me by a Rails plugin? I’m
trying to mock Session from the restful_authentication plugin but I
get a number of errors telling me RSpec doesn’t recognize Session.
NameError in ‘SessionsController handling GET /sessions/new should
be successful’
uninitialized constant Session
Your problem is that the class isn’t just Session, it’s
CGI::Session::ActiveRecordStore::Session