我知道我可以按如下方式模拟对象:
Account.any_instance.expects(:type).returns("premium")
我记得听说这被认为是一种糟糕的做法。我想做类似的事情
user = users(:bob)
user.account.expects(:type).returns("premium")
但这似乎并没有模拟正确的对象。有没有比any_instance
在课堂上使用 call 更好的解决方案?
编辑:我得到的错误信息是
not all expectations were satisfied
unsatisfied expectations:
- expected exactly once, not yet invoked: #<Account:0x5f9f8f8>.type(any_parameters)