Move helper methods away from tests setup to avoid redefinition on each test run

This commit is contained in:
Wojciech Piekutowski 2011-02-20 16:00:06 +01:00
parent c0b0325100
commit 6cdae6dc7e
4 changed files with 20 additions and 38 deletions

View File

@ -78,7 +78,17 @@ class Test::Unit::TestCase
self.class.mongo_port
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)
begin
yield

View File

@ -3,19 +3,6 @@ include Mongo
class ConnectionTest < Test::Unit::TestCase
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
setup do
@conn = Connection.new('localhost', 27017, :connect => false)

View File

@ -1,18 +1,16 @@
require './test/test_helper'
def insert_message(db, documents)
documents = [documents] unless documents.is_a?(Array)
message = ByteBuffer.new
message.put_int(0)
Mongo::BSON_CODER.serialize_cstr(message, "#{db.name}.test")
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)
end
class DBTest < Test::Unit::TestCase
context "DBTest: " do
setup do
def insert_message(db, documents)
documents = [documents] unless documents.is_a?(Array)
message = ByteBuffer.new
message.put_int(0)
Mongo::BSON_CODER..serialize_cstr(message, "#{db.name}.test")
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)
end
end
context "DB commands" do
setup do
@conn = stub()

View File

@ -3,19 +3,6 @@ include Mongo
class ReplSetConnectionTest < Test::Unit::TestCase
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
setup do
TCPSocket.stubs(:new).returns(new_mock_socket('localhost', 27017))