Faye 和 Ruby:已 Rspec 阅读 Faye 日志或消息
Faye and Ruby: have Rspec read Faye log or messages
如何让 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
这只是挂起。这些消息来自 Faye 的日志。我做错了什么?
http://www.rubydoc.info/github/eventmachine/eventmachine/EventMachine.run
(阅读注释块)
我会说 EM.run 调用块(从不 returns 并等待连接),这就是您的测试挂起的原因。
虽然没有真正看到你的测试试图做什么,所以我不能给你一个关于如何改进它的指导。
所以我已经解决了我自己的问题。如果对其他人有帮助,我会 post 将我的解决方案放在这里。
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 消息。任务完成。不是世界上最整洁的东西,但谁在乎呢。
如何让 Rspec 甚至 Ruby 阅读 Faye 消息?他们在 Faye 的日志中正常显示,但我似乎无法通过 Rspec:
连接到 Fayeit '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
这只是挂起。这些消息来自 Faye 的日志。我做错了什么?
http://www.rubydoc.info/github/eventmachine/eventmachine/EventMachine.run (阅读注释块)
我会说 EM.run 调用块(从不 returns 并等待连接),这就是您的测试挂起的原因。 虽然没有真正看到你的测试试图做什么,所以我不能给你一个关于如何改进它的指导。
所以我已经解决了我自己的问题。如果对其他人有帮助,我会 post 将我的解决方案放在这里。
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 消息。任务完成。不是世界上最整洁的东西,但谁在乎呢。