次のようにオブジェクトをモックできることを知っています。
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)