这下面的应用程序将一些数据保存到数据库,我想测试它保存正确。如何测试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! –