加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

嘲笑 – 存根中的any_number_of_times方法的替代

发布时间:2020-12-16 22:06:03 所属栏目:百科 来源:网络整理
导读:我已将我的项目升级到rails 4,但是现在我得到了一些不赞成的警告,其中一个是DEPRECATION:any_number_of_times已被弃用..我收到这个警告的代码是 sponsorship = RSpec::Mocks::Mock.new(:sponsorship)SPONSORSHIP.should_receive(:[]).with('sponsorship').a
我已将我的项目升级到rails 4,但是现在我得到了一些不赞成的警告,其中一个是DEPRECATION: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)

我已经使用存根上面的代码,但它没有正确的stubbing.你能找到我做错了什么对于stubbing我已经使用

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读