$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib') require 'mongo' 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'] || 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 @coll_full_name = 'ruby-mongo-test.test' end def teardown @coll.clear unless @coll == nil || @db.socket.closed? end def test_close @db.close assert @db.socket.closed? begin @coll.insert('a' => 1) fail "expected IOError exception" rescue IOError => ex assert_match /closed stream/, ex.to_s end end def test_full_coll_name assert_equal @coll_full_name, @db.full_coll_name(@coll.name) end def test_master # Doesn't really test anything since we probably only have one database # during this test. @db.switch_to_master assert_not_nil @db.socket end end