Sha256: 750ae1078afdbbdc19d44730f28e3e4308f312396e7edde11c838dc405ef3dc6

Contents?: true

Size: 1.27 KB

Versions: 14

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

describe 'BulkWriteError message' do
  let(:client) { authorized_client }
  let(:collection_name) { 'bulk_write_error_message_spec' }
  let(:collection) { client[collection_name] }

  before do
    collection.delete_many
  end

  context 'a bulk write with one error' do
    it 'reports code name, code and message' do
      begin
        collection.insert_many([
          {_id: 1},
          {_id: 1},
          {_id: 1},
        ], ordered: true)
        fail('Should have raised')
      rescue Mongo::Error::BulkWriteError => e
        e.message.should =~ %r,\A\[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):,
      end
    end
  end

  context 'a bulk write with multiple errors' do
    it 'reports code name, code and message' do
      begin
        collection.insert_many([
          {_id: 1},
          {_id: 1},
          {_id: 1},
        ], ordered: false)
        fail('Should have raised')
      rescue Mongo::Error::BulkWriteError => e
        e.message.should =~ %r,\AMultiple errors: \[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):.*\[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):,
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/integration/bulk_write_error_message_spec.rb
mongo-2.17.4 spec/integration/bulk_write_error_message_spec.rb
mongo-2.17.3 spec/integration/bulk_write_error_message_spec.rb
mongo-2.17.2 spec/integration/bulk_write_error_message_spec.rb
mongo-2.16.3 spec/integration/bulk_write_error_message_spec.rb
mongo-2.16.2 spec/integration/bulk_write_error_message_spec.rb
mongo-2.17.1 spec/integration/bulk_write_error_message_spec.rb
mongo-2.16.1 spec/integration/bulk_write_error_message_spec.rb
mongo-2.17.0 spec/integration/bulk_write_error_message_spec.rb
mongo-2.16.0 spec/integration/bulk_write_error_message_spec.rb
mongo-2.15.1 spec/integration/bulk_write_error_message_spec.rb
mongo-2.16.0.alpha1 spec/integration/bulk_write_error_message_spec.rb
mongo-2.15.0 spec/integration/bulk_write_error_message_spec.rb
mongo-2.15.0.alpha spec/integration/bulk_write_error_message_spec.rb