Sha256: 80102294c96b566d57532832772aa634a05cf4a9f65b88f5c318f17a89294f8f

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

# Example
class MyCommand
  include Wisper

  def execute(be_successful)
    if be_successful
      broadcast('success', 'hello')
    else
      broadcast('failure', 'world')
    end
  end
end

describe Wisper do

  it 'subscribes object to all published events' do
    listener = double('listener')
    listener.should_receive(:success).with('hello')

    command = MyCommand.new

    command.add_listener(listener)

    command.execute(true)
  end

  it 'subscribes block to all published events' do
    insider = double('Insider')
    insider.should_receive(:render).with('hello')

    command = MyCommand.new

    command.add_block_listener do |message|
      insider.render(message)
    end

    command.execute(true)
  end

  it 'maps events to different methods' do
    listener_1 = double('listener')
    listener_2 = double('listener')
    listener_1.should_receive(:happy_days).with('hello')
    listener_2.should_receive(:sad_days).with('world')

    command = MyCommand.new

    command.add_listener(listener_1, :on => :success, :with => :happy_days)
    command.add_listener(listener_2, :on => :failure, :with => :sad_days)

    command.execute(true)
    command.execute(false)
  end

  it 'subscribes block can be chained' do
    insider = double('Insider')
    insider.should_receive(:render).with('success')

    command = MyCommand.new

    command.on(:success) { |message| insider.render('success') }
           .on(:failure) { |message| insider.render('failure') }

    command.execute(true)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wisper-1.0.0 spec/lib/integration_spec.rb