RSpec Stubbing:按顺序返回 [英] RSpec Stubbing: return in a sequence

查看:35
本文介绍了RSpec Stubbing:按顺序返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道以下事情有效:

返回参数

subject.should_receive(:get_user_choice){ |choices| choices.to_a[0] }

和一个序列(它会在第一次调用时返回 0,第二次退出")

and a sequence (it will return a 0 on the first call, and the second time "exit")

subject.should_receive(:get_user_choice).and_return(0, "exit")

但是如何组合它们呢?如果我想第一次返回参数然后返回exit"怎么办

But how to combine them? what if I would like to return the parameter the first time and then return "exit"

推荐答案

或者:

subject.should_receive(:get_user_choice).ordered.and_return { |choices| choices.to_a[0] }
subject.should_receive(:get_user_choice).ordered.and_return { "exit" }

这篇关于RSpec Stubbing:按顺序返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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