spec/adhearsion/call_controller/dial_spec.rb in adhearsion-2.5.4 vs spec/adhearsion/call_controller/dial_spec.rb in adhearsion-2.6.0

- old
+ new

@@ -20,45 +20,45 @@ let(:latch) { CountDownLatch.new 1 } let(:join_options) { options[:join_options] || {} } before do - other_mock_call.wrapped_object.stub id: other_call_id, write_command: true - second_other_mock_call.wrapped_object.stub id: second_other_call_id, write_command: true + allow(other_mock_call.wrapped_object).to receive_messages id: other_call_id, write_command: true + allow(second_other_mock_call.wrapped_object).to receive_messages id: second_other_call_id, write_command: true end def mock_end(reason = :hangup_command) - Punchblock::Event::End.new.tap { |event| event.stub reason: reason } + Punchblock::Event::End.new.tap { |event| allow(event).to receive_messages reason: reason } end describe "#dial" do it "should dial the call to the correct endpoint and return a dial status object" do - OutboundCall.should_receive(:new).and_return other_mock_call - other_mock_call.should_receive(:dial).with(to, :from => 'foo').once + expect(OutboundCall).to receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).with(to, :from => 'foo').once dial_thread = Thread.new do status = subject.dial(to, :from => 'foo') - status.should be_a Dial::DialStatus + expect(status).to be_a Dial::DialStatus joined_status = status.joins[status.calls.first] - joined_status.duration.should == 0.0 - joined_status.result.should == :no_answer + expect(joined_status.duration).to eq(0.0) + expect(joined_status.result).to eq(:no_answer) end sleep 0.1 other_mock_call << mock_end - dial_thread.join.should be_true + expect(dial_thread.join).to be_truthy end it "should default the caller ID to that of the original call" do - call.stub :from => 'sip:foo@bar.com' - OutboundCall.should_receive(:new).and_return other_mock_call - other_mock_call.should_receive(:dial).with(to, :from => 'sip:foo@bar.com').once + allow(call).to receive_messages :from => 'sip:foo@bar.com' + expect(OutboundCall).to receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).with(to, :from => 'sip:foo@bar.com').once dial_thread = Thread.new do subject.dial to end sleep 0.1 other_mock_call << mock_end - dial_thread.join.should be_true + expect(dial_thread.join).to be_truthy end let(:options) { { :foo => :bar } } def dial_in_thread @@ -69,85 +69,85 @@ end end describe "without a block" do before do - other_mock_call.should_receive(:dial).once.with(to, options) - OutboundCall.should_receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).once.with(to, options) + expect(OutboundCall).to receive(:new).and_return other_mock_call end it "blocks the original controller until the new call ends" do dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end it "unblocks the original controller if the original call ends" do - other_mock_call.should_receive(:hangup).once + expect(other_mock_call).to receive(:hangup).once dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end it "joins the new call to the existing one on answer" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end context "with a join target specified" do let(:options) { { join_target: {mixer_name: 'foobar'} } } it "joins the calls to the specified target on answer" do - call.should_receive(:answer).once - call.should_receive(:join).once.with({mixer_name: 'foobar'}, {}) - other_mock_call.should_receive(:join).once.with({mixer_name: 'foobar'}, {}) + expect(call).to receive(:answer).once + expect(call).to receive(:join).once.with({mixer_name: 'foobar'}, {}) + expect(other_mock_call).to receive(:join).once.with({mixer_name: 'foobar'}, {}) dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end end context "with a pre-join callback specified" do let(:foo) { double } let(:options) { { pre_join: ->(call) { foo.bar call } } } it "executes the callback prior to joining" do - foo.should_receive(:bar).once.with(other_mock_call).ordered - call.should_receive(:answer).once.ordered - other_mock_call.should_receive(:join).once.with(call, {}).ordered + expect(foo).to receive(:bar).once.with(other_mock_call).ordered + expect(call).to receive(:answer).once.ordered + expect(other_mock_call).to receive(:join).once.with(call, {}).ordered dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end end context "with ringback specified" do let(:component) { Punchblock::Component::Output.new } @@ -157,90 +157,90 @@ component.request! component.execute! end it "plays the ringback asynchronously, terminating prior to joining" do - subject.should_receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component) - component.should_receive(:stop!).twice - call.should_receive(:answer).once.ordered - other_mock_call.should_receive(:join).once.with(call, {}).ordered + expect(subject).to receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component) + expect(component).to receive(:stop!).twice + expect(call).to receive(:answer).once.ordered + expect(other_mock_call).to receive(:join).once.with(call, {}).ordered dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end context "as a callback" do let(:foo) { double } let(:options) { { ringback: -> { foo.bar; component } } } it "calls the callback to start, and uses the return value of the callback to stop the ringback" do - foo.should_receive(:bar).once.ordered - component.should_receive(:stop!).twice - call.should_receive(:answer).once.ordered - other_mock_call.should_receive(:join).once.with(call, {}).ordered + expect(foo).to receive(:bar).once.ordered + expect(component).to receive(:stop!).twice + expect(call).to receive(:answer).once.ordered + expect(other_mock_call).to receive(:join).once.with(call, {}).ordered dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end end context "when the call is rejected" do it "terminates the ringback before returning" do - subject.should_receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component) - component.should_receive(:stop!).once + expect(subject).to receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component) + expect(component).to receive(:stop!).once t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_end(:reject) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end end end it "hangs up the new call when the root call ends" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) - other_mock_call.should_receive(:hangup).once + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) + expect(other_mock_call).to receive(:hangup).once dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end context "when the call is rejected" do it "has an overall dial status of :no_answer" do t = dial_in_thread sleep 0.5 other_mock_call << mock_end(:reject) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :no_answer + expect(status.result).to eq(:no_answer) end end context "when the call ends with an error" do it "has an overall dial status of :error" do @@ -248,26 +248,26 @@ sleep 0.5 other_mock_call << mock_end(:error) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :error + expect(status.result).to eq(:error) joined_status = status.joins[status.calls.first] - joined_status.duration.should == 0.0 - joined_status.result.should == :error + expect(joined_status.duration).to eq(0.0) + expect(joined_status.result).to eq(:error) end end context "when the call is answered and joined" do it "has an overall dial status of :answer" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}).and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end t = dial_in_thread @@ -275,27 +275,27 @@ sleep 0.5 other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :answer + expect(status.result).to eq(:answer) joined_status = status.joins[status.calls.first] - joined_status.result.should == :joined + expect(joined_status.result).to eq(:joined) end it "records the duration of the join" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}).and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end - other_mock_call.stub hangup: true + allow(other_mock_call).to receive_messages hangup: true t = dial_in_thread sleep 0.5 @@ -307,60 +307,60 @@ base_time = Time.local(2008, 9, 1, 12, 0, 37) Timecop.freeze base_time other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :answer + expect(status.result).to eq(:answer) joined_status = status.joins[status.calls.first] - joined_status.duration.should == 37.0 + expect(joined_status.duration).to eq(37.0) end context "when join options are specified" do let(:options) { { join_options: {media: :direct} } } it "joins the calls with those options" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, media: :direct) - other_mock_call.stub hangup: true + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, media: :direct) + allow(other_mock_call).to receive_messages hangup: true t = dial_in_thread sleep 0.5 other_mock_call << mock_answered other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join end end end context "when a dial is split" do let(:join_target) { call } before do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(join_target, join_options).and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(join_target, join_options) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end - other_mock_call.stub(:unjoin).and_return do + allow(other_mock_call).to receive(:unjoin) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end end it "should unjoin the calls" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end dial = Dial::Dial.new to, options, call @@ -376,14 +376,14 @@ other_mock_call << mock_answered dial.split other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "should not unblock immediately" do dial = Dial::Dial.new to, options, call dial.run subject @@ -397,18 +397,18 @@ other_mock_call << mock_answered dial.split - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "should set end time" do dial = Dial::Dial.new to, options, call dial.run subject @@ -431,17 +431,17 @@ base_time = Time.local(2008, 9, 1, 12, 0, 54) Timecop.freeze base_time other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join status = dial.status - status.result.should be == :answer + expect(status.result).to eq(:answer) joined_status = status.joins[status.calls.first] - joined_status.duration.should == 37.0 + expect(joined_status.duration).to eq(37.0) end context "with new controllers specified" do let(:split_latch) { CountDownLatch.new 2 } @@ -472,36 +472,36 @@ sleep 0.5 other_mock_call << mock_answered - should_receive(:callback).once.with(call) - should_receive(:callback).once.with(other_mock_call) + expect(self).to receive(:callback).once.with(call) + expect(self).to receive(:callback).once.with(other_mock_call) dial.split main: main_split_controller, others: others_split_controller, main_callback: ->(call) { self.callback(call) }, others_callback: ->(call) { self.callback(call) } - latch.wait(2).should be_false - split_latch.wait(2).should be_true + expect(latch.wait(2)).to be_falsey + expect(split_latch.wait(2)).to be_truthy - call['hit_split_controller'].should == main_split_controller - call['split_controller_metadata']['current_dial'].should be dial + expect(call['hit_split_controller']).to eq(main_split_controller) + expect(call['split_controller_metadata']['current_dial']).to be dial - other_mock_call['hit_split_controller'].should == others_split_controller - other_mock_call['split_controller_metadata']['current_dial'].should be dial + expect(other_mock_call['hit_split_controller']).to eq(others_split_controller) + expect(other_mock_call['split_controller_metadata']['current_dial']).to be dial other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end end context "when rejoining" do it "should rejoin the calls" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end dial = Dial::Dial.new to, options, call @@ -516,63 +516,63 @@ other_mock_call << mock_answered dial.split - other_mock_call.should_receive(:join).once.ordered.with(call, {}) + expect(other_mock_call).to receive(:join).once.ordered.with(call, {}) dial.rejoin other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end context "when join options were set originally" do let(:options) { { join_options: {media: :direct} } } it "should rejoin with the same parameters" do - other_mock_call.stub(:unjoin) + allow(other_mock_call).to receive(:unjoin) dial = Dial::Dial.new to, options, call dial.run subject other_mock_call << mock_answered dial.split - other_mock_call.should_receive(:join).once.ordered.with(call, media: :direct) + expect(other_mock_call).to receive(:join).once.ordered.with(call, media: :direct) dial.rejoin end end context "when join options are passed to rejoin" do it "should rejoin with those parameters" do - other_mock_call.stub(:unjoin) + allow(other_mock_call).to receive(:unjoin) dial = Dial::Dial.new to, options, call dial.run subject other_mock_call << mock_answered dial.split - other_mock_call.should_receive(:join).once.ordered.with(call, media: :direct) + expect(other_mock_call).to receive(:join).once.ordered.with(call, media: :direct) dial.rejoin nil, media: :direct end end context "when a join target was originally specified" do let(:join_target) { {mixer_name: 'foobar'} } let(:options) { { join_target: join_target } } it "joins the calls to the specified target on answer" do - call.should_receive(:join).once.with(join_target, {}) - other_mock_call.should_receive(:unjoin).once.ordered.with(join_target) - call.should_receive(:unjoin).once.ordered.with(join_target).and_return do + expect(call).to receive(:join).once.with(join_target, {}) + expect(other_mock_call).to receive(:unjoin).once.ordered.with(join_target) + expect(call).to receive(:unjoin).once.ordered.with(join_target) do call << Punchblock::Event::Unjoined.new(join_target) other_mock_call << Punchblock::Event::Unjoined.new(join_target) end dial = Dial::Dial.new to, options, call @@ -587,28 +587,28 @@ other_mock_call << mock_answered dial.split - call.should_receive(:join).once.ordered.with({mixer_name: 'foobar'}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: 'foobar'}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: 'foobar'}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: 'foobar'}, {}) dial.rejoin other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end end context "to a specified mixer" do let(:mixer) { SecureRandom.uuid } it "should join all calls to the mixer" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end dial = Dial::Dial.new to, options, call @@ -623,24 +623,24 @@ other_mock_call << mock_answered dial.split - call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) dial.rejoin mixer_name: mixer other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "#split should then unjoin calls from the mixer" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end dial = Dial::Dial.new to, options, call @@ -655,28 +655,28 @@ other_mock_call << mock_answered dial.split - call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) dial.rejoin mixer_name: mixer - other_mock_call.should_receive(:unjoin).once.ordered.with(mixer_name: mixer).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(mixer_name: mixer) do other_mock_call << Punchblock::Event::Unjoined.new(mixer_name: mixer) end - call.should_receive(:unjoin).once.ordered.with(mixer_name: mixer).and_return do + expect(call).to receive(:unjoin).once.ordered.with(mixer_name: mixer) do call << Punchblock::Event::Unjoined.new(mixer_name: mixer) end dial.split other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(10)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end end end context "when another dial is merged in" do @@ -686,40 +686,40 @@ let(:dial) { Dial::Dial.new to, options, call } let(:other_dial) { Dial::Dial.new second_to, options, second_root_call } before do - second_root_call.stub write_command: true, id: second_root_call_id - OutboundCall.should_receive(:new).and_return second_other_mock_call - second_other_mock_call.should_receive(:join).once.with(second_root_call, {}) - second_other_mock_call.should_receive(:dial).once.with(second_to, options) - second_root_call.should_receive(:answer).once + allow(second_root_call).to receive_messages write_command: true, id: second_root_call_id + expect(OutboundCall).to receive(:new).and_return second_other_mock_call + expect(second_other_mock_call).to receive(:join).once.with(second_root_call, {}) + expect(second_other_mock_call).to receive(:dial).once.with(second_to, options) + expect(second_root_call).to receive(:answer).once - SecureRandom.stub uuid: mixer + allow(SecureRandom).to receive_messages uuid: mixer dial.run subject other_dial.run subject other_mock_call << mock_answered second_other_mock_call << mock_answered end it "should split calls, rejoin to a mixer, and rejoin other calls to mixer" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end - second_other_mock_call.should_receive(:unjoin).once.ordered.with(second_root_call).and_return do + expect(second_other_mock_call).to receive(:unjoin).once.ordered.with(second_root_call) do second_root_call << Punchblock::Event::Unjoined.new(call_uri: second_other_mock_call.id) second_other_mock_call << Punchblock::Event::Unjoined.new(call_uri: second_root_call.id) end - call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) dial.merge other_dial waiter_thread = Thread.new do dial.await_completion @@ -730,35 +730,35 @@ other_mock_call.async << mock_end second_root_call.async << mock_end second_other_mock_call.async << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end context "when join options were specified originally" do let(:options) { { join_options: {media: :direct} } } it "should rejoin with default options" do - other_mock_call.stub(:unjoin) - second_other_mock_call.stub(:unjoin) + allow(other_mock_call).to receive(:unjoin) + allow(second_other_mock_call).to receive(:unjoin) - call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) dial.merge other_dial end end it "should add the merged calls to the returned status" do - [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true } + [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true } dial.merge other_dial waiter_thread = Thread.new do dial.await_completion latch.countdown! @@ -768,19 +768,19 @@ other_mock_call.async << mock_end second_root_call.async << mock_end second_other_mock_call.async << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer - dial.status.calls.should include(second_root_call, second_other_mock_call) + expect(dial.status.result).to eq(:answer) + expect(dial.status.calls).to include(second_root_call, second_other_mock_call) end it "should not unblock until all joined calls end" do - [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true } + [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true } dial.merge other_dial waiter_thread = Thread.new do dial.await_completion @@ -788,28 +788,28 @@ end sleep 0.5 other_mock_call << mock_end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey second_other_mock_call << mock_end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey second_root_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "should cleanup merged calls when the root call ends" do [call, other_mock_call, second_root_call, second_other_mock_call].each do |c| - c.stub join: true, unjoin: true + allow(c).to receive_messages join: true, unjoin: true end [other_mock_call, second_root_call, second_other_mock_call].each do |c| - c.should_receive(:hangup).once + expect(c).to receive(:hangup).once end dial.merge other_dial waiter_thread = Thread.new do @@ -819,18 +819,18 @@ end sleep 0.5 call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "should subsequently rejoin to a mixer" do - [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true } + [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true } dial.merge other_dial waiter_thread = Thread.new do dial.await_completion @@ -838,33 +838,33 @@ end sleep 0.5 other_mock_call << mock_end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey [call, second_root_call, second_other_mock_call].each do |call| - call.should_receive(:unjoin).once.with(mixer_name: mixer).and_return do + expect(call).to receive(:unjoin).once.with(mixer_name: mixer) do call << Punchblock::Event::Unjoined.new(mixer_name: mixer) end end dial.split [call, second_root_call, second_other_mock_call].each do |call| - call.should_receive(:join).once.with({mixer_name: mixer}, {}).and_return do + expect(call).to receive(:join).once.with({mixer_name: mixer}, {}) do call << Punchblock::Event::Joined.new(mixer_name: mixer) end end dial.rejoin end describe "if splitting fails" do it "should not add the merged calls to the returned status" do - [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true } - other_dial.should_receive(:split).and_raise StandardError + [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true } + expect(other_dial).to receive(:split).and_raise StandardError expect { dial.merge other_dial }.to raise_error(StandardError) waiter_thread = Thread.new do dial.await_completion latch.countdown! @@ -874,53 +874,53 @@ other_mock_call.async << mock_end second_root_call.async << mock_end second_other_mock_call.async << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer - dial.status.calls.should_not include(second_root_call, second_other_mock_call) + expect(dial.status.result).to eq(:answer) + expect(dial.status.calls).not_to include(second_root_call, second_other_mock_call) end it "should unblock before all joined calls end" do - [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true } + [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true } - other_dial.should_receive(:split).and_raise StandardError + expect(other_dial).to receive(:split).and_raise StandardError expect { dial.merge other_dial }.to raise_error(StandardError) waiter_thread = Thread.new do dial.await_completion latch.countdown! end sleep 0.5 other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy second_other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy second_root_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "should not cleanup merged calls when the root call ends" do [call, other_mock_call, second_root_call, second_other_mock_call].each do |c| - c.stub join: true, unjoin: true + allow(c).to receive_messages join: true, unjoin: true end - other_mock_call.should_receive(:hangup).once + expect(other_mock_call).to receive(:hangup).once [second_root_call, second_other_mock_call].each do |c| - c.should_receive(:hangup).never + expect(c).to receive(:hangup).never end - other_dial.should_receive(:split).and_raise StandardError + expect(other_dial).to receive(:split).and_raise StandardError expect { dial.merge other_dial }.to raise_error(StandardError) waiter_thread = Thread.new do dial.await_completion dial.cleanup_calls @@ -928,20 +928,20 @@ end sleep 0.5 call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end end context "if a call hangs up" do it "should still allow splitting and rejoining" do - [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true } + [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true } dial.merge other_dial waiter_thread = Thread.new do dial.await_completion @@ -949,44 +949,44 @@ end sleep 0.5 [call, second_root_call, second_other_mock_call].each do |call| - call.should_receive(:unjoin).once.with(mixer_name: mixer).and_return do + expect(call).to receive(:unjoin).once.with(mixer_name: mixer) do call << Punchblock::Event::Unjoined.new(mixer_name: mixer) end end - other_mock_call.should_receive(:unjoin).and_raise Adhearsion::Call::Hangup + expect(other_mock_call).to receive(:unjoin).and_raise Adhearsion::Call::Hangup dial.split other_mock_call << mock_end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey [call, second_root_call, second_other_mock_call].each do |call| - call.should_receive(:join).once.with({mixer_name: mixer}, {}).and_return do + expect(call).to receive(:join).once.with({mixer_name: mixer}, {}) do call << Punchblock::Event::Joined.new(mixer_name: mixer) end end - other_mock_call.should_receive(:join).and_raise Adhearsion::Call::ExpiredError + expect(other_mock_call).to receive(:join).and_raise Adhearsion::Call::ExpiredError dial.rejoin end end context "if the calls were not joined" do it "should still join to mixer" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable) - second_other_mock_call.should_receive(:unjoin).once.ordered.with(second_root_call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable) + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable) + expect(second_other_mock_call).to receive(:unjoin).once.ordered.with(second_root_call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable) - call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) dial.merge other_dial waiter_thread = Thread.new do dial.await_completion @@ -997,14 +997,14 @@ other_mock_call.async << mock_end second_root_call.async << mock_end second_other_mock_call.async << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end end end end end @@ -1017,27 +1017,27 @@ it "should raise Call::Hangup" do expect { subject.dial to, options }.to raise_error(Call::Hangup) end it "should not make any outbound calls" do - OutboundCall.should_receive(:new).never + expect(OutboundCall).to receive(:new).never expect { subject.dial to, options }.to raise_error end end describe "with multiple third parties specified" do let(:options) { {} } let(:other_options) { options } let(:second_other_options) { options } before do - OutboundCall.should_receive(:new).and_return other_mock_call, second_other_mock_call + expect(OutboundCall).to receive(:new).and_return other_mock_call, second_other_mock_call - other_mock_call.should_receive(:dial).once.with(to, other_options) + expect(other_mock_call).to receive(:dial).once.with(to, other_options) - second_other_mock_call.should_receive(:dial).once.with(second_to, second_other_options) - second_other_mock_call.should_receive(:join).never + expect(second_other_mock_call).to receive(:dial).once.with(second_to, second_other_options) + expect(second_other_mock_call).to receive(:join).never end def dial_in_thread Thread.new do status = subject.dial [to, second_to], options @@ -1045,54 +1045,54 @@ status end end it "dials all parties and joins the first one to answer, hanging up the rest" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) - second_other_mock_call.should_receive(:hangup).once.and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) + expect(second_other_mock_call).to receive(:hangup).once do second_other_mock_call << mock_end end t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.should be_a Dial::DialStatus - status.should have(2).calls - status.calls.each { |c| c.should be_a OutboundCall } + expect(status).to be_a Dial::DialStatus + expect(status.calls.size).to eq(2) + status.calls.each { |c| expect(c).to be_a OutboundCall } end it "unblocks when the joined call unjoins, allowing it to proceed further" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) - other_mock_call.should_receive(:hangup).once - second_other_mock_call.should_receive(:hangup).once.and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) + expect(other_mock_call).to receive(:hangup).once + expect(second_other_mock_call).to receive(:hangup).once do second_other_mock_call << mock_end end t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.should be_a Dial::DialStatus - status.should have(2).calls - status.calls.each { |c| c.should be_a OutboundCall } + expect(status).to be_a Dial::DialStatus + expect(status.calls.size).to eq(2) + status.calls.each { |c| expect(c).to be_a OutboundCall } end describe "with options overrides" do let(:options) do { @@ -1152,15 +1152,15 @@ second_to => dial_second_other_options }, options) latch.countdown! end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey second_other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join end end context "when all calls are rejected" do @@ -1170,49 +1170,49 @@ sleep 0.5 other_mock_call << mock_end(:reject) second_other_mock_call << mock_end(:reject) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :no_answer + expect(status.result).to eq(:no_answer) end end context "when a call is answered and joined, and the other ends with an error" do it "has an overall dial status of :answer" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) - second_other_mock_call.should_receive(:hangup).once.and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) + expect(second_other_mock_call).to receive(:hangup).once do second_other_mock_call << mock_end(:error) end t = dial_in_thread sleep 0.5 other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :answer + expect(status.result).to eq(:answer) end end end describe "with a timeout specified" do let(:timeout) { 3 } it "should abort the dial after the specified timeout" do - other_mock_call.should_receive(:dial).once - other_mock_call.should_receive(:hangup).once - OutboundCall.should_receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).once + expect(other_mock_call).to receive(:hangup).once + expect(OutboundCall).to receive(:new).and_return other_mock_call time = Time.now t = Thread.new do status = subject.dial to, :timeout => timeout @@ -1220,45 +1220,45 @@ status end latch.wait time = Time.now - time - time.round.should be == timeout + expect(time.round).to eq(timeout) t.join status = t.value - status.result.should be == :timeout + expect(status.result).to eq(:timeout) end describe "if someone answers before the timeout elapses" do it "should not abort until the far end hangs up" do - other_mock_call.should_receive(:dial).once.with(to, hash_including(:timeout => timeout)) - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) - OutboundCall.should_receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).once.with(to, hash_including(:timeout => timeout)) + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) + expect(OutboundCall).to receive(:new).and_return other_mock_call time = Time.now t = Thread.new do status = subject.dial to, :timeout => timeout latch.countdown! status end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_end - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy time = Time.now - time - time.to_i.should be > timeout + expect(time.to_i).to be > timeout t.join status = t.value - status.result.should be == :answer + expect(status.result).to eq(:answer) end end end describe "with a confirmation controller" do @@ -1284,117 +1284,119 @@ context "with confirmation controller metadata specified" do let(:options) { {:confirm => confirmation_controller, :confirm_metadata => {:foo => 'bar'}} } before do - other_mock_call.should_receive(:dial).once - OutboundCall.should_receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).once + expect(OutboundCall).to receive(:new).and_return other_mock_call end it "should set the metadata on the controller" do - other_mock_call.should_receive(:hangup).once.and_return do + expect(other_mock_call).to receive(:hangup).once do other_mock_call << mock_end end other_mock_call['confirm'] = false dial_in_thread - latch.wait(0.1).should be_false + expect(latch.wait(0.1)).to be_falsey other_mock_call << mock_answered - confirmation_latch.wait(2).should be_true - latch.wait(2).should be_true + expect(confirmation_latch.wait(2)).to be_truthy + expect(latch.wait(2)).to be_truthy - other_mock_call[:foo].should == 'bar' + expect(other_mock_call[:foo]).to eq('bar') end end context "when an outbound call is answered" do before do - other_mock_call.should_receive(:dial).once - OutboundCall.should_receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).once + expect(OutboundCall).to receive(:new).and_return other_mock_call end it "should execute the specified confirmation controller" do - other_mock_call.should_receive(:hangup).once.and_return do + expect(other_mock_call).to receive(:hangup).once do other_mock_call << mock_end end other_mock_call['confirm'] = false dial_in_thread - latch.wait(0.1).should be_false + expect(latch.wait(0.1)).to be_falsey other_mock_call << mock_answered - confirmation_latch.wait(2).should be_true - latch.wait(2).should be_true + expect(confirmation_latch.wait(2)).to be_truthy + expect(latch.wait(2)).to be_truthy end it "should join the calls if the call is still active after execution of the call controller" do other_mock_call['confirm'] = true - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}).and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end + expect(other_mock_call).to receive(:hangup).once do + other_mock_call << mock_end + end t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey base_time = Time.local(2008, 9, 1, 12, 0, 0) Timecop.freeze base_time other_mock_call << mock_answered base_time = Time.local(2008, 9, 1, 12, 0, 42) Timecop.freeze base_time other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) - other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(3)).to be_truthy t.join status = t.value - status.result.should be == :answer + expect(status.result).to eq(:answer) joined_status = status.joins[status.calls.first] - joined_status.duration.should == 42.0 - joined_status.result.should == :joined + expect(joined_status.duration).to eq(42.0) + expect(joined_status.result).to eq(:joined) end it "should not join the calls if the call is not active after execution of the call controller" do - other_mock_call.should_receive(:hangup).once.and_return do + expect(other_mock_call).to receive(:hangup).once do other_mock_call << mock_end end other_mock_call['confirm'] = false - call.should_receive(:answer).never - other_mock_call.should_receive(:join).never.with(call) + expect(call).to receive(:answer).never + expect(other_mock_call).to receive(:join).never.with(call) t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :unconfirmed + expect(status.result).to eq(:unconfirmed) joined_status = status.joins[status.calls.first] - joined_status.duration.should == 0.0 - joined_status.result.should == :unconfirmed + expect(joined_status.duration).to eq(0.0) + expect(joined_status.result).to eq(:unconfirmed) end end context "when multiple calls are made" do before do - OutboundCall.should_receive(:new).and_return other_mock_call, second_other_mock_call + expect(OutboundCall).to receive(:new).and_return other_mock_call, second_other_mock_call end def dial_in_thread Thread.new do status = subject.dial [to, second_to], options @@ -1404,78 +1406,78 @@ end context "when one answers" do it "should only execute the confirmation controller on the first call to answer, immediately hanging up all others" do other_mock_call['confirm'] = true - call.should_receive(:answer).once + expect(call).to receive(:answer).once - other_mock_call.should_receive(:dial).once.with(to, from: nil) - other_mock_call.should_receive(:join).once.with(call, {}).and_return do + expect(other_mock_call).to receive(:dial).once.with(to, from: nil) + expect(other_mock_call).to receive(:join).once.with(call, {}) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end - other_mock_call.should_receive(:hangup).once.and_return do + expect(other_mock_call).to receive(:hangup).once do other_mock_call << mock_end end - second_other_mock_call.should_receive(:dial).once.with(second_to, from: nil) - second_other_mock_call.should_receive(:join).never - second_other_mock_call.should_receive(:execute_controller).never - second_other_mock_call.should_receive(:hangup).once.and_return do + expect(second_other_mock_call).to receive(:dial).once.with(second_to, from: nil) + expect(second_other_mock_call).to receive(:join).never + expect(second_other_mock_call).to receive(:execute_controller).never + expect(second_other_mock_call).to receive(:hangup).once do second_other_mock_call << mock_end(:foo) end t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered - confirmation_latch.wait(2).should be_true + expect(confirmation_latch.wait(2)).to be_truthy other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.should be_a Dial::DialStatus - status.should have(2).calls - status.calls.each { |c| c.should be_a OutboundCall } - status.result.should be == :answer + expect(status).to be_a Dial::DialStatus + expect(status.calls.size).to eq(2) + status.calls.each { |c| expect(c).to be_a OutboundCall } + expect(status.result).to eq(:answer) end end end end end describe "#dial_and_confirm" do it "should dial the call to the correct endpoint and return a dial status object" do - OutboundCall.should_receive(:new).and_return other_mock_call - other_mock_call.should_receive(:dial).with(to, :from => 'foo').once + expect(OutboundCall).to receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).with(to, :from => 'foo').once dial_thread = Thread.new do status = subject.dial_and_confirm(to, :from => 'foo') - status.should be_a Dial::DialStatus + expect(status).to be_a Dial::DialStatus joined_status = status.joins[status.calls.first] - joined_status.duration.should == 0.0 - joined_status.result.should == :no_answer + expect(joined_status.duration).to eq(0.0) + expect(joined_status.result).to eq(:no_answer) end sleep 0.1 other_mock_call << mock_end - dial_thread.join.should be_true + expect(dial_thread.join).to be_truthy end it "should default the caller ID to that of the original call" do - call.stub :from => 'sip:foo@bar.com' - OutboundCall.should_receive(:new).and_return other_mock_call - other_mock_call.should_receive(:dial).with(to, :from => 'sip:foo@bar.com').once + allow(call).to receive_messages :from => 'sip:foo@bar.com' + expect(OutboundCall).to receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).with(to, :from => 'sip:foo@bar.com').once dial_thread = Thread.new do subject.dial_and_confirm to end sleep 0.1 other_mock_call << mock_end - dial_thread.join.should be_true + expect(dial_thread.join).to be_truthy end let(:options) { { :foo => :bar } } def dial_in_thread @@ -1486,85 +1488,85 @@ end end describe "without a block" do before do - other_mock_call.should_receive(:dial).once.with(to, options) - OutboundCall.should_receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).once.with(to, options) + expect(OutboundCall).to receive(:new).and_return other_mock_call end it "blocks the original controller until the new call ends" do dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end it "unblocks the original controller if the original call ends" do - other_mock_call.should_receive(:hangup).once + expect(other_mock_call).to receive(:hangup).once dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end it "joins the new call to the existing one on answer" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end context "with a join target specified" do let(:options) { { join_target: {mixer_name: 'foobar'} } } it "joins the calls to the specified target on answer" do - call.should_receive(:answer).once - call.should_receive(:join).once.with({mixer_name: 'foobar'}, {}) - other_mock_call.should_receive(:join).once.with({mixer_name: 'foobar'}, {}) + expect(call).to receive(:answer).once + expect(call).to receive(:join).once.with({mixer_name: 'foobar'}, {}) + expect(other_mock_call).to receive(:join).once.with({mixer_name: 'foobar'}, {}) dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end end context "with a pre-join callback specified" do let(:foo) { double } let(:options) { { pre_join: ->(call) { foo.bar call } } } it "executes the callback prior to joining" do - foo.should_receive(:bar).once.with(other_mock_call).ordered - call.should_receive(:answer).once.ordered - other_mock_call.should_receive(:join).once.with(call, {}).ordered + expect(foo).to receive(:bar).once.with(other_mock_call).ordered + expect(call).to receive(:answer).once.ordered + expect(other_mock_call).to receive(:join).once.with(call, {}).ordered dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end end context "with ringback specified" do let(:component) { Punchblock::Component::Output.new } @@ -1574,90 +1576,90 @@ component.request! component.execute! end it "plays the ringback asynchronously, terminating prior to joining" do - subject.should_receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component) - component.should_receive(:stop!).twice - call.should_receive(:answer).once.ordered - other_mock_call.should_receive(:join).once.with(call, {}).ordered + expect(subject).to receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component) + expect(component).to receive(:stop!).twice + expect(call).to receive(:answer).once.ordered + expect(other_mock_call).to receive(:join).once.with(call, {}).ordered dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end context "as a callback" do let(:foo) { double } let(:options) { { ringback: -> { foo.bar; component } } } it "calls the callback to start, and uses the return value of the callback to stop the ringback" do - foo.should_receive(:bar).once.ordered - component.should_receive(:stop!).twice - call.should_receive(:answer).once.ordered - other_mock_call.should_receive(:join).once.with(call, {}).ordered + expect(foo).to receive(:bar).once.ordered + expect(component).to receive(:stop!).twice + expect(call).to receive(:answer).once.ordered + expect(other_mock_call).to receive(:join).once.with(call, {}).ordered dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end end context "when the call is rejected" do it "terminates the ringback before returning" do - subject.should_receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component) - component.should_receive(:stop!).once + expect(subject).to receive(:play!).once.with(['file://tt-monkeys'], repeat_times: 0).and_return(component) + expect(component).to receive(:stop!).once t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_end(:reject) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end end end it "hangs up the new call when the root call ends" do - other_mock_call.should_receive(:hangup).once - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) + expect(other_mock_call).to receive(:hangup).once + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy end context "when the call is rejected" do it "has an overall dial status of :no_answer" do t = dial_in_thread sleep 0.5 other_mock_call << mock_end(:reject) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :no_answer + expect(status.result).to eq(:no_answer) end end context "when the call ends with an error" do it "has an overall dial status of :error" do @@ -1665,26 +1667,26 @@ sleep 0.5 other_mock_call << mock_end(:error) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :error + expect(status.result).to eq(:error) joined_status = status.joins[status.calls.first] - joined_status.duration.should == 0.0 - joined_status.result.should == :error + expect(joined_status.duration).to eq(0.0) + expect(joined_status.result).to eq(:error) end end context "when the call is answered and joined" do it "has an overall dial status of :answer" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}).and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end t = dial_in_thread @@ -1692,27 +1694,27 @@ sleep 0.5 other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :answer + expect(status.result).to eq(:answer) joined_status = status.joins[status.calls.first] - joined_status.result.should == :joined + expect(joined_status.result).to eq(:joined) end it "records the duration of the join" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}).and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end - other_mock_call.stub hangup: true + allow(other_mock_call).to receive_messages hangup: true t = dial_in_thread sleep 0.5 @@ -1724,63 +1726,63 @@ base_time = Time.local(2008, 9, 1, 12, 0, 37) Timecop.freeze base_time other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :answer + expect(status.result).to eq(:answer) joined_status = status.joins[status.calls.first] - joined_status.duration.should == 37.0 + expect(joined_status.duration).to eq(37.0) end context "when join options are specified" do let(:options) { { join_options: {media: :direct} } } it "joins the calls with those options" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, media: :direct).and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, media: :direct) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end - other_mock_call.stub hangup: true + allow(other_mock_call).to receive_messages hangup: true t = dial_in_thread sleep 0.5 other_mock_call << mock_answered other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join end end end context "when a dial is split" do let(:join_target) { call } before do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(join_target, join_options).and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(join_target, join_options) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end - other_mock_call.stub(:unjoin).and_return do + allow(other_mock_call).to receive(:unjoin) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end end it "should unjoin the calls" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end dial = Dial::ParallelConfirmationDial.new to, options, call @@ -1796,14 +1798,14 @@ other_mock_call << mock_answered dial.split other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "should not unblock immediately" do dial = Dial::ParallelConfirmationDial.new to, options, call dial.run subject @@ -1817,18 +1819,18 @@ other_mock_call << mock_answered dial.split - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "should set end time" do dial = Dial::ParallelConfirmationDial.new to, options, call dial.run subject @@ -1851,17 +1853,17 @@ base_time = Time.local(2008, 9, 1, 12, 0, 54) Timecop.freeze base_time other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join status = dial.status - status.result.should be == :answer + expect(status.result).to eq(:answer) joined_status = status.joins[status.calls.first] - joined_status.duration.should == 37.0 + expect(joined_status.duration).to eq(37.0) end context "with new controllers specified" do let(:split_latch) { CountDownLatch.new 2 } @@ -1892,36 +1894,36 @@ sleep 0.5 other_mock_call << mock_answered - should_receive(:callback).once.with(call) - should_receive(:callback).once.with(other_mock_call) + expect(self).to receive(:callback).once.with(call) + expect(self).to receive(:callback).once.with(other_mock_call) dial.split main: main_split_controller, others: others_split_controller, main_callback: ->(call) { self.callback(call) }, others_callback: ->(call) { self.callback(call) } - latch.wait(2).should be_false - split_latch.wait(2).should be_true + expect(latch.wait(2)).to be_falsey + expect(split_latch.wait(2)).to be_truthy - call['hit_split_controller'].should == main_split_controller - call['split_controller_metadata']['current_dial'].should be dial + expect(call['hit_split_controller']).to eq(main_split_controller) + expect(call['split_controller_metadata']['current_dial']).to be dial - other_mock_call['hit_split_controller'].should == others_split_controller - other_mock_call['split_controller_metadata']['current_dial'].should be dial + expect(other_mock_call['hit_split_controller']).to eq(others_split_controller) + expect(other_mock_call['split_controller_metadata']['current_dial']).to be dial other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end end context "when rejoining" do it "should rejoin the calls" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end dial = Dial::ParallelConfirmationDial.new to, options, call @@ -1936,57 +1938,57 @@ other_mock_call << mock_answered dial.split - other_mock_call.should_receive(:join).once.ordered.with(call, {}).and_return do + expect(other_mock_call).to receive(:join).once.ordered.with(call, {}) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end dial.rejoin other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end context "when join options were set originally" do let(:options) { { join_options: {media: :direct} } } it "should rejoin with the same parameters" do - other_mock_call.stub(:unjoin) + allow(other_mock_call).to receive(:unjoin) dial = Dial::ParallelConfirmationDial.new to, options, call dial.run subject other_mock_call << mock_answered dial.split - other_mock_call.should_receive(:join).once.ordered.with(call, media: :direct).and_return do + expect(other_mock_call).to receive(:join).once.ordered.with(call, media: :direct) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end dial.rejoin end end context "when join options are passed to rejoin" do it "should rejoin with those parameters" do - other_mock_call.stub(:unjoin) + allow(other_mock_call).to receive(:unjoin) dial = Dial::ParallelConfirmationDial.new to, options, call dial.run subject other_mock_call << mock_answered dial.split - other_mock_call.should_receive(:join).once.ordered.with(call, media: :direct).and_return do + expect(other_mock_call).to receive(:join).once.ordered.with(call, media: :direct) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end dial.rejoin nil, media: :direct end @@ -1995,13 +1997,13 @@ context "when a join target was originally specified" do let(:join_target) { {mixer_name: 'foobar'} } let(:options) { { join_target: join_target } } it "joins the calls to the specified target on answer" do - call.should_receive(:join).once.with(join_target, {}) - other_mock_call.should_receive(:unjoin).once.ordered.with(join_target) - call.should_receive(:unjoin).once.ordered.with(join_target).and_return do + expect(call).to receive(:join).once.with(join_target, {}) + expect(other_mock_call).to receive(:unjoin).once.ordered.with(join_target) + expect(call).to receive(:unjoin).once.ordered.with(join_target) do call << Punchblock::Event::Unjoined.new(join_target) other_mock_call << Punchblock::Event::Unjoined.new(join_target) end dial = Dial::ParallelConfirmationDial.new to, options, call @@ -2016,28 +2018,28 @@ other_mock_call << mock_answered dial.split - call.should_receive(:join).once.ordered.with({mixer_name: 'foobar'}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: 'foobar'}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: 'foobar'}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: 'foobar'}, {}) dial.rejoin other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end end context "to a specified mixer" do let(:mixer) { SecureRandom.uuid } it "should join all calls to the mixer" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end dial = Dial::ParallelConfirmationDial.new to, options, call @@ -2052,24 +2054,24 @@ other_mock_call << mock_answered dial.split - call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) dial.rejoin mixer_name: mixer other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "#split should then unjoin calls from the mixer" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end dial = Dial::ParallelConfirmationDial.new to, options, call @@ -2084,28 +2086,28 @@ other_mock_call << mock_answered dial.split - call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) dial.rejoin mixer_name: mixer - other_mock_call.should_receive(:unjoin).once.ordered.with(mixer_name: mixer).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(mixer_name: mixer) do other_mock_call << Punchblock::Event::Unjoined.new(mixer_name: mixer) end - call.should_receive(:unjoin).once.ordered.with(mixer_name: mixer).and_return do + expect(call).to receive(:unjoin).once.ordered.with(mixer_name: mixer) do call << Punchblock::Event::Unjoined.new(mixer_name: mixer) end dial.split other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end end end context "when another dial is merged in" do @@ -2115,40 +2117,40 @@ let(:dial) { Dial::ParallelConfirmationDial.new to, options, call } let(:other_dial) { Dial::ParallelConfirmationDial.new second_to, options, second_root_call } before do - second_root_call.stub write_command: true, id: second_root_call_id - OutboundCall.should_receive(:new).and_return second_other_mock_call - second_other_mock_call.should_receive(:join).once.with(second_root_call, {}) - second_other_mock_call.should_receive(:dial).once.with(second_to, options) - second_root_call.should_receive(:answer).once + allow(second_root_call).to receive_messages write_command: true, id: second_root_call_id + expect(OutboundCall).to receive(:new).and_return second_other_mock_call + expect(second_other_mock_call).to receive(:join).once.with(second_root_call, {}) + expect(second_other_mock_call).to receive(:dial).once.with(second_to, options) + expect(second_root_call).to receive(:answer).once - SecureRandom.stub uuid: mixer + allow(SecureRandom).to receive_messages uuid: mixer dial.run subject other_dial.run subject other_mock_call << mock_answered second_other_mock_call << mock_answered end it "should split calls, rejoin to a mixer, and rejoin other calls to mixer" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_return do + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call) do call << Punchblock::Event::Unjoined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) end - second_other_mock_call.should_receive(:unjoin).once.ordered.with(second_root_call).and_return do + expect(second_other_mock_call).to receive(:unjoin).once.ordered.with(second_root_call) do second_root_call << Punchblock::Event::Unjoined.new(call_uri: second_other_mock_call.id) second_other_mock_call << Punchblock::Event::Unjoined.new(call_uri: second_root_call.id) end - call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) dial.merge other_dial waiter_thread = Thread.new do dial.await_completion @@ -2159,35 +2161,35 @@ other_mock_call.async << mock_end second_root_call.async << mock_end second_other_mock_call.async << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end context "when join options were specified originally" do let(:options) { { join_options: {media: :direct} } } it "should rejoin with default options" do - other_mock_call.stub(:unjoin) - second_other_mock_call.stub(:unjoin) + allow(other_mock_call).to receive(:unjoin) + allow(second_other_mock_call).to receive(:unjoin) - call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) dial.merge other_dial end end it "should add the merged calls to the returned status" do - [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true } + [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true } dial.merge other_dial waiter_thread = Thread.new do dial.await_completion latch.countdown! @@ -2197,19 +2199,19 @@ other_mock_call.async << mock_end second_root_call.async << mock_end second_other_mock_call.async << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer - dial.status.calls.should include(second_root_call, second_other_mock_call) + expect(dial.status.result).to eq(:answer) + expect(dial.status.calls).to include(second_root_call, second_other_mock_call) end it "should not unblock until all joined calls end" do - [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true } + [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true } dial.merge other_dial waiter_thread = Thread.new do dial.await_completion @@ -2217,28 +2219,28 @@ end sleep 0.5 other_mock_call << mock_end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey second_other_mock_call << mock_end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey second_root_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "should cleanup merged calls when the root call ends" do [call, other_mock_call, second_root_call, second_other_mock_call].each do |c| - c.stub join: true, unjoin: true + allow(c).to receive_messages join: true, unjoin: true end [other_mock_call, second_root_call, second_other_mock_call].each do |c| - c.should_receive(:hangup).once + expect(c).to receive(:hangup).once end dial.merge other_dial waiter_thread = Thread.new do @@ -2248,18 +2250,18 @@ end sleep 0.5 call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end it "should subsequently rejoin to a mixer" do - [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true } + [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true } dial.merge other_dial waiter_thread = Thread.new do dial.await_completion @@ -2267,32 +2269,32 @@ end sleep 0.5 other_mock_call << mock_end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey [call, second_root_call, second_other_mock_call].each do |call| - call.should_receive(:unjoin).once.with(mixer_name: mixer).and_return do + expect(call).to receive(:unjoin).once.with(mixer_name: mixer) do call << Punchblock::Event::Unjoined.new(mixer_name: mixer) end end dial.split [call, other_mock_call, second_root_call, second_other_mock_call].each do |call| - call.should_receive(:join).once.with({mixer_name: mixer}, {}).and_return do + expect(call).to receive(:join).once.with({mixer_name: mixer}, {}) do call << Punchblock::Event::Joined.new(mixer_name: mixer) end end dial.rejoin end context "if a call hangs up" do it "should still allow splitting and rejoining" do - [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| c.stub join: true, unjoin: true } + [call, other_mock_call, second_root_call, second_other_mock_call].each { |c| allow(c).to receive_messages join: true, unjoin: true } dial.merge other_dial waiter_thread = Thread.new do dial.await_completion @@ -2300,44 +2302,44 @@ end sleep 0.5 [call, second_root_call, second_other_mock_call].each do |call| - call.should_receive(:unjoin).once.with(mixer_name: mixer).and_return do + expect(call).to receive(:unjoin).once.with(mixer_name: mixer) do call << Punchblock::Event::Unjoined.new(mixer_name: mixer) end end - other_mock_call.should_receive(:unjoin).and_raise Adhearsion::Call::Hangup + expect(other_mock_call).to receive(:unjoin).and_raise Adhearsion::Call::Hangup dial.split other_mock_call << mock_end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey [call, second_root_call, second_other_mock_call].each do |call| - call.should_receive(:join).once.with({mixer_name: mixer}, {}).and_return do + expect(call).to receive(:join).once.with({mixer_name: mixer}, {}) do call << Punchblock::Event::Joined.new(mixer_name: mixer) end end - other_mock_call.should_receive(:join).and_raise Adhearsion::Call::ExpiredError + expect(other_mock_call).to receive(:join).and_raise Adhearsion::Call::ExpiredError dial.rejoin end end context "if the calls were not joined" do it "should still join to mixer" do - other_mock_call.should_receive(:unjoin).once.ordered.with(call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable) - second_other_mock_call.should_receive(:unjoin).once.ordered.with(second_root_call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable) + expect(other_mock_call).to receive(:unjoin).once.ordered.with(call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable) + expect(second_other_mock_call).to receive(:unjoin).once.ordered.with(second_root_call).and_raise Punchblock::ProtocolError.new.setup(:service_unavailable) - call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_root_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) - second_other_mock_call.should_receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_root_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) + expect(second_other_mock_call).to receive(:join).once.ordered.with({mixer_name: mixer}, {}) dial.merge other_dial waiter_thread = Thread.new do dial.await_completion @@ -2348,14 +2350,14 @@ other_mock_call.async << mock_end second_root_call.async << mock_end second_other_mock_call.async << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy waiter_thread.join - dial.status.result.should be == :answer + expect(dial.status.result).to eq(:answer) end end end end end @@ -2368,27 +2370,27 @@ it "should raise Call::Hangup" do expect { subject.dial_and_confirm to, options }.to raise_error(Call::Hangup) end it "should not make any outbound calls" do - OutboundCall.should_receive(:new).never + expect(OutboundCall).to receive(:new).never expect { subject.dial_and_confirm to, options }.to raise_error end end describe "with multiple third parties specified" do let(:options) { {} } let(:other_options) { options } let(:second_other_options) { options } before do - OutboundCall.should_receive(:new).and_return other_mock_call, second_other_mock_call + expect(OutboundCall).to receive(:new).and_return other_mock_call, second_other_mock_call - other_mock_call.should_receive(:dial).once.with(to, other_options) + expect(other_mock_call).to receive(:dial).once.with(to, other_options) - second_other_mock_call.should_receive(:dial).once.with(second_to, second_other_options) - second_other_mock_call.should_receive(:join).never + expect(second_other_mock_call).to receive(:dial).once.with(second_to, second_other_options) + expect(second_other_mock_call).to receive(:join).never end def dial_in_thread Thread.new do status = subject.dial_and_confirm [to, second_to], options @@ -2396,54 +2398,54 @@ status end end it "dials all parties and joins the first one to answer, hanging up the rest" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) - second_other_mock_call.should_receive(:hangup).once.and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) + expect(second_other_mock_call).to receive(:hangup).once do second_other_mock_call << mock_end end t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.should be_a Dial::DialStatus - status.should have(2).calls - status.calls.each { |c| c.should be_a OutboundCall } + expect(status).to be_a Dial::DialStatus + expect(status.calls.size).to eq(2) + status.calls.each { |c| expect(c).to be_a OutboundCall } end it "unblocks when the joined call unjoins, allowing it to proceed further" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) - other_mock_call.should_receive(:hangup).once - second_other_mock_call.should_receive(:hangup).once.and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) + expect(other_mock_call).to receive(:hangup).once + expect(second_other_mock_call).to receive(:hangup).once do second_other_mock_call << mock_end end t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.should be_a Dial::DialStatus - status.should have(2).calls - status.calls.each { |c| c.should be_a OutboundCall } + expect(status).to be_a Dial::DialStatus + expect(status.calls.size).to eq(2) + status.calls.each { |c| expect(c).to be_a OutboundCall } end describe "with options overrides" do let(:options) do { @@ -2503,15 +2505,15 @@ second_to => dial_second_other_options }, options) latch.countdown! end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey second_other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join end end context "when all calls are rejected" do @@ -2521,49 +2523,49 @@ sleep 0.5 other_mock_call << mock_end(:reject) second_other_mock_call << mock_end(:reject) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :no_answer + expect(status.result).to eq(:no_answer) end end context "when a call is answered and joined, and the other ends with an error" do it "has an overall dial status of :answer" do - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) - second_other_mock_call.should_receive(:hangup).once.and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) + expect(second_other_mock_call).to receive(:hangup).once do second_other_mock_call << mock_end(:error) end t = dial_in_thread sleep 0.5 other_mock_call << mock_answered other_mock_call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :answer + expect(status.result).to eq(:answer) end end end describe "with a timeout specified" do let(:timeout) { 3 } it "should abort the dial after the specified timeout" do - other_mock_call.should_receive(:dial).once - other_mock_call.should_receive(:hangup).once - OutboundCall.should_receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).once + expect(other_mock_call).to receive(:hangup).once + expect(OutboundCall).to receive(:new).and_return other_mock_call time = Time.now t = Thread.new do status = subject.dial_and_confirm to, :timeout => timeout @@ -2571,45 +2573,45 @@ status end latch.wait time = Time.now - time - time.round.should be == timeout + expect(time.round).to eq(timeout) t.join status = t.value - status.result.should be == :timeout + expect(status.result).to eq(:timeout) end describe "if someone answers before the timeout elapses" do it "should not abort until the far end hangs up" do - other_mock_call.should_receive(:dial).once.with(to, hash_including(:timeout => timeout)) - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}) - OutboundCall.should_receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).once.with(to, hash_including(:timeout => timeout)) + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) + expect(OutboundCall).to receive(:new).and_return other_mock_call time = Time.now t = Thread.new do status = subject.dial_and_confirm to, :timeout => timeout latch.countdown! status end - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_end - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy time = Time.now - time - time.to_i.should be > timeout + expect(time.to_i).to be > timeout t.join status = t.value - status.result.should be == :answer + expect(status.result).to eq(:answer) end end end describe "with a confirmation controller" do @@ -2638,113 +2640,113 @@ context "with confirmation controller metadata specified" do let(:options) { {:confirm => confirmation_controller, :confirm_metadata => {:foo => 'bar'}} } before do - other_mock_call.should_receive(:dial).once - OutboundCall.should_receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).once + expect(OutboundCall).to receive(:new).and_return other_mock_call end it "should set the metadata on the controller" do - other_mock_call.should_receive(:hangup).once.and_return do + expect(other_mock_call).to receive(:hangup).once do other_mock_call << mock_end end other_mock_call['confirm'] = false dial_in_thread - latch.wait(0.1).should be_false + expect(latch.wait(0.1)).to be_falsey other_mock_call << mock_answered - confirmation_latch.wait(2).should be_true - latch.wait(2).should be_true + expect(confirmation_latch.wait(2)).to be_truthy + expect(latch.wait(2)).to be_truthy - other_mock_call[:foo].should == 'bar' + expect(other_mock_call[:foo]).to eq('bar') end end context "when an outbound call is answered" do before do - other_mock_call.should_receive(:dial).once - OutboundCall.should_receive(:new).and_return other_mock_call + expect(other_mock_call).to receive(:dial).once + expect(OutboundCall).to receive(:new).and_return other_mock_call end it "should execute the specified confirmation controller" do - other_mock_call.should_receive(:hangup).once.and_return do + expect(other_mock_call).to receive(:hangup).once do other_mock_call << mock_end end other_mock_call['confirm'] = false dial_in_thread - latch.wait(0.1).should be_false + expect(latch.wait(0.1)).to be_falsey other_mock_call << mock_answered - confirmation_latch.wait(2).should be_true - latch.wait(2).should be_true + expect(confirmation_latch.wait(2)).to be_truthy + expect(latch.wait(2)).to be_truthy end it "should join the calls if the call is still active after execution of the call controller" do - other_mock_call.should_receive(:hangup).once.and_return do + expect(other_mock_call).to receive(:hangup).once do other_mock_call << mock_end end other_mock_call['confirm'] = true - call.should_receive(:answer).once - other_mock_call.should_receive(:join).once.with(call, {}).and_return do + expect(call).to receive(:answer).once + expect(other_mock_call).to receive(:join).once.with(call, {}) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey base_time = Time.local(2008, 9, 1, 12, 0, 0) Timecop.freeze base_time other_mock_call << mock_answered base_time = Time.local(2008, 9, 1, 12, 0, 42) Timecop.freeze base_time other_mock_call << Punchblock::Event::Unjoined.new(call_uri: call.id) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :answer + expect(status.result).to eq(:answer) joined_status = status.joins[status.calls.first] - joined_status.duration.should == 42.0 - joined_status.result.should == :joined + expect(joined_status.duration).to eq(42.0) + expect(joined_status.result).to eq(:joined) end it "should not join the calls if the call is not active after execution of the call controller" do - other_mock_call.should_receive(:hangup).once.and_return do + expect(other_mock_call).to receive(:hangup).once do other_mock_call << mock_end end other_mock_call['confirm'] = false - call.should_receive(:answer).never - other_mock_call.should_receive(:join).never.with(call) + expect(call).to receive(:answer).never + expect(other_mock_call).to receive(:join).never.with(call) t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call << mock_answered - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy t.join status = t.value - status.result.should be == :unconfirmed + expect(status.result).to eq(:unconfirmed) joined_status = status.joins[status.calls.first] - joined_status.duration.should == 0.0 - joined_status.result.should == :unconfirmed + expect(joined_status.duration).to eq(0.0) + expect(joined_status.result).to eq(:unconfirmed) end end context "when multiple calls are made" do let(:confirmation_latch) { CountDownLatch.new 2 } @@ -2758,11 +2760,11 @@ end end let(:options) { {confirm: confirmation_controller, confirm_metadata: {'foo' => 'bar'}, apology: apology_controller} } before do - OutboundCall.should_receive(:new).and_return other_mock_call, second_other_mock_call + expect(OutboundCall).to receive(:new).and_return other_mock_call, second_other_mock_call end def dial_in_thread Thread.new do status = subject.dial_and_confirm [to, second_to], options @@ -2776,52 +2778,52 @@ other_mock_call['confirm'] = true other_mock_call['confirmation_delay'] = 1 second_other_mock_call['confirm'] = true second_other_mock_call['confirmation_delay'] = 1.3 - call.should_receive(:answer).once + expect(call).to receive(:answer).once - other_mock_call.should_receive(:dial).once.with(to, from: nil) - other_mock_call.should_receive(:join).once.with(call, {}).and_return do + expect(other_mock_call).to receive(:dial).once.with(to, from: nil) + expect(other_mock_call).to receive(:join).once.with(call, {}) do call << Punchblock::Event::Joined.new(call_uri: other_mock_call.id) other_mock_call << Punchblock::Event::Joined.new(call_uri: call.id) end - other_mock_call.should_receive(:hangup).once.and_return do + expect(other_mock_call).to receive(:hangup).once do other_mock_call.async.deliver_message mock_end end - second_other_mock_call.should_receive(:dial).once.with(second_to, from: nil) - second_other_mock_call.should_receive(:join).never - second_other_mock_call.should_receive(:hangup).once.and_return do + expect(second_other_mock_call).to receive(:dial).once.with(second_to, from: nil) + expect(second_other_mock_call).to receive(:join).never + expect(second_other_mock_call).to receive(:hangup).once do second_other_mock_call.async.deliver_message mock_end end t = dial_in_thread - latch.wait(2).should be_false + expect(latch.wait(2)).to be_falsey other_mock_call.async.deliver_message mock_answered second_other_mock_call.async.deliver_message mock_answered - confirmation_latch.wait(2).should be_true + expect(confirmation_latch.wait(2)).to be_truthy sleep 2 other_mock_call.async.deliver_message Punchblock::Event::Unjoined.new(call_uri: call.id) - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy - second_other_mock_call['apology_done'].should be_true - second_other_mock_call['apology_metadata'].should == {'foo' => 'bar'} + expect(second_other_mock_call['apology_done']).to be_truthy + expect(second_other_mock_call['apology_metadata']).to eq({'foo' => 'bar'}) t.join status = t.value - status.should be_a Dial::DialStatus - status.should have(2).calls - status.calls.each { |c| c.should be_a OutboundCall } - status.result.should be == :answer - status.joins[other_mock_call].result.should == :joined - status.joins[second_other_mock_call].result.should == :lost_confirmation + expect(status).to be_a Dial::DialStatus + expect(status.calls.size).to eq(2) + status.calls.each { |c| expect(c).to be_a OutboundCall } + expect(status.result).to eq(:answer) + expect(status.joins[other_mock_call].result).to eq(:joined) + expect(status.joins[second_other_mock_call].result).to eq(:lost_confirmation) end end end end end @@ -2829,26 +2831,26 @@ describe Dial::Dial do subject { Dial::Dial.new to, {}, call } describe "#prep_calls" do it "yields all calls to the passed block" do - OutboundCall.should_receive(:new).and_return other_mock_call + expect(OutboundCall).to receive(:new).and_return other_mock_call gathered_calls = [] subject.prep_calls { |call| gathered_calls << call } expect(gathered_calls).to include(other_mock_call) end end context "#skip_cleanup" do it "allows the new call to continue after the root call ends" do - OutboundCall.should_receive(:new).and_return other_mock_call + expect(OutboundCall).to receive(:new).and_return other_mock_call - call.stub answer: true - other_mock_call.stub dial: true, join: true - other_mock_call.should_receive(:hangup).never + allow(call).to receive_messages answer: true + allow(other_mock_call).to receive_messages dial: true, join: true + expect(other_mock_call).to receive(:hangup).never subject.run double('controller') subject.skip_cleanup @@ -2859,10 +2861,40 @@ end other_mock_call << mock_answered call << mock_end - latch.wait(2).should be_true + expect(latch.wait(2)).to be_truthy + end + end + + describe "#cleanup_calls" do + let(:dial) { Dial::Dial.new to, dial_options, call } + + before do + allow(other_mock_call).to receive_messages dial: true + expect(OutboundCall).to receive(:new).and_return other_mock_call + end + + context "when a Cleanup Controller is specified" do + let(:cleanup_controller) do + Class.new(Adhearsion::CallController) do + def run + logger.info "Cleaning up..." + end + end + end + let(:dial_options) { {cleanup: cleanup_controller} } + + it "invokes the Cleanup Controller on each active outbound call before terminating the call" do + expect(cleanup_controller).to receive(:new).with(other_mock_call, anything) + Thread.new do + dial.run double(Adhearsion::CallController) + dial.cleanup_calls + latch.countdown! + end + expect(latch.wait(2)).to be_truthy + end end end end end end