Sha256: 46b996ab8aa32dc539882f181e85b764fe8185d25494b63d5b74cecef9a4a2d3

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe "Blocks", actor_system: :global do
  class MyBlockActor
    include Celluloid

    def initialize(name)
      @name = name
    end
    attr_reader :name

    def ask_for_something(other)
      sender_actor = current_actor
      $data << [:outside, @name, current_actor.name]
      other.do_something_and_callback do |value|
        $data << [:yielded, @name, current_actor.name]
        $data << self.receive_result(:self)
        $data << current_actor.receive_result(:current_actor)
        $data << sender_actor.receive_result(:sender)
        "somevalue"
      end
    end

    def do_something_and_callback
      $data << [:something, @name, current_actor.name]
      $data << yield(:foo)
    end

    def receive_result(result)
      [result, @name, current_actor.name]
    end
  end

  it "works" do
    $data = []

    a1 = MyBlockActor.new("one")
    a2 = MyBlockActor.new("two")

    a1.ask_for_something a2

    expected = [
      [:outside, "one", "one"],
      [:something, "two", "two"],
      [:yielded, "one", "one"],
      [:self, "one", "one"],
      [:current_actor, "one", "one"],
      [:sender, "one", "one"],
      "somevalue",
    ]

    $data.should eq(expected)
  end
end

Version data entries

9 entries across 7 versions & 4 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/celluloid-0.16.0/spec/celluloid/block_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/celluloid-0.16.0/spec/celluloid/block_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/celluloid-0.16.0/spec/celluloid/block_spec.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/celluloid-0.16.0/spec/celluloid/block_spec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/celluloid-0.16.0/spec/celluloid/block_spec.rb
celluloid-0.16.0 spec/celluloid/block_spec.rb
celluloid-0.16.0.pre3 spec/celluloid/block_spec.rb
celluloid-0.16.0.pre2 spec/celluloid/block_spec.rb
celluloid-0.16.0.pre spec/celluloid/block_spec.rb