0
我知道我可以嘲笑的对象如下:如何模拟Rails中的关联对象?
Account.any_instance.expects(:type).returns("premium")
我记得听到这被认为是一个贫穷的做法。我喜欢做类似
user = users(:bob)
user.account.expects(:type).returns("premium")
但这似乎并没有模拟正确的对象。有没有比在班上使用any_instance
电话更好的解决方案?
编辑:那我收到错误消息是
not all expectations were satisfied
unsatisfied expectations:
- expected exactly once, not yet invoked: #<Account:0x5f9f8f8>.type(any_parameters)
我认为如果你展示整个方法和整个测试,情况会更好。现在它只能是一个猜测的问题。 – sebkkom 2014-10-08 14:56:44