如何使用 minitest 对同一函数进行多次调用以获得不同的 returns
How to stub multiple calls to same function to get different returns using minitest
我正在尝试存根 class 方法。该方法多次调用 'gets'。我想手动 return 特定值到 'gets' 调用。
我的代码与此类似 -
ParseAndPlay.stub :gets, {***NEED SOMETHING HERE***} do
ParseAndPlay.run
end
和ParseAndPlay.run期望
def ParseAndPlay.run
gets #=> expects "5 5"
gets #=> "1 1 N"
gets #=> "MMM" ... and so on
end
仅使用 minitest 就可以做到吗?
我最终更改了正在测试的 class。调用了一个新函数 'get_input',然后调用了 'gets',然后存根了 'get_input' 方法。
我正在尝试存根 class 方法。该方法多次调用 'gets'。我想手动 return 特定值到 'gets' 调用。 我的代码与此类似 -
ParseAndPlay.stub :gets, {***NEED SOMETHING HERE***} do
ParseAndPlay.run
end
和ParseAndPlay.run期望
def ParseAndPlay.run
gets #=> expects "5 5"
gets #=> "1 1 N"
gets #=> "MMM" ... and so on
end
仅使用 minitest 就可以做到吗?
我最终更改了正在测试的 class。调用了一个新函数 'get_input',然后调用了 'gets',然后存根了 'get_input' 方法。