這下面的應用程序將一些數據保存到數據庫,我想測試它保存正確。如何測試em-mongo + Goliath?
require 'goliath'
class App < Goliath::API
def response(env)
db = EM::Mongo::Connection.new('localhost').db('hello')
db.collection('coll').insert({'identifier => 1'})
[204, {}, {}]
end
end
require 'goliath/test_helper'
Goliath.env = :test
describe App do
include Goliath::TestHelper
it do
with_api(described_class) do
get_request do |req|
db = EM::Mongo::Connection.new('localhost').db('hello')
db.collection('coll').first.callback do |rec|
rec['identifier'].should == 100
end
end
end
end
end
上述規格自從callback
返回前反應器結束。我想過手動啓動反應器,如:
EM.run do
db = EM::Mongo::Connection.new('localhost').db('hello')
db.collection('coll').first.callback do |rec|
rec['identifier'].should == 100
EM.stop
end
end
雖然我不知道是否開始爲每一個規範的反應堆是很好的做法。請幫助?
這樣做,thx!在一個不相關的說明中,從你的博客中學到了很多,thx! –