jjzjj

NameBuilder

全部标签

ruby - 如何避免使用 allow_any_instance_of?

假设我们有以下代码:classAdefcreate_serveroptions={name:NameBuilder.new.build_name}do_some_operations(options)endend为了测试这些方法,我曾经使用allow_any_instance_of:it'doesoperations'doallow_any_instance_of(NameBuilder).toreceive(:build_name)#testbodyend但是文档建议我们不要使用它becauseofseveralreasons.那么如何避免allow_any_instance_of呢