jeudi 1 septembre 2016

Rspec mocking the create call for new activerecord objects

I have an activerecord Object user, in the app I am making I am using a single sign on gem but need to save some of the user data in our db, my application_controller has this code

def create_user
  User.create(name: current_user['name'], email: current_user['email'], company_id: current_user['id'])
end

I need an Rspec test that mocks out the actual create call. I have tried

allow_any_instance_of(User).to receive(:create).with(any_args).and_return(user)

which returns an error saying User does not implement create

Aucun commentaire:

Enregistrer un commentaire