How to stub multiple calls to same function to get different returns using minitest

959 views Asked by At

I am trying to stub a class method. The method has multiple calls to 'gets'. I wanted to manually return specific values to 'gets' calls. My code is similar to this -

ParseAndPlay.stub :gets, {***NEED SOMETHING HERE***} do
    ParseAndPlay.run
end

and ParseAndPlay.run expects

def ParseAndPlay.run
    gets #=> expects "5 5"
    gets #=> "1 1 N"
    gets #=> "MMM" ... and so on
end

Can this be done by just using minitest?

1

There are 1 answers

0
Harish Ved On BEST ANSWER

I ended up changing the class that was being tested. Called a new function 'get_input' which then called 'gets' and then stubbed the 'get_input' method.