2009-12-01 18:49:57 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require 'rubygems' if ENV['C_EXT']
|
2009-11-30 22:50:54 +00:00
|
|
|
require 'mongo'
|
2009-10-20 15:31:07 +00:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
begin
|
2009-12-01 18:49:57 +00:00
|
|
|
require 'rubygems'
|
2010-02-22 20:49:04 +00:00
|
|
|
require 'shoulda'
|
2009-10-20 15:31:07 +00:00
|
|
|
require 'mocha'
|
|
|
|
rescue LoadError
|
|
|
|
puts <<MSG
|
|
|
|
|
2010-02-22 20:49:04 +00:00
|
|
|
This test suite requires shoulda and mocha.
|
|
|
|
You can install them as follows:
|
|
|
|
gem install shoulda
|
2009-10-20 15:31:07 +00:00
|
|
|
gem install mocha
|
|
|
|
|
|
|
|
MSG
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2010-10-14 20:11:30 +00:00
|
|
|
require 'bson_ext/cbson' if !(RUBY_PLATFORM =~ /java/) && ENV['C_EXT']
|
2009-12-01 18:49:57 +00:00
|
|
|
|
2010-10-07 21:05:45 +00:00
|
|
|
unless defined? MONGO_TEST_DB
|
2010-12-15 17:55:06 +00:00
|
|
|
MONGO_TEST_DB = 'ruby-test-db'
|
2010-10-07 21:05:45 +00:00
|
|
|
end
|
2010-04-05 19:48:35 +00:00
|
|
|
|
2010-12-10 16:12:18 +00:00
|
|
|
unless defined? TEST_PORT
|
2010-12-10 21:00:35 +00:00
|
|
|
TEST_PORT = ENV['MONGO_RUBY_DRIVER_PORT'] ? ENV['MONGO_RUBY_DRIVER_PORT'].to_i : Mongo::Connection::DEFAULT_PORT
|
2010-12-10 16:12:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
unless defined? TEST_HOST
|
|
|
|
TEST_HOST = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
|
|
|
end
|
|
|
|
|
2009-10-20 15:31:07 +00:00
|
|
|
class Test::Unit::TestCase
|
|
|
|
include Mongo
|
2010-04-05 14:39:55 +00:00
|
|
|
include BSON
|
2009-11-23 18:13:14 +00:00
|
|
|
|
2010-10-13 21:09:23 +00:00
|
|
|
def self.standard_connection(options={})
|
2010-12-10 16:12:18 +00:00
|
|
|
Connection.new(TEST_HOST, TEST_PORT, options)
|
2010-10-13 21:09:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def standard_connection(options={})
|
|
|
|
self.class.standard_connection(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.host_port
|
|
|
|
"#{mongo_host}:#{mongo_port}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.mongo_host
|
2010-12-10 16:12:18 +00:00
|
|
|
TEST_HOST
|
2010-10-13 21:09:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.mongo_port
|
2010-12-10 16:12:18 +00:00
|
|
|
TEST_PORT
|
2010-10-13 21:09:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def host_port
|
|
|
|
self.class.host_port
|
|
|
|
end
|
|
|
|
|
|
|
|
def mongo_host
|
|
|
|
self.class.mongo_host
|
|
|
|
end
|
|
|
|
|
|
|
|
def mongo_port
|
|
|
|
self.class.mongo_port
|
|
|
|
end
|
|
|
|
|
2010-12-13 21:25:23 +00:00
|
|
|
|
2010-05-04 20:00:05 +00:00
|
|
|
def assert_raise_error(klass, message)
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
rescue => e
|
|
|
|
assert_equal klass, e.class
|
|
|
|
assert e.message.include?(message), "#{e.message} does not include #{message}."
|
2010-08-02 22:19:54 +00:00
|
|
|
else
|
|
|
|
flunk "Expected assertion #{klass} but none was raised."
|
2010-05-04 20:00:05 +00:00
|
|
|
end
|
|
|
|
end
|
2009-10-20 15:31:07 +00:00
|
|
|
end
|