Sha256: a016e6f3b06b1683d475a8e11f41d2e913e2a0985d1afeb013806516dacb0c4a

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

RSpec.describe Mutant::Actor::Env do
  let(:mutex)       { double('Mutex')                           }
  let(:thread)      { double('Thread')                          }
  let(:thread_root) { double('Thread Root')                     }
  let(:actor)       { Mutant::Actor::Actor.new(thread, mailbox) }

  let(:object) { described_class.new(thread_root) }

  before do
    expect(Mutex).to receive(:new).and_return(mutex)
  end

  describe '#current' do
    subject { object.current }

    let!(:mailbox)    { Mutant::Actor::Mailbox.new                }

    before do
      expect(Mutant::Actor::Mailbox).to receive(:new).and_return(mailbox).ordered
      expect(thread_root).to receive(:current).and_return(thread)
    end

    it { should eql(actor) }
  end

  describe '#spawn' do
    subject { object.spawn(&block) }

    let!(:mailbox)    { Mutant::Actor::Mailbox.new                }

    let(:yields) { [] }

    let(:block) { ->(actor) { yields << actor } }

    before do
      expect(Mutant::Actor::Mailbox).to receive(:new).and_return(mailbox).ordered
      expect(thread_root).to receive(:new).and_yield.and_return(thread).ordered
      expect(thread_root).to receive(:current).and_return(thread).ordered
    end

    it 'returns sender' do
      should eql(actor.sender)
    end

    it 'yields actor' do
      expect { subject }.to change { yields }.from([]).to([actor])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mutant-0.7.1 spec/unit/mutant/actor/env_spec.rb