gpt4 book ai didi

mocking - stub 中的 any_number_of_times 方法的替代方法

转载 作者:行者123 更新时间:2023-12-03 04:42:36 27 4
gpt4 key购买 nike

我已将项目升级到 Rails 4,但现在收到一些弃用警告,其中之一是弃用:any_number_of_times 已弃用。。我收到此警告的代码是

sponsorship = RSpec::Mocks::Mock.new(:sponsorship)

SPONSORSHIP.should_receive(:[]).with('sponsorship').any_number_of_times.and_return(sponsorship)

另一种情况是

sponsorship.should_receive(:[]).with(key).any_number_of_times.and_return(value)

我在上面的代码中使用了 stub ,但它没有正确 stub 。你能找到我哪里做错了吗?对于 stub 我用过

SPONSORSHIP.stub(:[]).with('sponsorship').and_return(sponsorship)

最佳答案

方法any_number_of_times已被弃用(并且在RSpec 3中消失),因为它并没有真正测试任何东西。它永远不会失败,因为它也可以被调用 0 次。请参阅 https://trello.com/c/p2OsobvA/78-update-website-menu-architecture-to-accommodate-pledging-as-well-as-weddings-memorials-etc 中的扩展参数.

如果您希望至少调用一次,可以使用at_least(1).times

关于mocking - stub 中的 any_number_of_times 方法的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19227124/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com