gpt4 book ai didi

ruby-on-rails - RSpec should_receive 宏,包含需要测试的内容的 id

转载 作者:数据小太阳 更新时间:2023-10-29 08:40:36 25 4
gpt4 key购买 nike

我如何编写它才能在不对 1 进行硬编码的情况下通过。鸡和蛋。

@sender = Factory(:user)
@receiver = Factory(:user)

mailer = double
mailer.should_receive(:deliver)
Mailer.should_receive(:email).with(1, @sender.id, @receiver.id).and_return(mailer)

# This will create an object with id #1 to make this test pass
@object = Object.create(:sender => @sender, :receiver => @receiver)

最佳答案

这个怎么样?

Mailer.should_receive(:email).with(an_instance_of(Fixnum), @sender.id, @receiver.id).and_return(mailer)

关于ruby-on-rails - RSpec should_receive 宏,包含需要测试的内容的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7397177/

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