Sha256: 07359daa10f13262c80836622c91fc6e6fd37a2a08857f85f5d0f784f665270a

Contents?: true

Size: 1.71 KB

Versions: 5

Compression:

Stored size: 1.71 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Adhearsion
  describe PunchblockPlugin do
    it "should make the client accessible from the Initializer" do
      PunchblockPlugin::Initializer.client = :foo
      PunchblockPlugin.client.should be :foo
      PunchblockPlugin::Initializer.client = nil
    end

    describe '#execute_component' do
      let(:message)     { Punchblock::Command::Accept.new }
      let(:response)    { :foo }
      let(:mock_client) { mock 'Client' }

      let(:execute_expectation) { PunchblockPlugin.client.should_receive(:execute_command).once }

      before do
        PunchblockPlugin::Initializer.client = mock_client
        message.stub :execute! => true
        message.response = response
        execute_expectation
      end

      it "writes a command to the client" do
        execute_expectation.with(message, :async => true)
        PunchblockPlugin.execute_component message
      end

      it "blocks until a response is received" do
        slow_command = Punchblock::Command::Dial.new
        slow_command.request!
        starting_time = Time.now
        Thread.new do
          sleep 0.5
          slow_command.response = response
        end
        PunchblockPlugin.execute_component slow_command
        (Time.now - starting_time).should >= 0.4
      end

      describe "with a successful response" do
        it "returns the executed command" do
          PunchblockPlugin.execute_component(message).should be message
        end
      end

      describe "with an error response" do
        let(:response) { Exception.new }

        it "raises the error" do
          lambda { PunchblockPlugin.execute_component message }.should raise_error Exception
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
adhearsion-2.3.5 spec/adhearsion/punchblock_plugin_spec.rb
adhearsion-2.3.4 spec/adhearsion/punchblock_plugin_spec.rb
adhearsion-2.3.3 spec/adhearsion/punchblock_plugin_spec.rb
adhearsion-2.3.2 spec/adhearsion/punchblock_plugin_spec.rb
adhearsion-2.3.1 spec/adhearsion/punchblock_plugin_spec.rb