use any_instance_of in rspec

rubyrailsrspec
tomoyukikashiro
tomoyukikashiro

You can use stub like this.

user.stub(:name).and_return("example")

But you can not use stub method to non-initialize object which is initialize in application logic (e.g. ApplicationController)
In this case you need to use any_instance_of method.

ApplicationController.any_instance_of.stub(:auth?).and_return(true)