Is there a way to have mocha raise an exception the first time an stub
is called, and then return a value the second time it is called?
First example, I’m trying to connect to a server and test the case where
my first attempt raises a ‘Server busy’ exception or something of that
sort. So I wait, then retry and then the second time the connection is
successful.
Is there a way to have mocha raise an exception the first time an stub
is called, and then return a value the second time it is called?
First example, I’m trying to connect to a server and test the case where
my first attempt raises a ‘Server busy’ exception or something of that
sort. So I wait, then retry and then the second time the connection is
successful.
server.expects(:connect).returns do
server.expects(:connect).returns(true)
raise Busy
end
Is there a way to have mocha raise an exception the first time an stub
is called, and then return a value the second time it is called?
First example, I’m trying to connect to a server and test the case where
my first attempt raises a ‘Server busy’ exception or something of that
sort. So I wait, then retry and then the second time the connection is
successful.
Thanks for the help both of you! I ended up using the method James
proposed (it was cleaner ).
Very interesting thread too. From a usability standpoint, adding a
raises method to TestCase seems to provide the most intuitive syntax…
at least for me it does. Can’t wait to see how things pan out!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.