gpt4 book ai didi

ruby-on-rails - 如何使用Rspec检查方法是否存在?

转载 作者:行者123 更新时间:2023-12-04 03:40:23 24 4
gpt4 key购买 nike

我想写一个很好的干净的检查方法是否存在:

expect(subscriber.respond_to?(:fake_method)).to be(true)    <-- This fails (as expected)

expect(subscriber).respond_to?(:fake_method) <-- This passes, why?

fake_method不存在,但是当我使用第二种约定时,我的测试通过了。

有任何想法吗?

最佳答案

我相信我有答案。第二种约定不起作用,因为根据文档,匹配器是不同的:

https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/respond-to-matcher

您应该尝试:

expect(subscriber).to respond_to(:fake_method) 

干杯!

关于ruby-on-rails - 如何使用Rspec检查方法是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33021154/

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