Sha256: bdb1f4e74e3318f1eaccd2b71e45e3a0f5793dbd37a43a2e79069c9af603c67a

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

describe 'integration' do
  before :all do
    start_endpoint :mars
    start_endpoint :pluto
    Buster.local_endpoint = 'ipc://earth.ipc'
    Buster.routes[/mars/] = 'ipc://mars.ipc'
    Buster.routes[/pluto/] = 'ipc://pluto.ipc'
    Buster.routes[/station/] = 'ipc://station.ipc'
    Thread.new { Buster.start }
    sleep 1 #bus startup delay
  end

  after :all do
    Buster.stop
  end

  let(:mutex) { Mutex.new }
  let(:baton) { ConditionVariable.new }

  describe 'when sending a hello_mars' do
    before do
      Handler 'HelloEarth' do |props|
        mutex.synchronize do
          @response = props['name']
          baton.signal
        end
      end
    end

    it 'should respond in the mars uppercase style' do
      name = 'Major Tom'
      Buster.fire :hello_mars, :name => name
      mutex.synchronize do
        baton.wait(mutex, 1)
        @response.should == name.upcase
      end
    end
  end

  describe 'when sending a hello_pluto' do
    before do
      Handler 'HelloEarth' do |props|
        mutex.synchronize do
          @response = props['name']
          baton.signal
        end
      end
    end

    it 'should respond in the pluto reversed style' do
      name = 'Ground Control'
      Buster.fire :hello_pluto, :name => name
      mutex.synchronize do
        baton.wait(mutex, 1)
        @response.should == name.reverse
      end
    end
  end

  describe 'when sending to a powered down space station' do
    before do
      Handler 'TenFour' do |props|
        mutex.synchronize do
          @ten_foured = true
          baton.signal
        end
      end
    end

    it 'should receive response when the station powers up' do
      Buster.fire :adjust_station_temperature
      sleep 1 #Oh no! Station isn't started!
      start_endpoint :station
      mutex.synchronize do
        baton.wait(mutex, 1)
        @ten_foured.should == true
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
buster-0.1.3 spec/integration_spec.rb
buster-0.1.2 spec/integration_spec.rb
buster-0.1.1 spec/integration_spec.rb