diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 251e94b..106fd53 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,4 @@ require 'adhearsion' -require 'flexmock' require 'voicemail' Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f } @@ -8,7 +7,6 @@ config.color = true config.tty = true - config.mock_framework = :flexmock config.filter_run :focus => true config.run_all_when_everything_filtered = true end diff --git a/spec/support/voicemail_controller_spec_helper.rb b/spec/support/voicemail_controller_spec_helper.rb index a3d1eb9..d8de6a7 100644 --- a/spec/support/voicemail_controller_spec_helper.rb +++ b/spec/support/voicemail_controller_spec_helper.rb @@ -1,7 +1,7 @@ module VoicemailControllerSpecHelper def self.included(test_case) test_case.let(:from) { "sip:user@server.com" } - test_case.let(:call) { flexmock 'Call', from: from } + test_case.let(:call) { Adhearsion::Call.new from: from, active?: true } test_case.let(:config) { Voicemail::Plugin.config } test_case.let(:greeting) { nil } test_case.let(:mailbox) do @@ -13,27 +13,27 @@ def self.included(test_case) email_address: 'lpradovera@mojolingo.com' } end - test_case.let(:storage_instance) { flexmock 'StorageInstance' } + test_case.let(:storage_instance) { double 'StorageInstance' } test_case.let(:metadata) do { :mailbox => 100, :storage => storage_instance } end - test_case.subject(:controller) { flexmock test_case.described_class.new(call, metadata) } + test_case.subject(:controller) { test_case.described_class.new(call, metadata) } test_case.before(:each) do - storage_instance.should_receive(:get_mailbox).with(metadata[:mailbox]).and_return(mailbox) + expect(storage_instance).to receive(:get_mailbox).with(metadata[:mailbox]).and_return(mailbox) end end def should_play(*args) - subject.should_receive(:play).once.tap { |exp| exp.with(*args) if args.count > 0 } + expect(subject).to receive(:play).once.tap { |exp| exp.with(*args) if args.count > 0 } end def should_ask(*args) - subject.should_receive(:ask).with(*args).once + expect(subject).to receive(:ask).with(*args).once end def should_invoke(*args) - subject.should_receive(:invoke).once.with(*args) + expect(subject).to receive(:invoke).once.with(*args) end end diff --git a/spec/voicemail/call_controllers/mailbox_play_message_controller_spec.rb b/spec/voicemail/call_controllers/mailbox_play_message_controller_spec.rb index 7342ee5..071bd3a 100644 --- a/spec/voicemail/call_controllers/mailbox_play_message_controller_spec.rb +++ b/spec/voicemail/call_controllers/mailbox_play_message_controller_spec.rb @@ -46,7 +46,6 @@ end describe '#play_message' do - include FlexMock::ArgumentTypes before do ['delete', 'replay', 'skip'].each do |prompt| subject.should_receive(:t).with("voicemail.messages.menu.#{prompt}").and_return prompt diff --git a/spec/voicemail/call_controllers/voicemail_controller_spec.rb b/spec/voicemail/call_controllers/voicemail_controller_spec.rb index b02a25d..168497d 100644 --- a/spec/voicemail/call_controllers/voicemail_controller_spec.rb +++ b/spec/voicemail/call_controllers/voicemail_controller_spec.rb @@ -42,7 +42,7 @@ end context 'with an existing mailbox' do - let(:ask_result) { flexmock 'Result', status: :noinput, response: nil } + let(:ask_result) { Adhearsion::CallController::Input::Result.new status: :noinput, utterance: nil } def default_output_expectations subject.should_receive(:t).with('voicemail.default_greeting').and_return 'Hiyas!' @@ -77,7 +77,7 @@ def default_output_expectations context 'when the greeting message is interrupted' do context 'with the correct digit' do - let(:ask_result) { flexmock 'Result', status: :match, response: '#' } + let(:ask_result) { Adhearsion::CallController::Input::Result.new status: :match, utterance: '#' } it 'should pass control to the AuthenticationController' do subject.should_receive(:t).with('voicemail.default_greeting').and_return 'Hiyas!' should_ask('Hiyas!', limit: 1).and_return ask_result @@ -86,7 +86,7 @@ def default_output_expectations end end context 'with an incorrect digit' do - let(:ask_result) { flexmock 'Result', status: :match, response: '1' } + let(:ask_result) { Adhearsion::CallController::Input::Result.new status: :match, utterance: '1' } it 'executes the normal output, recording and hangup' do default_output_expectations subject.should_receive(:hangup).once diff --git a/spec/voicemail/intro_message_creator_spec.rb b/spec/voicemail/intro_message_creator_spec.rb index ddf4434..05bf9b3 100644 --- a/spec/voicemail/intro_message_creator_spec.rb +++ b/spec/voicemail/intro_message_creator_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Voicemail::IntroMessageCreator do - include FlexMock::ArgumentTypes context 'included in a CallController' do let(:config) { Voicemail::Plugin.config } @@ -11,7 +10,7 @@ received: Time.local(2012, 5, 1, 9, 0, 0) } end - let(:call) { flexmock 'Call', from: 'sip:user@server.com' } + let(:call) { double Adhearsion::Call, from: 'sip:user@server.com' } let(:metadata) { Hash.new } let(:call_controller_class) do class MyCallController < Adhearsion::CallController @@ -19,69 +18,69 @@ class MyCallController < Adhearsion::CallController end end - subject { flexmock call_controller_class.new call, metadata } + subject { call_controller_class.new call, metadata } describe '#intro_message' do context 'in :i18n_string mode' do before do config.numeric_method = :i18n_string - flexmock(I18n).should_receive('localize').with(message[:received]).and_return '9pm' - subject.should_receive(:t).with('voicemail.messages.message_received_on_x', received_on: '9pm').and_return 'Message received at 9pm' + expect(I18n).to receive('localize').with(message[:received]).and_return '9pm' + expect(subject).to receive(:t).with('voicemail.messages.message_received_on_x', received_on: '9pm').and_return 'Message received at 9pm' end it 'returns the translation' do - subject.should_receive(:t).with('voicemail.messages.message_received_from_x', from: message[:from]).and_return 'Message received from 1234' - subject.intro_message(message).should == ['Message received at 9pm', 'Message received from 1234'] + expect(subject).to receive(:t).with('voicemail.messages.message_received_from_x', from: message[:from]).and_return 'Message received from 1234' + expect(subject.intro_message(message)).to eq ['Message received at 9pm', 'Message received from 1234'] end it 'handles an unknown caller' do unk_caller_msg = message.dup unk_caller_msg[:from] = '' - subject.should_receive(:t).with('voicemail.unknown_caller').and_return 'an unknown caller' - subject.should_receive(:t).with('voicemail.messages.message_received_from_x', from: 'an unknown caller').and_return 'Message received from an unknown caller' - subject.intro_message(unk_caller_msg).should == ['Message received at 9pm', 'Message received from an unknown caller'] + expect(subject).to receive(:t).with('voicemail.unknown_caller').and_return 'an unknown caller' + expect(subject).to receive(:t).with('voicemail.messages.message_received_from_x', from: 'an unknown caller').and_return 'Message received from an unknown caller' + expect(subject.intro_message(unk_caller_msg)).to eq ['Message received at 9pm', 'Message received from an unknown caller'] end it 'handles stringified keys' do message = { 'from' => '1234', 'received' => Time.local(2012, 5, 1, 9, 0, 0) } - subject.should_receive(:t).with('voicemail.messages.message_received_from_x', from: message['from']).and_return 'Message received from 1234' - subject.intro_message(message).should == ['Message received at 9pm', 'Message received from 1234'] + expect(subject).to receive(:t).with('voicemail.messages.message_received_from_x', from: message['from']).and_return 'Message received from 1234' + expect(subject.intro_message(message)).to eq ['Message received at 9pm', 'Message received from 1234'] end end context 'in :ahn_say mode' do - let!(:ahn_config) { flexmock(Adhearsion.config, punchblock: OpenStruct.new, ahnsay: OpenStruct.new(sounds_dir: '/')) } before do + Adhearsion.config.ahnsay.sounds_dir = '/' config.numeric_method = :ahn_say config.datetime_format = 'hmp' end it 'returns a nice array full of ahn_say sound files' do - subject.should_receive(:t).with('voicemail.messages.message_received_on').and_return 'Message received on ' - subject.should_receive(:t).with('from').and_return ' from ' - subject.intro_message(message).should == [ + expect(subject).to receive(:t).with('voicemail.messages.message_received_on').and_return 'Message received on ' + expect(subject).to receive(:t).with('from').and_return ' from ' + expect(subject.intro_message(message)).to eq [ 'Message received on ', - ['/9.ul', '/oclock.ul', '/a-m.ul'], + ['file:///9.ul', 'file:///oclock.ul', 'file:///a-m.ul'], ' from ', - ['/1.ul', '/2.ul', '/3.ul', '/4.ul'] + ['file:///1.ul', 'file:///2.ul', 'file:///3.ul', 'file:///4.ul'] ] end end context 'in :play_numeric mode' do - let(:formatter) { flexmock Adhearsion::CallController::Output::Formatter } + let(:formatter) { double Adhearsion::CallController::Output::Formatter } before do - flexmock Adhearsion::CallController::Output::Formatter, new: formatter config.numeric_method = :play_numeric end it 'returns speech and ssml in an array' do - formatter.should_receive(:ssml_for_time).with(Time.local(2012, 5, 1, 9, 0, 0), any).and_return :time - formatter.should_receive(:ssml_for_characters).with('1234').and_return :number - subject.should_receive(:t).with('voicemail.messages.message_received_on').and_return 'Message received on ' - subject.should_receive(:t).with('from').and_return ' from ' - subject.intro_message(message).should == ['Message received on ', :time, ' from ', :number] + pending "Get rid of these mocks" + expect(formatter).to receive(:ssml_for_time).with(Time.local(2012, 5, 1, 9, 0, 0), any_args).and_return :time + expect(formatter).to receive(:ssml_for_characters).with('1234').and_return :number + expect(subject).to receive(:t).with('voicemail.messages.message_received_on').and_return 'Message received on ' + expect(subject).to receive(:t).with('from').and_return ' from ' + expect(subject.intro_message(message)).to eq ['Message received on ', :time, ' from ', :number] end end end diff --git a/spec/voicemail/storage_pstore_spec.rb b/spec/voicemail/storage_pstore_spec.rb index ccda2fc..0bc26d5 100644 --- a/spec/voicemail/storage_pstore_spec.rb +++ b/spec/voicemail/storage_pstore_spec.rb @@ -29,7 +29,6 @@ module Voicemail store[:saved][100] = [message_2, message_3] store[:mailboxes][100] = mailbox end - flexmock storage end end @@ -48,35 +47,35 @@ module Voicemail end describe "#save_recording" do - let(:recording_object) { flexmock 'recording_object', uri: "file://somewav.wav" } + let(:recording_object) { double 'recording_object', uri: "file://somewav.wav" } it "saves the recording" do storage.save_recording(100, :new, "foo", recording_object) storage.store.transaction do |store| - store[:new][100].last[:uri].should == "file://somewav.wav" - store[:new][100].last[:from].should == "foo" - store[:new][100].last[:id].should_not be_nil + expect(store[:new][100].last[:uri]).to eq "file://somewav.wav" + expect(store[:new][100].last[:from]).to eq "foo" + expect(store[:new][100].last[:id]).to_not be_nil end end end describe "#count_messages" do it "returns the new message count" do - storage.count_messages(100, :new).should == 1 + expect(storage.count_messages(100, :new)).to eq 1 end it "returns the saved message count" do - storage.count_messages(100, :saved).should == 2 + expect(storage.count_messages(100, :saved)).to eq 2 end end describe '#get_messages' do it 'returns all new messages' do - storage.get_messages(100, :new).should == [{ id: :foo }] + expect(storage.get_messages(100, :new)).to eq [{ id: :foo }] end it 'returns all saved messages' do - storage.get_messages(100, :saved).should == [{ id: :bar }, { id: :biz }] + expect(storage.get_messages(100, :saved)).to eq [{ id: :bar }, { id: :biz }] end end @@ -84,16 +83,16 @@ module Voicemail it "changes the message type to :saved" do storage.change_message_type 100, :foo, :new, :saved storage.store.transaction do |store| - store[:new][100].should == [] - store[:saved][100].should == [message_2, message_3, message_1] + expect(store[:new][100]).to eq [] + expect(store[:saved][100]).to eq [message_2, message_3, message_1] end end it "changes the message type to :new" do storage.change_message_type 100, :bar, :saved, :new storage.store.transaction do |store| - store[:new][100].should == [message_1, message_2] - store[:saved][100].should == [message_3] + expect(store[:new][100]).to eq [message_1, message_2] + expect(store[:saved][100]).to eq [message_3] end end end @@ -108,7 +107,7 @@ module Voicemail it "deletes the greeting message" do storage.delete_greeting_from_mailbox 100 storage.store.transaction do |store| - store[:mailboxes][100][:greeting].should be_nil + expect(store[:mailboxes][100][:greeting]).to be_nil end end end diff --git a/voicemail.gemspec b/voicemail.gemspec index c96e5b6..ee189ef 100644 --- a/voicemail.gemspec +++ b/voicemail.gemspec @@ -26,7 +26,6 @@ Gem::Specification.new do |s| s.add_development_dependency %q, ["~> 0.6.0"] s.add_development_dependency %q, [">= 0"] s.add_development_dependency %q - s.add_development_dependency %q s.add_development_dependency %q s.add_development_dependency %q end