Move helper methods away from tests setup to avoid redefinition on each test run
This commit is contained in:
parent
c0b0325100
commit
6cdae6dc7e
|
@ -78,6 +78,16 @@ class Test::Unit::TestCase
|
||||||
self.class.mongo_port
|
self.class.mongo_port
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new_mock_socket(host='localhost', port=27017)
|
||||||
|
socket = Object.new
|
||||||
|
socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
||||||
|
socket.stubs(:close)
|
||||||
|
socket
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_mock_db
|
||||||
|
db = Object.new
|
||||||
|
end
|
||||||
|
|
||||||
def assert_raise_error(klass, message)
|
def assert_raise_error(klass, message)
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -3,19 +3,6 @@ include Mongo
|
||||||
|
|
||||||
class ConnectionTest < Test::Unit::TestCase
|
class ConnectionTest < Test::Unit::TestCase
|
||||||
context "Initialization: " do
|
context "Initialization: " do
|
||||||
setup do
|
|
||||||
def new_mock_socket(host='localhost', port=27017)
|
|
||||||
socket = Object.new
|
|
||||||
socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
|
||||||
socket.stubs(:close)
|
|
||||||
socket
|
|
||||||
end
|
|
||||||
|
|
||||||
def new_mock_db
|
|
||||||
db = Object.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "given a single node" do
|
context "given a single node" do
|
||||||
setup do
|
setup do
|
||||||
@conn = Connection.new('localhost', 27017, :connect => false)
|
@conn = Connection.new('localhost', 27017, :connect => false)
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
require './test/test_helper'
|
require './test/test_helper'
|
||||||
|
|
||||||
class DBTest < Test::Unit::TestCase
|
def insert_message(db, documents)
|
||||||
context "DBTest: " do
|
|
||||||
setup do
|
|
||||||
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
|
||||||
message.put_int(0)
|
message.put_int(0)
|
||||||
Mongo::BSON_CODER..serialize_cstr(message, "#{db.name}.test")
|
Mongo::BSON_CODER.serialize_cstr(message, "#{db.name}.test")
|
||||||
documents.each { |doc| message.put_array(Mongo::BSON_CODER.new.serialize(doc, true).to_a) }
|
documents.each { |doc| message.put_array(Mongo::BSON_CODER.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
|
|
||||||
|
|
||||||
|
class DBTest < Test::Unit::TestCase
|
||||||
|
context "DBTest: " do
|
||||||
context "DB commands" do
|
context "DB commands" do
|
||||||
setup do
|
setup do
|
||||||
@conn = stub()
|
@conn = stub()
|
||||||
|
|
|
@ -3,19 +3,6 @@ include Mongo
|
||||||
|
|
||||||
class ReplSetConnectionTest < Test::Unit::TestCase
|
class ReplSetConnectionTest < Test::Unit::TestCase
|
||||||
context "Initialization: " do
|
context "Initialization: " do
|
||||||
setup do
|
|
||||||
def new_mock_socket(host='localhost', port=27017)
|
|
||||||
socket = Object.new
|
|
||||||
socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
|
||||||
socket.stubs(:close)
|
|
||||||
socket
|
|
||||||
end
|
|
||||||
|
|
||||||
def new_mock_db
|
|
||||||
db = Object.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "connecting to a replica set" do
|
context "connecting to a replica set" do
|
||||||
setup do
|
setup do
|
||||||
TCPSocket.stubs(:new).returns(new_mock_socket('localhost', 27017))
|
TCPSocket.stubs(:new).returns(new_mock_socket('localhost', 27017))
|
||||||
|
|
Loading…
Reference in New Issue