Sha256: bc899ae5d17cdd705b326e7d698e8d71a2df1f602703bf8107156ae03e86412c

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe MarilynRPC::Gentleman do
  before(:each) do
    module MarilynRPC
      def self.serialize(obj)
        obj
      end
    end

    class DeferObjectMock
      attr_accessor :callback

      def callback(&block)
        @callback = block
      end

      def call(*args)
        @callback.call(*args)
      end
    end

    class ConnectionMock
      attr_accessor :data
      def send_mail(obj)
        @data = obj
      end
    end
  end
  
  it "should be possible to defer a process to a gentleman" do
    deferable = DeferObjectMock.new
    
    g = MarilynRPC::Gentleman.new(deferable) do |a, b|
      a + b
    end
    g.connection = ConnectionMock.new
    deferable.call(1, 2)
    g.connection.data.result.should == 3
  end
  
  it "should be possible to create a gentleman helper" do
    callback = nil
    
    g = MarilynRPC::Gentleman.proxy do |helper|
      callback = helper
    
      lambda do |a, b|
        a + b
      end
    end
    
    g.connection = ConnectionMock.new
    callback.call(1, 2)
    g.connection.data.result.should == 3
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
marilyn-rpc-0.0.3 spec/gentleman_spec.rb
marilyn-rpc-0.0.2 spec/gentleman_spec.rb
marilyn-rpc-0.0.1 spec/gentleman_spec.rb