Sha256: 42dde90e096d1ed1e86dc224c389a9d3306a67bdef84ce4ba20c72f7a71e3be3

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'proletariat/testing/expectation_guarantor'

module Proletariat
  module Testing
    describe ExpectationGuarantor::MessageCounter do
      describe '#expected_messages_received?' do
        context 'count is equal or greater than expected' do
          it 'should return true' do
            counter = ExpectationGuarantor::MessageCounter.new(1, 3)
            expect(counter.expected_messages_received?).to be_truthy
          end
        end

        context 'count is less than expected' do
          it 'should return false' do
            counter = ExpectationGuarantor::MessageCounter.new(5, 3)
            expect(counter.expected_messages_received?).to be_falsey
          end
        end
      end

      describe '#post?' do
        class FakeBlockTaker
          attr_reader :block

          def initialize(&block)
            @block = block
          end
        end

        before do
          stub_const 'Concurrent::Future', FakeBlockTaker
        end

        it 'should increment the count' do
          counter = ExpectationGuarantor::MessageCounter.new(1)
          counter.post?('message', 'key')
          expect(counter.expected_messages_received?).to be_truthy
        end

        it 'should return a future containing :ok' do
          counter = ExpectationGuarantor::MessageCounter.new(1)
          expect(Concurrent::Future).to receive(:new)
          counter.post?('message', 'key')
        end

        it 'should ensure the returned future contains :ok' do
          counter = ExpectationGuarantor::MessageCounter.new(1)
          future = counter.post?('message', 'key')
          expect(future.block.call).to eq :ok
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
proletariat-0.0.4 spec/lib/testing/expectation_guarantor_spec.rb