gpt4 book ai didi

ruby-on-rails - 如果您不知道所有 WITH 值,如何使用 Rspec any_instance_of

转载 作者:行者123 更新时间:2023-11-28 21:29:47 25 4
gpt4 key购买 nike

我正在我的测试中创建一条新记录...在创建记录期间,应用程序调用另一个类来通知用户有关记录的创建...

一个人为的例子可能是

 user = User.make!
expect_any_instance_of(Notifier).to receive(:tell_user).with(user.id, new_message_id)
Message.create(author: User.make!, recepient: user, message: 'this is a test')

现在显然我不知道将要创建的消息的 id。
所以我想知道是否有人知道我将如何构造 with 部分期望不关心第二个参数中的值,但关心第一个参数中的值。

感谢您的帮助。

最佳答案

我认为您正在寻找的是 kind_of 方法

user = User.make!
expect_any_instance_of(Notifier).to receive(:tell_user).with(user.id, kind_of(Numeric))
Message.create(author: User.make!, recepient: user, message: 'this is a test')

如果你想更具体一些,你也可以使用instance_of(Fixnum)

关于ruby-on-rails - 如果您不知道所有 WITH 值,如何使用 Rspec any_instance_of,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27007994/

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