RSpec should_receive 宏,包含需要测试的内容的 id [英] RSpec should_receive macro that includes id of what needs to be tested

查看:31
本文介绍了RSpec should_receive 宏,包含需要测试的内容的 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何编写它才能在不硬编码 1 的情况下通过.鸡和蛋.

How can I write this so it passes without hardcoding 1. Chicken and the egg.

@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)

这篇关于RSpec should_receive 宏,包含需要测试的内容的 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆