Sha256: a00ea5e81ec462f283f451f76221aea4b7b31ff36ef5eeaf4d513025a842baca

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 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')
          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')
        end

        it 'should ensure the returned future contains :ok' do
          counter = ExpectationGuarantor::MessageCounter.new(1)
          future = counter.post?('message')
          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.3 spec/lib/testing/expectation_guarantor_spec.rb