mardi 5 mai 2015

Testing infinite loop with MiniTest and using mocking

I have a section in my code which polls a queue for a message and then acts on it depending on the message type:

@queue = Foo::Queue.new
loop do
  @queue.poll do |message|                                                                                                                              
    if message[:task] == TAKEACTION
      result = takeaction(message)
      @queue.send_result(result, message)
    end
    @queue.pong(message) if message[:task] == PING
  end
end

How do I set up a test to supply a single message and verify that the @queue acts on it as I expect?

I have seen very little about testing blocks in minitest, and haven't found anything in ruby regarding breaking out of infinite loops, though I found one idea in python where you set up the second run to throw an exception.

Can any ruby / minitest gurus help?

Aucun commentaire:

Enregistrer un commentaire