diff --git a/bson.gemspec b/bson.gemspec index a79f0a9..daac0e9 100644 --- a/bson.gemspec +++ b/bson.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.files = ['LICENSE.txt'] s.files += ['lib/bson.rb'] + Dir['lib/bson/**/*.rb'] s.files += ['bin/b2json', 'bin/j2bson'] - s.test_files = Dir['test/bson/*.rb'] + s.test_files = Dir['test/bson/*.rb', 'test/support/hash_with_indifferent_access.rb'] s.executables = ['b2json', 'j2bson'] diff --git a/test/bson/binary_test.rb b/test/bson/binary_test.rb index 842229b..30ffa78 100644 --- a/test/bson/binary_test.rb +++ b/test/bson/binary_test.rb @@ -1,5 +1,5 @@ # encoding:utf-8 -require './test/test_helper' +require './test/bson/test_helper' class BinaryTest < Test::Unit::TestCase context "Inspecting" do diff --git a/test/bson/bson_test.rb b/test/bson/bson_test.rb index 37926e6..b9e0e26 100644 --- a/test/bson/bson_test.rb +++ b/test/bson/bson_test.rb @@ -1,5 +1,6 @@ # encoding:utf-8 -require './test/test_helper' +require './test/bson/test_helper' +require 'set' if RUBY_VERSION < '1.9' require 'complex' diff --git a/test/bson/byte_buffer_test.rb b/test/bson/byte_buffer_test.rb index 972f65a..a599c7b 100644 --- a/test/bson/byte_buffer_test.rb +++ b/test/bson/byte_buffer_test.rb @@ -1,5 +1,5 @@ # encoding: binary -require './test/test_helper' +require './test/bson/test_helper' class ByteBufferTest < Test::Unit::TestCase include BSON diff --git a/test/bson/hash_with_indifferent_access_test.rb b/test/bson/hash_with_indifferent_access_test.rb index 130d68f..0574ebb 100644 --- a/test/bson/hash_with_indifferent_access_test.rb +++ b/test/bson/hash_with_indifferent_access_test.rb @@ -1,5 +1,5 @@ # encoding:utf-8 -require './test/test_helper' +require './test/bson/test_helper' require './test/support/hash_with_indifferent_access' class HashWithIndifferentAccessTest < Test::Unit::TestCase diff --git a/test/bson/json_test.rb b/test/bson/json_test.rb index ce8e2c4..05d2765 100644 --- a/test/bson/json_test.rb +++ b/test/bson/json_test.rb @@ -1,4 +1,4 @@ -require './test/test_helper' +require './test/bson/test_helper' require 'rubygems' require 'json' diff --git a/test/bson/object_id_test.rb b/test/bson/object_id_test.rb index 69f361a..0639de6 100644 --- a/test/bson/object_id_test.rb +++ b/test/bson/object_id_test.rb @@ -1,10 +1,9 @@ -require './test/test_helper' +require './test/bson/test_helper' require 'rubygems' require 'json' class ObjectIdTest < Test::Unit::TestCase - include Mongo include BSON def setup @@ -65,18 +64,6 @@ class ObjectIdTest < Test::Unit::TestCase assert_equal "BSON::ObjectId('#{@o.to_s}')", @o.inspect end - def test_save_and_restore - db = standard_connection.db(MONGO_TEST_DB) - coll = db.collection('test') - - coll.remove - coll << {'a' => 1, '_id' => @o} - - row = coll.find().collect.first - assert_equal 1, row['a'] - assert_equal @o, row['_id'] - end - def test_from_string hex_str = @o.to_s o2 = ObjectId.from_string(hex_str) diff --git a/test/bson/ordered_hash_test.rb b/test/bson/ordered_hash_test.rb index 625b6dd..20e3138 100644 --- a/test/bson/ordered_hash_test.rb +++ b/test/bson/ordered_hash_test.rb @@ -1,4 +1,4 @@ -require './test/test_helper' +require './test/bson/test_helper' class OrderedHashTest < Test::Unit::TestCase diff --git a/test/bson/test_helper.rb b/test/bson/test_helper.rb new file mode 100644 index 0000000..668f77e --- /dev/null +++ b/test/bson/test_helper.rb @@ -0,0 +1,46 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'bson') +require 'rubygems' if RUBY_VERSION < '1.9.0' && ENV['C_EXT'] +require 'test/unit' + +def silently + warn_level = $VERBOSE + $VERBOSE = nil + result = yield + $VERBOSE = warn_level + result +end + +begin + require 'rubygems' if RUBY_VERSION < "1.9.0" && !ENV['C_EXT'] + silently { require 'shoulda' } + silently { require 'mocha' } +rescue LoadError + puts < e + assert_equal klass, e.class + assert e.message.include?(message), "#{e.message} does not include #{message}." + else + flunk "Expected assertion #{klass} but none was raised." + end + end + +end diff --git a/test/bson/timestamp_test.rb b/test/bson/timestamp_test.rb index 0bdd32a..f12b24f 100644 --- a/test/bson/timestamp_test.rb +++ b/test/bson/timestamp_test.rb @@ -1,7 +1,6 @@ -require './test/test_helper' +require './test/bson/test_helper' class TimestampTest < Test::Unit::TestCase - include Mongo def test_timestamp_equality t1 = Timestamp.new(5000, 200)