In RSpec, I have a function that creates a new stream, and inside this stream performs some action - in my case, it calls TCPSocket#readline . Here's the function as it is now:
def read Thread.new do while line = @socket.readline
Due to thread scheduling, my test will fail if it is written as such:
it "reads from socket" do subject.socket.should_receive(:readline) subject.read end
Currently, the only way I know is to use sleep 0.1 . Is there a way to properly delay the test until this thread is started?
Nick acker
source share