minor: removed shoulda dependency
This commit is contained in:
parent
0368e79c74
commit
54a68c7438
26
README.rdoc
26
README.rdoc
@ -292,12 +292,10 @@ It's also possible to test replica pairs with connection pooling:
|
|||||||
|
|
||||||
$ rake test:pooled_pair_insert
|
$ rake test:pooled_pair_insert
|
||||||
|
|
||||||
===Shoulda and Mocha
|
===Mocha
|
||||||
|
|
||||||
All tests now require shoulda and mocha. You can install these gems as
|
Running the test suite requires mocha. You can install it as follows:
|
||||||
follows:
|
|
||||||
|
|
||||||
$ gem install shoulda
|
|
||||||
$ gem install mocha
|
$ gem install mocha
|
||||||
|
|
||||||
The tests assume that the Mongo database is running on the default port. You
|
The tests assume that the Mongo database is running on the default port. You
|
||||||
@ -305,23 +303,6 @@ can override the default host (localhost) and port (Connection::DEFAULT_PORT) by
|
|||||||
using the environment variables MONGO_RUBY_DRIVER_HOST and
|
using the environment variables MONGO_RUBY_DRIVER_HOST and
|
||||||
MONGO_RUBY_DRIVER_PORT.
|
MONGO_RUBY_DRIVER_PORT.
|
||||||
|
|
||||||
The project mongo-qa (http://github.com/mongodb/mongo-qa) contains many more
|
|
||||||
Mongo driver tests that are language independent. To run thoses tests as part
|
|
||||||
of the "rake test" task, download the code "next to" this directory. So, after
|
|
||||||
installing the mongo-qa code you would have these two directories next to each
|
|
||||||
other:
|
|
||||||
|
|
||||||
$ ls
|
|
||||||
mongo-qa
|
|
||||||
mongo-ruby-driver
|
|
||||||
$ rake test
|
|
||||||
|
|
||||||
The tests run just fine if the mongo-qa directory is not there.
|
|
||||||
|
|
||||||
Additionally, the script bin/validate is used by the mongo-qa project's
|
|
||||||
validator script.
|
|
||||||
|
|
||||||
|
|
||||||
= Documentation
|
= Documentation
|
||||||
|
|
||||||
This documentation is available online at http://api.mongodb.org/ruby. You can
|
This documentation is available online at http://api.mongodb.org/ruby. You can
|
||||||
@ -342,7 +323,7 @@ See CREDITS.
|
|||||||
|
|
||||||
= License
|
= License
|
||||||
|
|
||||||
Copyright 2008-2009 10gen Inc.
|
Copyright 2008-2010 10gen Inc.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -355,4 +336,3 @@ See CREDITS.
|
|||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
# encoding:utf-8
|
# encoding:utf-8
|
||||||
|
|
||||||
require 'test/test_helper'
|
require 'test/test_helper'
|
||||||
|
|
||||||
class BinaryTest < Test::Unit::TestCase
|
|
||||||
|
|
||||||
context "Inspecting" do
|
context "Inspecting" do
|
||||||
setup do
|
setup do
|
||||||
@data = ("THIS IS BINARY " * 50).unpack("c*")
|
@data = ("THIS IS BINARY " * 50).unpack("c*")
|
||||||
@ -14,4 +11,3 @@ class BinaryTest < Test::Unit::TestCase
|
|||||||
assert_equal "<Mongo::Binary:#{binary.object_id}>", binary.inspect
|
assert_equal "<Mongo::Binary:#{binary.object_id}>", binary.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
require 'test/test_helper'
|
require 'test/test_helper'
|
||||||
|
include Mongo
|
||||||
|
|
||||||
class GridTest < Test::Unit::TestCase
|
context "GridFileSystem:" do
|
||||||
|
setup do
|
||||||
def setup
|
|
||||||
@db ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
@db ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
||||||
@files = @db.collection('fs.files')
|
@files = @db.collection('fs.files')
|
||||||
@chunks = @db.collection('fs.chunks')
|
@chunks = @db.collection('fs.chunks')
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
teardown do
|
||||||
@files.remove
|
@files.remove
|
||||||
@chunks.remove
|
@chunks.remove
|
||||||
end
|
end
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
require 'test/test_helper'
|
require 'test/test_helper'
|
||||||
|
include Mongo
|
||||||
|
|
||||||
class GridIOTest < Test::Unit::TestCase
|
context "" do
|
||||||
include GridFS
|
setup do
|
||||||
|
|
||||||
def setup
|
|
||||||
@db ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
@db ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
||||||
@files = @db.collection('fs.files')
|
@files = @db.collection('fs.files')
|
||||||
@chunks = @db.collection('fs.chunks')
|
@chunks = @db.collection('fs.chunks')
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
teardown do
|
||||||
@files.remove
|
@files.remove
|
||||||
@chunks.remove
|
@chunks.remove
|
||||||
end
|
end
|
||||||
@ -30,6 +29,5 @@ class GridIOTest < Test::Unit::TestCase
|
|||||||
file = GridIO.new(@files, @chunks, @filename, @mode, false, :chunk_size => 1000)
|
file = GridIO.new(@files, @chunks, @filename, @mode, false, :chunk_size => 1000)
|
||||||
assert_equal 1000, file.chunk_size
|
assert_equal 1000, file.chunk_size
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
require 'test/test_helper'
|
require 'test/test_helper'
|
||||||
|
include Mongo
|
||||||
|
|
||||||
class GridTest < Test::Unit::TestCase
|
context "Tests:" do
|
||||||
|
setup do
|
||||||
def setup
|
|
||||||
@db ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
@db ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
||||||
@files = @db.collection('test-fs.files')
|
@files = @db.collection('test-fs.files')
|
||||||
@chunks = @db.collection('test-fs.chunks')
|
@chunks = @db.collection('test-fs.chunks')
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
teardown do
|
||||||
@files.remove
|
@files.remove
|
||||||
@chunks.remove
|
@chunks.remove
|
||||||
end
|
end
|
||||||
@ -44,6 +44,8 @@ class GridTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "Streaming: " do
|
||||||
|
setup do
|
||||||
def read_and_write_stream(filename, read_length, opts={})
|
def read_and_write_stream(filename, read_length, opts={})
|
||||||
io = File.open(File.join(File.dirname(__FILE__), 'data', filename), 'r')
|
io = File.open(File.join(File.dirname(__FILE__), 'data', filename), 'r')
|
||||||
id = @grid.put(io, filename + read_length.to_s, opts)
|
id = @grid.put(io, filename + read_length.to_s, opts)
|
||||||
@ -60,8 +62,6 @@ class GridTest < Test::Unit::TestCase
|
|||||||
assert_equal data.length, read_data.length
|
assert_equal data.length, read_data.length
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Streaming: " do
|
|
||||||
setup do
|
|
||||||
@grid = Grid.new(@db, 'test-fs')
|
@grid = Grid.new(@db, 'test-fs')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,14 +5,12 @@ require 'test/unit'
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'shoulda'
|
|
||||||
require 'mocha'
|
require 'mocha'
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
puts <<MSG
|
puts <<MSG
|
||||||
|
|
||||||
This test suite now requires shoulda and mocha.
|
This test suite requires mocha.
|
||||||
You can install these gems as follows:
|
You can install it as follows:
|
||||||
gem install shoulda
|
|
||||||
gem install mocha
|
gem install mocha
|
||||||
|
|
||||||
MSG
|
MSG
|
||||||
@ -40,3 +38,31 @@ class Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# shoulda-mini
|
||||||
|
# based on test/spec/mini 5
|
||||||
|
# http://gist.github.com/307649
|
||||||
|
# chris@ozmm.org
|
||||||
|
#
|
||||||
|
def context(*args, &block)
|
||||||
|
return super unless (name = args.first) && block
|
||||||
|
require 'test/unit'
|
||||||
|
klass = Class.new(Test::Unit::TestCase) do
|
||||||
|
def self.should(name, &block)
|
||||||
|
define_method("test_#{name.to_s.gsub(/\W/,'_')}", &block) if block
|
||||||
|
end
|
||||||
|
def self.xshould(*args) end
|
||||||
|
def self.context(*args, &block) instance_eval(&block) end
|
||||||
|
def self.setup(&block)
|
||||||
|
define_method(:setup) { self.class.setups.each { |s| instance_eval(&s) } }
|
||||||
|
setups << block
|
||||||
|
end
|
||||||
|
def self.setups; @setups ||= [] end
|
||||||
|
def self.teardown(&block) define_method(:teardown, &block) end
|
||||||
|
end
|
||||||
|
(class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
|
||||||
|
klass.class_eval do
|
||||||
|
include Mongo
|
||||||
|
end
|
||||||
|
klass.class_eval &block
|
||||||
|
end
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
require 'test/test_helper'
|
require 'test/test_helper'
|
||||||
|
|
||||||
class ConnectionTest < Test::Unit::TestCase
|
|
||||||
|
|
||||||
context "Basic operations: " do
|
context "Basic operations: " do
|
||||||
setup do
|
setup do
|
||||||
@logger = mock()
|
@logger = mock()
|
||||||
@ -58,6 +56,3 @@ class ConnectionTest < Test::Unit::TestCase
|
|||||||
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
|
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
require 'test/test_helper'
|
require 'test/test_helper'
|
||||||
|
include Mongo
|
||||||
|
|
||||||
class ConnectionTest < Test::Unit::TestCase
|
context "Initialization: " do
|
||||||
|
setup do
|
||||||
def new_mock_socket
|
def new_mock_socket
|
||||||
socket = Object.new
|
socket = Object.new
|
||||||
socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
||||||
@ -11,8 +12,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|||||||
def new_mock_db
|
def new_mock_db
|
||||||
db = Object.new
|
db = Object.new
|
||||||
end
|
end
|
||||||
|
end
|
||||||
context "Initialization: " do
|
|
||||||
|
|
||||||
context "given a single node" do
|
context "given a single node" do
|
||||||
setup do
|
setup do
|
||||||
@ -113,21 +113,3 @@ class ConnectionTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with a nonstandard port" do
|
|
||||||
setup do
|
|
||||||
TCPSocket.stubs(:new).returns(new_mock_socket)
|
|
||||||
@conn = Connection.new('255.255.255.255', 2500, :connect => false)
|
|
||||||
admin_db = new_mock_db
|
|
||||||
admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
|
|
||||||
@conn.expects(:[]).with('admin').returns(admin_db)
|
|
||||||
@conn.connect_to_master
|
|
||||||
end
|
|
||||||
|
|
||||||
should "set localhost and port correctly" do
|
|
||||||
assert_equal '255.255.255.255', @conn.host
|
|
||||||
assert_equal 2500, @conn.port
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
require 'test/test_helper'
|
require 'test/test_helper'
|
||||||
|
|
||||||
class TestCursor < Test::Unit::TestCase
|
|
||||||
|
|
||||||
context "Cursor options" do
|
context "Cursor options" do
|
||||||
setup do
|
setup do
|
||||||
@connection = stub(:class => Connection)
|
@connection = stub(:class => Connection)
|
||||||
@ -91,4 +89,3 @@ class TestCursor < Test::Unit::TestCase
|
|||||||
assert_nil @cursor.fields
|
assert_nil @cursor.fields
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require 'test/test_helper'
|
require 'test/test_helper'
|
||||||
|
|
||||||
class DBTest < Test::Unit::TestCase
|
context "DBTest: " do
|
||||||
|
setup do
|
||||||
def insert_message(db, documents)
|
def insert_message(db, documents)
|
||||||
documents = [documents] unless documents.is_a?(Array)
|
documents = [documents] unless documents.is_a?(Array)
|
||||||
message = ByteBuffer.new
|
message = ByteBuffer.new
|
||||||
@ -10,6 +10,7 @@ class DBTest < Test::Unit::TestCase
|
|||||||
documents.each { |doc| message.put_array(BSON.new.serialize(doc, true).to_a) }
|
documents.each { |doc| message.put_array(BSON.new.serialize(doc, true).to_a) }
|
||||||
message = db.add_message_headers(Mongo::Constants::OP_INSERT, message)
|
message = db.add_message_headers(Mongo::Constants::OP_INSERT, message)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "DB commands" do
|
context "DB commands" do
|
||||||
setup do
|
setup do
|
||||||
|
Loading…
Reference in New Issue
Block a user