Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I supress warning "removing `initialize' may cause serious problems" in rspec?

I have a test that does:

allow_any_instance_of(GoogleMapsService::Client).to receive(:initialize)

and I'm getting warning: removing 'initialize' may cause serious problems, but I didn't find any other way to stub this.

How can I solve it in another way so I don't get the warning or how can I silence the warning?

Thank you very much

like image 213
Leticia Esperon Avatar asked Sep 13 '25 20:09

Leticia Esperon


2 Answers

The #initialize method is called on the instance while the #new method is called on the class so you could do something like:

allow(GoogleMapsService::Client).to receive(:new)

See This issue for more context.

like image 184
Luc Avatar answered Sep 17 '25 19:09

Luc


I mean why don't you do this

allow(GoogleMapsService::Client).to receive(:new)

instead of

allow(GoogleMapsService::Client).to receive(:initialize)
like image 22
Kedarnag Mukanahallipatna Avatar answered Sep 17 '25 18:09

Kedarnag Mukanahallipatna