Sha256: 3ac1e327adee5933bc0ccfaa06fc6fb181c8cb820d810a3945e0a0f4dac895aa

Contents?: true

Size: 1.88 KB

Versions: 21

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'

def skippable?(file)
  !write_command_enabled? && (file.include?('bulkWrite') || file.include?('insert'))
end

def ignore?(test)
  if version = test.ignore_if_server_version_greater_than
    return true if version == "3.0" && find_command_enabled?
  end
  if version = test.ignore_if_server_version_less_than
    return true if version == "3.1" && !find_command_enabled?
  end
  false
end

describe 'Command Monitoring Events' do

  COMMAND_MONITORING_TESTS.each do |file|

    if !skippable?(file)

      spec = Mongo::CommandMonitoring::Spec.new(file)

      spec.tests.each do |test|

        context(test.description) do

          let(:subscriber) do
            Mongo::CommandMonitoring::TestSubscriber.new
          end

          let(:monitoring) do
            authorized_client.instance_variable_get(:@monitoring)
          end

          before do
            authorized_collection.find.delete_many
            authorized_client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
          end

          after do
            monitoring.subscribers[Mongo::Monitoring::COMMAND].delete(subscriber)
            authorized_collection.find.delete_many
          end

          test.expectations.each do |expectation|

            it "generates a #{expectation.event_name} for #{expectation.command_name}", unless: ignore?(test) do
              begin
                test.run(authorized_collection)
                event = subscriber.send(expectation.event_type)[expectation.command_name]
                expect(event).to send(expectation.matcher, expectation)
              rescue Mongo::Error::OperationFailure, Mongo::Error::BulkWriteError => e
                event = subscriber.send(expectation.event_type)[expectation.command_name]
                expect(event).to send(expectation.matcher, expectation)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 19 versions & 3 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mongo-2.4.1/spec/mongo/command_monitoring_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongo-2.4.1/spec/mongo/command_monitoring_spec.rb
tdiary-5.0.4 vendor/bundle/gems/mongo-2.4.1/spec/mongo/command_monitoring_spec.rb
mongo-2.4.1 spec/mongo/command_monitoring_spec.rb
mongo-2.4.0 spec/mongo/command_monitoring_spec.rb
mongo-2.3.1 spec/mongo/command_monitoring_spec.rb
mongo-2.4.0.rc1 spec/mongo/command_monitoring_spec.rb
mongo-2.4.0.rc0 spec/mongo/command_monitoring_spec.rb
mongo-2.3.0 spec/mongo/command_monitoring_spec.rb
mongo-2.2.7 spec/mongo/command_monitoring_spec.rb
mongo-2.2.6 spec/mongo/command_monitoring_spec.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongo-2.2.5/spec/mongo/command_monitoring_spec.rb
mongo-2.2.5 spec/mongo/command_monitoring_spec.rb
mongo-2.2.4 spec/mongo/command_monitoring_spec.rb
mongo-2.2.3 spec/mongo/command_monitoring_spec.rb
mongo-2.2.2 spec/mongo/command_monitoring_spec.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mongo-2.2.1/spec/mongo/command_monitoring_spec.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/mongo-2.2.1/spec/mongo/command_monitoring_spec.rb
mongo-2.2.1 spec/mongo/command_monitoring_spec.rb
mongo-2.2.0 spec/mongo/command_monitoring_spec.rb