include XGen::Mongo::Driver in test classes

This commit is contained in:
Jim Menard 2008-12-18 21:57:20 -05:00
parent 80475ff198
commit b4f11caff8
5 changed files with 20 additions and 12 deletions

View File

@ -5,6 +5,8 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class BSONTest < Test::Unit::TestCase
include XGen::Mongo::Driver
def setup
@b = BSON.new
end
@ -40,7 +42,7 @@ class BSONTest < Test::Unit::TestCase
end
def test_oid
doc = {'doc' => XGen::Mongo::Driver::ObjectID.new}
doc = {'doc' => ObjectID.new}
@b.serialize(doc)
assert_equal doc, @b.deserialize
end

View File

@ -5,10 +5,12 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class DBAPITest < Test::Unit::TestCase
include XGen::Mongo::Driver
def setup
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
@db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
@db = Mongo.new(host, port).db('ruby-mongo-test')
@coll = @db.collection('test')
@coll.clear
@r1 = @coll.insert('a' => 1) # collection not created until it's used

View File

@ -5,10 +5,12 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class DBConnectionTest < Test::Unit::TestCase
include XGen::Mongo::Driver
def test_no_exceptions
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-demo')
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
db = Mongo.new(host, port).db('ruby-mongo-demo')
coll = db.collection('test')
coll.clear
end

View File

@ -4,15 +4,17 @@ require 'test/unit'
class MessageTest < Test::Unit::TestCase
include XGen::Mongo::Driver
def setup
@msg = XGen::Mongo::Driver::Message.new(42)
@msg = Message.new(42)
end
def test_initial_info
assert_equal XGen::Mongo::Driver::Message::HEADER_SIZE, @msg.buf.length
assert_equal Message::HEADER_SIZE, @msg.buf.length
@msg.write_long(1029)
@msg.buf.rewind
assert_equal XGen::Mongo::Driver::Message::HEADER_SIZE + 8, @msg.buf.get_int
assert_equal Message::HEADER_SIZE + 8, @msg.buf.get_int
@msg.buf.get_int # skip message id
assert_equal 0, @msg.buf.get_int
assert_equal 42, @msg.buf.get_int
@ -22,12 +24,12 @@ class MessageTest < Test::Unit::TestCase
def test_update_length
@msg.update_message_length
@msg.buf.rewind
assert_equal XGen::Mongo::Driver::Message::HEADER_SIZE, @msg.buf.get_int
assert_equal Message::HEADER_SIZE, @msg.buf.get_int
end
def test_long_length
@msg.write_long(1027)
assert_equal XGen::Mongo::Driver::Message::HEADER_SIZE + 8, @msg.buf.length
assert_equal Message::HEADER_SIZE + 8, @msg.buf.length
end
end

View File

@ -53,8 +53,8 @@ class ObjectIDTest < Test::Unit::TestCase
def test_save_and_restore
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
db = Mongo.new(host, port).db('ruby-mongo-test')
coll = db.collection('test')
coll.clear