我知道以下事情有效:
返回一个参数
subject.should_receive(:get_user_choice){ |choices| choices.to_a[0] }
和一个序列(它将在第一次调用时返回 0,第二次“退出”)
subject.should_receive(:get_user_choice).and_return(0, "exit")
但是如何组合它们呢? 如果我想第一次返回参数然后返回“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" }
关于ruby - RSpec stub : return in a sequence,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7754733/