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

844 Views Asked by At

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

2

There are 2 best solutions below

0
Luc On BEST ANSWER

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.

2
Kedarnag Mukanahallipatna On

I mean why don't you do this

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

instead of

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