spec/punchblock/translator/asterisk/component/asterisk/agi_command_spec.rb in punchblock-2.5.2 vs spec/punchblock/translator/asterisk/component/asterisk/agi_command_spec.rb in punchblock-2.5.3

- old
+ new

@@ -30,11 +30,11 @@ context 'initial execution' do before { original_command.request! } it 'should send the appropriate action' do - ami_client.should_receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'EXEC ANSWER', 'CommandID' => component_id).and_return(response) + expect(ami_client).to receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'EXEC ANSWER', 'CommandID' => component_id).and_return(response) subject.execute end context 'with some parameters' do let(:params) { [1000, 'foo'] } @@ -42,11 +42,11 @@ let :original_command do Punchblock::Component::Asterisk::AGI::Command.new :name => 'WAIT FOR DIGIT', :params => params end it 'should send the appropriate action' do - ami_client.should_receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'WAIT FOR DIGIT "1000" "foo"', 'CommandID' => component_id).and_return(response) + expect(ami_client).to receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'WAIT FOR DIGIT "1000" "foo"', 'CommandID' => component_id).and_return(response) subject.execute end end end @@ -63,43 +63,43 @@ RubyAMI::Response.new 'ActionID' => "552a9d9f-46d7-45d8-a257-06fe95f48d99", 'Message' => 'Added AGI original_command to queue' end it 'should send the component node a ref with the action ID' do - ami_client.should_receive(:send_action).once.and_return response + expect(ami_client).to receive(:send_action).once.and_return response subject.execute - original_command.response(1).should == expected_response + expect(original_command.response(1)).to eq(expected_response) end context 'with an error' do let(:message) { 'Action failed' } let :response do RubyAMI::Error.new.tap { |e| e.message = message } end - before { ami_client.should_receive(:send_action).once.and_raise response } + before { expect(ami_client).to receive(:send_action).once.and_raise response } it 'should send the component node false' do subject.execute - original_command.response(1).should be_false + expect(original_command.response(1)).to be_false end context "which is 'No such channel'" do let(:message) { 'No such channel' } it "should return an :item_not_found error for the command" do subject.execute - original_command.response(0.5).should be == ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{mock_call.id}", mock_call.id) + expect(original_command.response(0.5)).to eq(ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{mock_call.id}", mock_call.id)) end end context "which is 'Channel SIP/nosuchchannel does not exist.'" do let(:message) { 'Channel SIP/nosuchchannel does not exist.' } it "should return an :item_not_found error for the command" do subject.execute - original_command.response(0.5).should be == ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{mock_call.id}", mock_call.id) + expect(original_command.response(0.5)).to eq(ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{mock_call.id}", mock_call.id)) end end end end @@ -130,14 +130,14 @@ it 'should send a complete event' do subject.handle_ami_event ami_event complete_event = original_command.complete_event 0.5 - original_command.should be_complete + expect(original_command).to be_complete - complete_event.component_id.should be == component_id.to_s - complete_event.reason.should be == expected_complete_reason + expect(complete_event.component_id).to eq(component_id.to_s) + expect(complete_event.reason).to eq(expected_complete_reason) end context "when the command was ASYNCAGI BREAK" do let :original_command do Punchblock::Component::Asterisk::AGI::Command.new :name => 'ASYNCAGI BREAK' @@ -145,16 +145,16 @@ let(:chan_var) { nil } before do response = RubyAMI::Response.new 'Value' => chan_var - ami_client.should_receive(:send_action).once.with('GetVar', 'Channel' => channel, 'Variable' => 'PUNCHBLOCK_END_ON_ASYNCAGI_BREAK').and_return response + expect(ami_client).to receive(:send_action).once.with('GetVar', 'Channel' => channel, 'Variable' => 'PUNCHBLOCK_END_ON_ASYNCAGI_BREAK').and_return response end it 'should not send an end (hangup) event to the translator' do - translator.should_receive(:handle_pb_event).once.with kind_of(Punchblock::Event::Complete) - translator.should_receive(:handle_pb_event).never.with kind_of(Punchblock::Event::End) + expect(translator).to receive(:handle_pb_event).once.with kind_of(Punchblock::Event::Complete) + expect(translator).to receive(:handle_pb_event).never.with kind_of(Punchblock::Event::End) subject.handle_ami_event ami_event end context "when the PUNCHBLOCK_END_ON_ASYNCAGI_BREAK channel var is set" do let(:chan_var) { 'true' } @@ -162,12 +162,12 @@ it 'should send an end (hungup) event to the translator' do expected_end_event = Punchblock::Event::End.new reason: :hungup, platform_code: 16, target_call_id: mock_call.id - translator.should_receive(:handle_pb_event).once.with kind_of(Punchblock::Event::Complete) - translator.should_receive(:handle_pb_event).once.with expected_end_event + expect(translator).to receive(:handle_pb_event).once.with kind_of(Punchblock::Event::Complete) + expect(translator).to receive(:handle_pb_event).once.with expected_end_event subject.handle_ami_event ami_event end context "when the AMI event has a timestamp" do let :ami_event do @@ -183,11 +183,11 @@ it "should use the AMI timestamp for the Rayo event" do expected_end_event = Punchblock::Event::End.new reason: :hungup, platform_code: 16, target_call_id: mock_call.id, timestamp: DateTime.new(2014, 2, 25, 22, 46, 20) - translator.should_receive(:handle_pb_event).once.with kind_of(Punchblock::Event::Complete) - translator.should_receive(:handle_pb_event).once.with expected_end_event + expect(translator).to receive(:handle_pb_event).once.with kind_of(Punchblock::Event::Complete) + expect(translator).to receive(:handle_pb_event).once.with expected_end_event subject.handle_ami_event ami_event end end end