Sha256: 15aea43d32499ebbf81821aaa0eb77eabde76aae7efd0a37f776322c104fb33b

Contents?: true

Size: 976 Bytes

Versions: 2

Compression:

Stored size: 976 Bytes

Contents

class ClientStub
  attr_accessor :session, :options, :is_open

  def transport_class
    Wamp::Client::Transport::EventMachineBase
  end

  def initialize(options)
    self.options = options
    self.is_open = false
    self.session = SessionStub.new
    @callbacks = {}
  end

  def open
    self.is_open = true

    # Fake connect
    trigger(:connect) { |handler| handler.call }

    # Fake challenge
    trigger(:challenge) { |handler| handler.call('wampcra', {}) } if self.options[:should_challenge]

    # Fake join
    trigger(:join) { |handler| handler.call(self.session, {}) }
  end

  def close
    # Fake leave
    trigger(:leave) { |handler| handler.call('left', {}) }

    # Fake disconnect
    trigger(:disconnect) { |handler| handler.call('left') }

    self.is_open = false
  end

  def on(event, &callback)
    @callbacks[event] = callback
  end

  def trigger(event, &callback)
    handler = @callbacks[event]
    callback.call(handler) if handler
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wamp-worker-0.1.1 spec/support/client_stub.rb
wamp-worker-0.1.0 spec/support/client_stub.rb