RSpec应该接收类的实例对象

时间:2015-09-06 15:57:50

标签: ruby-on-rails ruby-on-rails-3 rspec

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

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

Rails 3

2 个答案:

答案 0 :(得分:1)

答案是: 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

答案 1 :(得分:1)

如果您想让它接收特定类的实例,那么可以使用instance_of

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