Skip to content

Commit

Permalink
Avoid excessive mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Jun 21, 2015
1 parent 9d57c7e commit 2bb5723
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions spec/adhearsion/translator/asterisk/call_spec.rb
Expand Up @@ -1905,22 +1905,6 @@ def grxml_doc(mode = :dtmf)
'Message' => 'Added AGI original_command to queue'
end

it 'should send an appropriate AsyncAGI AMI action' do
expect_any_instance_of(Celluloid::Future).to receive(:value).and_return nil
expect(ami_client).to receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'EXEC ANSWER', 'CommandID' => Adhearsion.new_uuid).and_return(response)
subject.execute_agi_command 'EXEC ANSWER'
end

context 'with some parameters' do
let(:params) { [1000, 'foo'] }

it 'should send the appropriate action' do
expect_any_instance_of(Celluloid::Future).to receive(:value).and_return nil
expect(ami_client).to receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'WAIT FOR DIGIT "1000" "foo"', 'CommandID' => Adhearsion.new_uuid).and_return(response)
subject.execute_agi_command 'WAIT FOR DIGIT', *params
end
end

context 'with an error' do
let(:message) { 'Action failed' }

Expand Down Expand Up @@ -1952,7 +1936,6 @@ def grxml_doc(mode = :dtmf)
end
end


describe 'when receiving an AsyncAGI event' do
context 'of type Exec' do
let(:ami_event) do
Expand All @@ -1964,6 +1947,24 @@ def grxml_doc(mode = :dtmf)
"Result" => "200%20result=123%20(timeout)%0A"
end

it 'should send an appropriate AsyncAGI AMI action' do
expect(ami_client).to receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'EXEC ANSWER', 'CommandID' => Adhearsion.new_uuid).and_return(response)
fut = Celluloid::Future.new { subject.execute_agi_command 'EXEC ANSWER' }
sleep 0.25
subject.process_ami_event ami_event
end

context 'with some parameters' do
let(:params) { [1000, 'foo'] }

it 'should send the appropriate action' do
expect(ami_client).to receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'WAIT FOR DIGIT "1000" "foo"', 'CommandID' => Adhearsion.new_uuid).and_return(response)
fut = Celluloid::Future.new { subject.execute_agi_command 'WAIT FOR DIGIT', *params }
sleep 0.25
subject.process_ami_event ami_event
end
end

it 'should return the result' do
fut = Celluloid::Future.new { subject.execute_agi_command 'EXEC ANSWER' }
sleep 0.25
Expand All @@ -1983,6 +1984,24 @@ def grxml_doc(mode = :dtmf)
"Result" => "200%20result=123%20(timeout)%0A"
end

it 'should send an appropriate AsyncAGI AMI action' do
expect(ami_client).to receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'EXEC ANSWER', 'CommandID' => Adhearsion.new_uuid).and_return(response)
fut = Celluloid::Future.new { subject.execute_agi_command 'EXEC ANSWER' }
sleep 0.25
subject.process_ami_event ami_event
end

context 'with some parameters' do
let(:params) { [1000, 'foo'] }

it 'should send the appropriate action' do
expect(ami_client).to receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'WAIT FOR DIGIT "1000" "foo"', 'CommandID' => Adhearsion.new_uuid).and_return(response)
fut = Celluloid::Future.new { subject.execute_agi_command 'WAIT FOR DIGIT', *params }
sleep 0.25
subject.process_ami_event ami_event
end
end

it 'should return the result' do
fut = Celluloid::Future.new { subject.execute_agi_command 'EXEC ANSWER' }
sleep 0.25
Expand Down

0 comments on commit 2bb5723

Please sign in to comment.