Sha256: 5f76f00280e0ec3e4f0edcae0dbe691e90da1d511725b917965cd228f7940d84

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'

describe 'Mongo::Cursor' do
  let(:collection) { COLL }

  describe '#send_initial_query' do
    context 'when enabled' do
      let(:stats_client) { double('StatsD client').as_null_object }

      before do
        MongoProfiler.enable!

        MongoProfiler.stats_client = stats_client
      end

      it 'populate stats' do
        expect(stats_client).to receive(:increment).with(any_args)
        expect(stats_client).to receive(:timing).with(any_args)

        collection.find_one
      end

      it 'creates a profiler entry' do
        expect {
          collection.insert(test: 'test')
          expect(collection.find_one['test']).to eq 'test'
        }.to change { MongoProfiler.collection.count }.by(1)
      end
    end

    context 'when disabled' do
      before { MongoProfiler.disable! }

      it 'skips profiler entry' do
        expect {
          collection.insert(test: 'test')
          expect(collection.find_one['test']).to eq 'test'
        }.to_not change { MongoProfiler.collection.count }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongo_profiler-0.0.1 spec/mongo_profiler/extensions/mongo/cursor_spec.rb