この以下のアプリはいくつかのデータをデータベースに保存します。正しく保存されることをテストしたいと思います。
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
すべての仕様でリアクターを起動することが良い習慣かどうかはわかりませんが。助けてください?