我怎样才能让Rspec甚至Ruby读取Faye消息?他们在Faye的日志中通过,但我似乎无法通过Rspec连接到Faye:
it 'gets Faye message' do
EM.run do
client = Faye::Client.new('http://localhost:9292/faye')
sub = client.subscribe('/documents') do |message|
puts message
end
sub.callback do |message|
puts message
end
end
end这个就挂了。这些信息会出现在菲的日志里。我做错了什么?
发布于 2015-11-27 22:35:58
所以我解决了我自己的问题。我将在这里发布我的解决方案,以防它帮助到其他人。
it 'generates a document process and gets a push response from faye' do
EM.run do
client = Faye::Client.new('http://localhost:9292/faye')
Thread.new { subject.perform(:generate, id) }
client.subscribe "/documents/#{id}/notify" do |response|
publication = client.publish("/documents/#{id}/notify", '0')
publication.callback do
if response != '0'
expect(response).to eq(id.to_s)
EM.stop
else
p "FAYE RESPONSE: #{response}" # diagnostic only
end
end
publication.errback { |error| p "FAYE RESPONSE: #{error.inspect}" }
end
end
end我的最终游戏只是让Rspec获得从subject.perform...进程发送的Faye消息。任务完成。不是世界上最整洁的东西,但谁在乎呢。
发布于 2015-11-27 07:59:08
http://www.rubydoc.info/github/eventmachine/eventmachine/EventMachine.run (读取便笺块)
我会说EM.run调用块(从不返回并等待连接),这就是测试挂起的原因。虽然没有真正看到你的测试试图做什么,所以我不能给你一个如何改进的指针。
https://stackoverflow.com/questions/33948736
复制相似问题