RSpec 应该接收 class 的实例对象

RSpec should receive instance object of class

请告诉我如何检查 should_receive 中返回的对象是否是 ClassName 的实例。

Messaging.should_receive(:send_text).with(:foo, :bar, object)

Rails 3

答案是: Messaging.should_receive(:send_text).with(:foo, :bar, kind_of(ClassName))

编辑:正确答案是:

Messaging.should_receive(:send_text).with(:foo, :bar, instance_of(ClassName))

感谢 K M Rakibul Islam

如果你想让它接收一个特定的class的实例,那么可以使用instance_of:

Messaging.should_receive(:send_text).with(:foo, :bar, instance_of(ClassName))