我正在我的测试中创建一条新记录...在创建记录期间,应用程序调用另一个类来通知用户有关记录的创建...
一个人为的例子可能是
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/