Sha256: 88e1b650c83e0e3034b03c9275974e85dd5dfac42f1b73c4edea2ebdd9ba03f0

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'
require_relative '../observable_shared'

module Concurrent

  describe Channel::Probe do

    let(:channel) { Object.new }
    let(:probe) { Channel::Probe.new }

    describe 'behavior' do

      # observable
      
      subject{ Channel::Probe.new }
      
      def trigger_observable(observable)
        observable.set('value')
      end

      it_should_behave_like :observable
    end

    describe '#set_unless_assigned' do
      context 'empty probe' do
        it 'assigns the value' do
          probe.set_unless_assigned(32, channel)
          probe.value.should eq 32
        end

        it 'assign the channel' do
          probe.set_unless_assigned(32, channel)
          probe.channel.should be channel
        end

        it 'returns true' do
          probe.set_unless_assigned('hi', channel).should eq true
        end
      end

      context 'fulfilled probe' do
        before(:each) { probe.set([27, nil]) }

        it 'does not assign the value' do
          probe.set_unless_assigned(88, channel)
          probe.value.should eq 27
        end

        it 'returns false' do
          probe.set_unless_assigned('hello', channel).should eq false
        end
      end

      context 'rejected probe' do
        before(:each) { probe.fail }

        it 'does not assign the value' do
          probe.set_unless_assigned(88, channel)
          probe.should be_rejected
        end

        it 'has a nil value' do
          probe.value.should be_nil
        end

        it 'has a nil channel' do
          probe.channel.should be_nil
        end

        it 'returns false' do
          probe.set_unless_assigned('hello', channel).should eq false
        end
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
concurrent-ruby-0.6.1 spec/concurrent/channel/probe_spec.rb
concurrent-ruby-0.6.0 spec/concurrent/channel/probe_spec.rb
concurrent-ruby-0.6.0.pre.2 spec/concurrent/channel/probe_spec.rb