Sha256: 6cfd8a17bf080b51c8de51bf2cd8944576734035da419b362c4942d569acf884

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

shared_context "a Celluloid Mailbox" do
  class TestEvent < Celluloid::SystemEvent; end

  it "receives messages" do
    message = :ohai

    subject << message
    subject.receive.should == message
  end

  it "raises system events when received" do
    subject.system_event TestEvent.new("example")

    expect do
      subject.receive
    end.to raise_exception(TestEvent)
  end

  it "prioritizes system events over other messages" do
    subject << :dummy1
    subject << :dummy2
    subject.system_event TestEvent.new("example")

    expect do
      subject.receive
    end.to raise_exception(TestEvent)
  end

  it "selectively receives messages with a block" do
    class Foo; end
    class Bar; end
    class Baz; end

    foo, bar, baz = Foo.new, Bar.new, Baz.new

    subject << baz
    subject << foo
    subject << bar

    subject.receive { |msg| msg.is_a? Foo }.should == foo
    subject.receive { |msg| msg.is_a? Bar }.should == bar
    subject.receive.should == baz
  end

  it "waits for a given timeout interval" do
    interval = 0.1
    started_at = Time.now

    subject.receive(interval) { false }
    (Time.now - started_at).should be_within(Celluloid::Timer::QUANTUM).of interval
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
celluloid-0.11.0 spec/support/mailbox_examples.rb
kulesa-celluloid-0.10.2 spec/support/mailbox_examples.rb
celluloid-0.10.0 spec/support/mailbox_examples.rb
celluloid-0.9.1 spec/support/mailbox_examples.rb
celluloid-0.9.0 spec/support/mailbox_examples.rb
celluloid-0.8.0 spec/support/mailbox_examples.rb
celluloid-0.7.2 spec/support/mailbox_examples.rb
celluloid-0.7.1 spec/support/mailbox_examples.rb
celluloid-0.7.0 spec/support/mailbox_examples.rb