rspecrspec-mocks

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


Solution

  • 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.