4

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

Leticia Esperon
  • 2,499
  • 1
  • 18
  • 40

2 Answers2

1

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.

Luc
  • 143
  • 6
0

I mean why don't you do this

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

instead of

allow(GoogleMapsService::Client).to receive(:initialize)
ThangLeQuoc
  • 2,272
  • 2
  • 19
  • 30
  • 2
    Mmm that doesn't work: `GoogleMapsService::Client does not implement #new` – Leticia Esperon Sep 19 '18 at 21:39
  • 1
    @LeticiaEsperon, That is because `.new` is called on the class itself rather than on an instance of the class. Try using `allow(GoogleMapsService::Client).to receive(:new)`. – Mark Schneider May 17 '19 at 08:17