Sha256: d0e42924289d2d983733409a0472b76e94ffa8098abec0ab02592a036e74aa1b

Contents?: true

Size: 1.96 KB

Versions: 3

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'

describe Bullet, focused: true do
  subject { Bullet }

  describe '#enable' do

    context 'enable Bullet' do
      before do
        # Bullet.enable
        # Do nothing. Bullet has already been enabled for the whole test suite.
      end

      it 'should be enabled' do
        expect(subject).to be_enable
      end

      context 'disable Bullet' do
        before do
          Bullet.enable = false
        end

        it 'should be disabled' do
          expect(subject).to_not be_enable
        end

        context 'enable Bullet again without patching again the orms' do
          before do
            expect(Bullet::Mongoid).not_to receive(:enable) if defined? Bullet::Mongoid
            expect(Bullet::ActiveRecord).not_to receive(:enable) if defined? Bullet::ActiveRecord
            Bullet.enable = true
          end

          it 'should be enabled again' do
            expect(subject).to be_enable
          end
        end
      end
    end
  end

  describe '#start?' do
    context 'when bullet is disabled' do
      before(:each) do
        Bullet.enable = false
      end

      it 'should not be started' do
        expect(Bullet).not_to be_start
      end
    end
  end

  describe '#debug' do
    before(:each) do
      $stdout = StringIO.new
    end

    after(:each) do
      $stdout = STDOUT
    end

    context 'when debug is enabled' do
      before(:each) do
        ENV['BULLET_DEBUG'] = 'true'
      end

      after(:each) do
        ENV['BULLET_DEBUG'] = 'false'
      end

      it 'should output debug information' do
        Bullet.debug('debug_message', 'this is helpful information')

        expect($stdout.string)
          .to eq("[Bullet][debug_message] this is helpful information\n")
      end
    end

    context 'when debug is disabled' do
      it 'should output debug information' do
        Bullet.debug('debug_message', 'this is helpful information')

        expect($stdout.string).to be_empty
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bullet-5.0.0 spec/bullet_spec.rb
bullet-4.14.10 spec/bullet_spec.rb
bullet-4.14.9 spec/bullet_spec.rb