Ruby RSpec stubing:按顺序返回

Ruby RSpec stubing:按顺序返回,ruby,rspec,stub,Ruby,Rspec,Stub,我知道以下几点是有效的: 返回参数 subject.should_receive(:get_user_choice){ |choices| choices.to_a[0] } 和序列(第一次调用时返回0,第二次“退出”) 但如何将它们结合起来呢? 如果我想第一次返回参数,然后返回“exit”不是最优雅的,但是如何: n = 0 subject.should_receive(:get_user_choice){|choices| (n += 1) < 2 ? choices.to_a

我知道以下几点是有效的:

返回参数

subject.should_receive(:get_user_choice){ |choices| choices.to_a[0] }
和序列(第一次调用时返回0,第二次“退出”)

但如何将它们结合起来呢?
如果我想第一次返回参数,然后返回“exit”

不是最优雅的,但是如何:

n = 0
subject.should_receive(:get_user_choice){|choices|
   (n += 1) < 2 ? choices.to_a[0] : "exit"
}
n=0
主题。你应该接收(:获取用户选择){选择吗|
(n+=1)<2?选择。到_a[0]:“退出”
}
或者:

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

当我在irb中尝试时,它似乎没有更新计数器。。。一定是做错了什么事(可能是拼写错误..叹气;-))谢谢,这对我有用!
subject.should_receive(:get_user_choice).ordered.and_return { |choices| choices.to_a[0] }
subject.should_receive(:get_user_choice).ordered.and_return { "exit" }