Sha256: 7484e8f8a5baad2b007086a7f0075c556d9f191f714f6dae99b70734bd07597a

Contents?: true

Size: 962 Bytes

Versions: 12

Compression:

Stored size: 962 Bytes

Contents

shared_context "a Celluloid Mailbox" do
  it "receives messages" do
    message = :ohai

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

  it "prioritizes system events over other messages" do
    subject << :dummy1
    subject << :dummy2

    subject << Celluloid::SystemEvent.new
    subject.receive.should be_a(Celluloid::SystemEvent)
  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

12 entries across 12 versions & 1 rubygems

Version Path
celluloid-0.13.0 spec/support/mailbox_examples.rb
celluloid-0.13.0.pre2 spec/support/mailbox_examples.rb
celluloid-0.13.0.pre spec/support/mailbox_examples.rb
celluloid-0.12.4 spec/support/mailbox_examples.rb
celluloid-0.12.4.pre2 spec/support/mailbox_examples.rb
celluloid-0.12.4.pre spec/support/mailbox_examples.rb
celluloid-0.12.3 spec/support/mailbox_examples.rb
celluloid-0.12.2 spec/support/mailbox_examples.rb
celluloid-0.12.1 spec/support/mailbox_examples.rb
celluloid-0.12.1.pre2 spec/support/mailbox_examples.rb
celluloid-0.12.1.pre spec/support/mailbox_examples.rb
celluloid-0.12.0 spec/support/mailbox_examples.rb