0

我正在努力弄清楚如何存根以下内容:

def max_post_limit
    Post.on(date).count > some_limit
end

我试图存根 Post... 部分,而不是方法。到目前为止,我已经尝试了以下和类似的变体。全部返回 0 或 1。

before do 
    Post.stubs(:on).returns([])
    Post.stubs.(:on).with(date).returns([])
    Post.stubs.(:count).returns(some_limit)
end

任何建议将不胜感激,谢谢。

4

1 回答 1

0

尝试:

allow(Post).to receive_message_chain(:on, :count) { 123 }

于 2015-06-04T22:08:00.893 回答