How to mock a nonexistent class with Rspec Mock

Asked

Viewed 95 times

0

I’m creating a lib that will use a model pattern of Rails, only that for the development of this lib I need to test without the presence of this model.

So think about mocking (I’m using Gem rspec-mock), tried so:

it '#user_autenticated?' do
  allow('User').to receive(:where).and_return([double('User', cpf: '00011122233344')])

  auth = Rbot::Auth.new(maestro)
  expect(auth.user_autenticated?).not_to be nil
end

But unfortunately I get the error:

"User" does not implement: where

Does anyone know a way out of this problem?

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.