adhearsion 1.2.6 → 2.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -10
- data/CHANGELOG.md +273 -0
- data/Gemfile +1 -1
- data/Guardfile +17 -0
- data/README.markdown +61 -9
- data/Rakefile +16 -48
- data/adhearsion.gemspec +21 -7
- data/bin/ahn +3 -1
- data/cucumber.yml +4 -0
- data/features/app_generator.feature +42 -0
- data/features/cli.feature +108 -0
- data/features/step_definitions/app_generator_steps.rb +6 -0
- data/features/step_definitions/cli_steps.rb +74 -0
- data/features/support/aruba_helper.rb +22 -0
- data/features/support/env.rb +37 -0
- data/features/support/utils.rb +8 -0
- data/lib/adhearsion.rb +85 -41
- data/lib/adhearsion/call.rb +176 -0
- data/lib/adhearsion/call_controller.rb +134 -0
- data/lib/adhearsion/call_controller/dial.rb +70 -0
- data/lib/adhearsion/call_controller/input.rb +173 -0
- data/lib/adhearsion/call_controller/menu.rb +124 -0
- data/lib/adhearsion/call_controller/output.rb +267 -0
- data/lib/adhearsion/call_controller/record.rb +42 -0
- data/lib/adhearsion/call_controller/utility.rb +60 -0
- data/lib/adhearsion/calls.rb +81 -0
- data/lib/adhearsion/cli.rb +1 -3
- data/lib/adhearsion/cli_commands.rb +142 -0
- data/lib/adhearsion/configuration.rb +149 -0
- data/lib/adhearsion/console.rb +19 -8
- data/lib/adhearsion/dialplan_controller.rb +9 -0
- data/lib/adhearsion/events.rb +84 -0
- data/lib/adhearsion/foundation/all.rb +0 -7
- data/lib/adhearsion/foundation/custom_daemonizer.rb +4 -6
- data/lib/adhearsion/foundation/exception_handler.rb +9 -0
- data/lib/adhearsion/foundation/object.rb +26 -8
- data/lib/adhearsion/foundation/synchronized_hash.rb +3 -6
- data/lib/adhearsion/foundation/thread_safety.rb +17 -1
- data/lib/adhearsion/generators/app/app_generator.rb +4 -13
- data/lib/adhearsion/generators/app/templates/Gemfile +10 -5
- data/lib/adhearsion/generators/app/templates/Procfile +1 -0
- data/lib/adhearsion/generators/app/templates/README.md +28 -0
- data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +41 -0
- data/lib/adhearsion/generators/app/templates/{components/simon_game → lib}/simon_game.rb +6 -18
- data/lib/adhearsion/generators/app/templates/script/ahn +2 -2
- data/lib/adhearsion/initializer.rb +151 -293
- data/lib/adhearsion/initializer/logging.rb +33 -0
- data/lib/adhearsion/logging.rb +65 -69
- data/lib/adhearsion/menu_dsl.rb +15 -0
- data/lib/adhearsion/menu_dsl/calculated_match.rb +39 -0
- data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +41 -0
- data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +18 -0
- data/lib/adhearsion/menu_dsl/match_calculator.rb +36 -0
- data/lib/adhearsion/{voip/menu_state_machine/menu_class.rb → menu_dsl/menu.rb} +38 -40
- data/lib/adhearsion/menu_dsl/menu_builder.rb +69 -0
- data/lib/adhearsion/menu_dsl/range_match_calculator.rb +55 -0
- data/lib/adhearsion/menu_dsl/string_match_calculator.rb +21 -0
- data/lib/adhearsion/outbound_call.rb +64 -0
- data/lib/adhearsion/plugin.rb +319 -0
- data/lib/adhearsion/plugin/collection.rb +19 -0
- data/lib/adhearsion/plugin/initializer.rb +37 -0
- data/lib/adhearsion/plugin/methods_container.rb +6 -0
- data/lib/adhearsion/process.rb +94 -0
- data/lib/adhearsion/punchblock_plugin.rb +29 -0
- data/lib/adhearsion/punchblock_plugin/initializer.rb +137 -0
- data/lib/adhearsion/router.rb +30 -0
- data/lib/adhearsion/router/route.rb +42 -0
- data/lib/adhearsion/script_ahn_loader.rb +2 -2
- data/lib/adhearsion/tasks.rb +14 -9
- data/lib/adhearsion/tasks/configuration.rb +26 -0
- data/lib/adhearsion/tasks/plugins.rb +17 -0
- data/lib/adhearsion/version.rb +8 -14
- data/spec/adhearsion/call_controller/dial_spec.rb +138 -0
- data/spec/adhearsion/call_controller/input_spec.rb +278 -0
- data/spec/adhearsion/call_controller/menu_spec.rb +120 -0
- data/spec/adhearsion/call_controller/output_spec.rb +466 -0
- data/spec/adhearsion/call_controller/record_spec.rb +125 -0
- data/spec/adhearsion/call_controller_spec.rb +395 -0
- data/spec/adhearsion/call_spec.rb +438 -0
- data/spec/adhearsion/calls_spec.rb +47 -0
- data/spec/adhearsion/configuration_spec.rb +308 -0
- data/spec/adhearsion/dialplan_controller_spec.rb +26 -0
- data/spec/adhearsion/events_spec.rb +112 -0
- data/spec/adhearsion/initializer/logging_spec.rb +58 -0
- data/spec/adhearsion/initializer_spec.rb +209 -122
- data/spec/adhearsion/logging_spec.rb +58 -47
- data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +56 -0
- data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +57 -0
- data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +33 -0
- data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +13 -0
- data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +118 -0
- data/spec/adhearsion/menu_dsl/menu_spec.rb +210 -0
- data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +28 -0
- data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +36 -0
- data/spec/adhearsion/menu_dsl_spec.rb +12 -0
- data/spec/adhearsion/outbound_call_spec.rb +174 -0
- data/spec/adhearsion/plugin_spec.rb +489 -0
- data/spec/adhearsion/process_spec.rb +34 -0
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +294 -0
- data/spec/adhearsion/router/route_spec.rb +99 -0
- data/spec/adhearsion/router_spec.rb +106 -0
- data/spec/adhearsion_spec.rb +46 -0
- data/spec/spec_helper.rb +14 -14
- data/spec/support/call_controller_test_helpers.rb +48 -0
- data/spec/support/initializer_stubs.rb +8 -13
- data/spec/support/punchblock_mocks.rb +6 -0
- metadata +255 -253
- data/CHANGELOG +0 -174
- data/bin/ahnctl +0 -68
- data/bin/jahn +0 -43
- data/examples/asterisk_manager_interface/standalone.rb +0 -51
- data/lib/adhearsion/commands.rb +0 -302
- data/lib/adhearsion/component_manager.rb +0 -278
- data/lib/adhearsion/component_manager/component_tester.rb +0 -54
- data/lib/adhearsion/component_manager/spec_framework.rb +0 -18
- data/lib/adhearsion/events_support.rb +0 -65
- data/lib/adhearsion/foundation/blank_slate.rb +0 -3
- data/lib/adhearsion/foundation/event_socket.rb +0 -205
- data/lib/adhearsion/foundation/future_resource.rb +0 -36
- data/lib/adhearsion/foundation/metaprogramming.rb +0 -17
- data/lib/adhearsion/foundation/numeric.rb +0 -13
- data/lib/adhearsion/foundation/pseudo_guid.rb +0 -10
- data/lib/adhearsion/foundation/relationship_properties.rb +0 -42
- data/lib/adhearsion/foundation/string.rb +0 -26
- data/lib/adhearsion/generators/app/templates/.ahnrc +0 -34
- data/lib/adhearsion/generators/app/templates/README +0 -8
- data/lib/adhearsion/generators/app/templates/components/ami_remote/ami_remote.rb +0 -15
- data/lib/adhearsion/generators/app/templates/components/disabled/HOW_TO_ENABLE +0 -7
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/README.markdown +0 -47
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.rb +0 -34
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.yml +0 -12
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/README.markdown +0 -3
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +0 -11
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
- data/lib/adhearsion/generators/app/templates/config/startup.rb +0 -81
- data/lib/adhearsion/generators/app/templates/dialplan.rb +0 -3
- data/lib/adhearsion/generators/app/templates/events.rb +0 -33
- data/lib/adhearsion/host_definitions.rb +0 -67
- data/lib/adhearsion/initializer/asterisk.rb +0 -86
- data/lib/adhearsion/initializer/configuration.rb +0 -324
- data/lib/adhearsion/initializer/database.rb +0 -60
- data/lib/adhearsion/initializer/drb.rb +0 -31
- data/lib/adhearsion/initializer/freeswitch.rb +0 -22
- data/lib/adhearsion/initializer/ldap.rb +0 -57
- data/lib/adhearsion/initializer/rails.rb +0 -41
- data/lib/adhearsion/initializer/xmpp.rb +0 -42
- data/lib/adhearsion/tasks/components.rb +0 -32
- data/lib/adhearsion/tasks/database.rb +0 -5
- data/lib/adhearsion/tasks/deprecations.rb +0 -59
- data/lib/adhearsion/tasks/generating.rb +0 -20
- data/lib/adhearsion/tasks/lint.rb +0 -4
- data/lib/adhearsion/voip/asterisk.rb +0 -4
- data/lib/adhearsion/voip/asterisk/agi_server.rb +0 -121
- data/lib/adhearsion/voip/asterisk/commands.rb +0 -1966
- data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +0 -140
- data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +0 -102
- data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +0 -250
- data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +0 -240
- data/lib/adhearsion/voip/asterisk/config_manager.rb +0 -64
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -697
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +0 -1681
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +0 -341
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +0 -78
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +0 -87
- data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +0 -80
- data/lib/adhearsion/voip/call.rb +0 -521
- data/lib/adhearsion/voip/call_routing.rb +0 -64
- data/lib/adhearsion/voip/commands.rb +0 -17
- data/lib/adhearsion/voip/constants.rb +0 -39
- data/lib/adhearsion/voip/conveniences.rb +0 -18
- data/lib/adhearsion/voip/dial_plan.rb +0 -252
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +0 -151
- data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +0 -37
- data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +0 -27
- data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +0 -124
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +0 -69
- data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +0 -16
- data/lib/adhearsion/voip/dsl/numerical_string.rb +0 -128
- data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +0 -48
- data/lib/adhearsion/voip/freeswitch/event_handler.rb +0 -58
- data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +0 -129
- data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +0 -38
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +0 -195
- data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +0 -80
- data/lib/adhearsion/voip/menu_state_machine/matchers.rb +0 -123
- data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +0 -57
- data/lib/adhearsion/xmpp/connection.rb +0 -61
- data/lib/theatre.rb +0 -147
- data/lib/theatre/README.markdown +0 -64
- data/lib/theatre/callback_definition_loader.rb +0 -86
- data/lib/theatre/guid.rb +0 -23
- data/lib/theatre/invocation.rb +0 -131
- data/lib/theatre/namespace_manager.rb +0 -153
- data/lib/theatre/version.rb +0 -2
- data/spec/adhearsion/cli_spec.rb +0 -306
- data/spec/adhearsion/component_manager_spec.rb +0 -292
- data/spec/adhearsion/constants_spec.rb +0 -8
- data/spec/adhearsion/drb_spec.rb +0 -65
- data/spec/adhearsion/fixtures/dialplan.rb +0 -3
- data/spec/adhearsion/foundation/event_socket_spec.rb +0 -168
- data/spec/adhearsion/host_definitions_spec.rb +0 -79
- data/spec/adhearsion/initializer/configuration_spec.rb +0 -291
- data/spec/adhearsion/initializer/loading_spec.rb +0 -154
- data/spec/adhearsion/initializer/paths_spec.rb +0 -74
- data/spec/adhearsion/relationship_properties_spec.rb +0 -54
- data/spec/adhearsion/voip/asterisk/agi_server_spec.rb +0 -473
- data/spec/adhearsion/voip/asterisk/ami/ami_spec.rb +0 -550
- data/spec/adhearsion/voip/asterisk/ami/lexer/ami_fixtures.yml +0 -30
- data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story +0 -291
- data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story.rb +0 -241
- data/spec/adhearsion/voip/asterisk/ami/lexer/story_helper.rb +0 -124
- data/spec/adhearsion/voip/asterisk/commands_spec.rb +0 -3241
- data/spec/adhearsion/voip/asterisk/config_file_generators/agents_spec.rb +0 -251
- data/spec/adhearsion/voip/asterisk/config_file_generators/queues_spec.rb +0 -323
- data/spec/adhearsion/voip/asterisk/config_file_generators/voicemail_spec.rb +0 -306
- data/spec/adhearsion/voip/asterisk/config_manager_spec.rb +0 -127
- data/spec/adhearsion/voip/asterisk/menu_command/calculated_match_spec.rb +0 -109
- data/spec/adhearsion/voip/asterisk/menu_command/matchers_spec.rb +0 -97
- data/spec/adhearsion/voip/call_routing_spec.rb +0 -125
- data/spec/adhearsion/voip/dialplan_manager_spec.rb +0 -468
- data/spec/adhearsion/voip/dsl/dialing_dsl_spec.rb +0 -270
- data/spec/adhearsion/voip/dsl/dispatcher_spec.rb +0 -82
- data/spec/adhearsion/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/adhearsion/voip/dsl/parser_spec.rb +0 -69
- data/spec/adhearsion/voip/freeswitch/basic_connection_manager_spec.rb +0 -39
- data/spec/adhearsion/voip/freeswitch/inbound_connection_manager_spec.rb +0 -39
- data/spec/adhearsion/voip/freeswitch/oes_server_spec.rb +0 -9
- data/spec/adhearsion/voip/numerical_string_spec.rb +0 -61
- data/spec/adhearsion/voip/phone_number_spec.rb +0 -45
- data/spec/support/the_following_code.rb +0 -3
- data/spec/theatre/dsl_examples/simple_before_call.rb +0 -7
- data/spec/theatre/dsl_spec.rb +0 -69
- data/spec/theatre/invocation_spec.rb +0 -182
- data/spec/theatre/namespace_spec.rb +0 -125
- data/spec/theatre/spec_helper_spec.rb +0 -28
- data/spec/theatre/theatre_class_spec.rb +0 -148
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Adhearsion
|
4
|
+
class CallController
|
5
|
+
describe Menu do
|
6
|
+
include CallControllerTestHelpers
|
7
|
+
|
8
|
+
describe "#play_sound_files_for_menu" do
|
9
|
+
let(:options) { Hash.new }
|
10
|
+
let(:menu_instance) { Adhearsion::MenuDSL::Menu.new(options) {} }
|
11
|
+
let(:sound_file) { "press a button" }
|
12
|
+
let(:sound_files) { [sound_file] }
|
13
|
+
|
14
|
+
it "should play the sound files for the menu" do
|
15
|
+
subject.should_receive(:interruptible_play).with(sound_file).and_return("1")
|
16
|
+
subject.play_sound_files_for_menu(menu_instance, sound_files)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should wait for digit if nothing is pressed during playback" do
|
20
|
+
subject.should_receive(:interruptible_play).with(sound_file).and_return(nil)
|
21
|
+
subject.should_receive(:wait_for_digit).with(menu_instance.timeout).and_return("1")
|
22
|
+
subject.play_sound_files_for_menu(menu_instance, sound_files)
|
23
|
+
end
|
24
|
+
end#play_sound_files_for_menu
|
25
|
+
|
26
|
+
describe "#jump_to" do
|
27
|
+
let(:match_object) { flexmock(Class.new) }
|
28
|
+
let(:overrides) { Hash.new(:extension => "1") }
|
29
|
+
let(:block) { Proc.new() {} }
|
30
|
+
|
31
|
+
it "calls instance_exec if the match object has a block" do
|
32
|
+
match_object.should_receive(:block).and_return(block)
|
33
|
+
subject.should_receive(:instance_exec).with(overrides[:extension], block)
|
34
|
+
subject.jump_to(match_object, overrides)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "calls invoke if the match object does not have a block" do
|
38
|
+
match_object.should_receive(:block).and_return(false)
|
39
|
+
match_object.should_receive(:match_payload).and_return(:payload)
|
40
|
+
subject.should_receive(:invoke).with(:payload, overrides)
|
41
|
+
subject.jump_to(match_object, overrides)
|
42
|
+
end
|
43
|
+
end#jump_to
|
44
|
+
|
45
|
+
describe "#menu" do
|
46
|
+
let(:sound_files) { ["press", "button"] }
|
47
|
+
context "menu state flow" do
|
48
|
+
let(:menu_instance) do
|
49
|
+
menu_instance = flexmock(MenuDSL::Menu.new({}) {})
|
50
|
+
end
|
51
|
+
let(:result_done) { MenuDSL::Menu::MenuResultDone.new }
|
52
|
+
let(:result_invalid) { MenuDSL::Menu::MenuResultInvalid.new }
|
53
|
+
let(:result_get_another_or_timeout) { MenuDSL::Menu::MenuGetAnotherDigitOrTimeout.new }
|
54
|
+
let(:result_get_another_or_finish) { MenuDSL::Menu::MenuGetAnotherDigitOrFinish.new(:match_object, :new_extension) }
|
55
|
+
let(:result_found) { MenuDSL::Menu::MenuResultFound.new(:match_object, :new_extension) }
|
56
|
+
|
57
|
+
before(:each) do
|
58
|
+
flexmock(MenuDSL::Menu).should_receive(:new).and_return(menu_instance)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "exits the function if MenuResultDone" do
|
62
|
+
menu_instance.should_receive(:should_continue?).and_return(true)
|
63
|
+
menu_instance.should_receive(:continue).and_return(result_done)
|
64
|
+
result = subject.menu(sound_files) {}
|
65
|
+
result.should == :done
|
66
|
+
end
|
67
|
+
|
68
|
+
it "executes failure hook and returns :failure if menu fails" do
|
69
|
+
menu_instance.should_receive(:should_continue?).and_return(false)
|
70
|
+
menu_instance.should_receive(:execute_failure_hook)
|
71
|
+
result = subject.menu(sound_files) {}
|
72
|
+
result.should == :failed
|
73
|
+
end
|
74
|
+
|
75
|
+
it "executes invalid hook if input is invalid" do
|
76
|
+
menu_instance.should_receive(:should_continue?).twice.and_return(true)
|
77
|
+
menu_instance.should_receive(:continue).and_return(result_invalid, result_done)
|
78
|
+
menu_instance.should_receive(:execute_invalid_hook)
|
79
|
+
menu_instance.should_receive(:restart!)
|
80
|
+
subject.menu(sound_files) {}
|
81
|
+
end
|
82
|
+
|
83
|
+
it "plays audio, then executes timeout hook if input times out" do
|
84
|
+
menu_instance.should_receive(:should_continue?).twice.and_return(true)
|
85
|
+
menu_instance.should_receive(:continue).and_return(result_get_another_or_timeout, result_done)
|
86
|
+
subject.should_receive(:play_sound_files_for_menu).with(menu_instance, sound_files).and_return(nil)
|
87
|
+
menu_instance.should_receive(:execute_timeout_hook)
|
88
|
+
menu_instance.should_receive(:restart!)
|
89
|
+
subject.menu(sound_files) {}
|
90
|
+
end
|
91
|
+
|
92
|
+
it "plays audio, then adds digit to digit buffer if input is received" do
|
93
|
+
menu_instance.should_receive(:should_continue?).twice.and_return(true)
|
94
|
+
menu_instance.should_receive(:continue).and_return(result_get_another_or_timeout, result_done)
|
95
|
+
subject.should_receive(:play_sound_files_for_menu).with(menu_instance, sound_files).and_return("1")
|
96
|
+
menu_instance.should_receive(:<<).with("1")
|
97
|
+
subject.menu(sound_files) {}
|
98
|
+
end
|
99
|
+
|
100
|
+
it "plays audio, then jumps to payload when input is finished" do
|
101
|
+
menu_instance.should_receive(:should_continue?).and_return(true)
|
102
|
+
menu_instance.should_receive(:continue).and_return(result_get_another_or_finish)
|
103
|
+
subject.should_receive(:play_sound_files_for_menu).with(menu_instance, sound_files).and_return(nil)
|
104
|
+
subject.should_receive(:jump_to).with(:match_object, :extension => :new_extension)
|
105
|
+
subject.menu(sound_files) {}
|
106
|
+
end
|
107
|
+
|
108
|
+
it "jumps to payload when result is found" do
|
109
|
+
menu_instance.should_receive(:should_continue?).and_return(true)
|
110
|
+
menu_instance.should_receive(:continue).and_return(result_found)
|
111
|
+
subject.should_receive(:jump_to).with(:match_object, :extension => :new_extension)
|
112
|
+
subject.menu(sound_files) {}
|
113
|
+
end
|
114
|
+
end#context
|
115
|
+
|
116
|
+
end#describe
|
117
|
+
|
118
|
+
end#shared
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,466 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Adhearsion
|
4
|
+
class CallController
|
5
|
+
describe Output do
|
6
|
+
include CallControllerTestHelpers
|
7
|
+
|
8
|
+
describe "#play_ssml" do
|
9
|
+
let(:ssml) { RubySpeech::SSML.draw { string "BOO" } }
|
10
|
+
|
11
|
+
it 'executes an Output with the correct ssml' do
|
12
|
+
expect_component_execution Punchblock::Component::Output.new(:ssml => ssml.to_s)
|
13
|
+
subject.play_ssml ssml
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "if an error is returned" do
|
17
|
+
before do
|
18
|
+
pending
|
19
|
+
subject.should_receive(:execute_component_and_await_completion).once.and_raise(StandardError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return false' do
|
23
|
+
pending
|
24
|
+
subject.play_ssml(ssml).should be false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#play_audio" do
|
30
|
+
let(:audio_file) { "/sounds/boo.wav" }
|
31
|
+
let(:fallback) { "text for tts" }
|
32
|
+
|
33
|
+
let(:ssml) do
|
34
|
+
file = audio_file
|
35
|
+
RubySpeech::SSML.draw { audio :src => file }
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:ssml_with_fallback) do
|
39
|
+
file = audio_file
|
40
|
+
fallback_text = fallback
|
41
|
+
RubySpeech::SSML.draw {
|
42
|
+
audio(:src => file) { fallback_text }
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'plays the correct ssml' do
|
47
|
+
subject.should_receive(:play_ssml).once.with(ssml).and_return true
|
48
|
+
subject.play_audio(audio_file).should be true
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'allows for fallback tts' do
|
52
|
+
subject.should_receive(:play_ssml).once.with(ssml_with_fallback).and_return true
|
53
|
+
subject.play_audio(audio_file, :fallback => fallback).should be true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#play_numeric" do
|
58
|
+
let :expected_doc do
|
59
|
+
RubySpeech::SSML.draw do
|
60
|
+
say_as(:interpret_as => 'cardinal') { "123" }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "with a number" do
|
65
|
+
let(:input) { 123 }
|
66
|
+
|
67
|
+
it 'plays the correct ssml' do
|
68
|
+
subject.should_receive(:play_ssml).once.with(expected_doc).and_return true
|
69
|
+
subject.play_numeric(input).should be true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "with a string representation of a number" do
|
74
|
+
let(:input) { "123" }
|
75
|
+
|
76
|
+
it 'plays the correct ssml' do
|
77
|
+
subject.should_receive(:play_ssml).once.with(expected_doc).and_return true
|
78
|
+
subject.play_numeric(input).should be true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "with something that's not a number" do
|
83
|
+
let(:input) { 'foo' }
|
84
|
+
|
85
|
+
it 'returns nil' do
|
86
|
+
subject.play_numeric(input).should be nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#play_time" do
|
92
|
+
let :expected_doc do
|
93
|
+
content = input.to_s
|
94
|
+
opts = expected_say_as_options
|
95
|
+
RubySpeech::SSML.draw do
|
96
|
+
say_as(opts) { content }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "with a time" do
|
101
|
+
let(:input) { Time.parse("12/5/2000") }
|
102
|
+
let(:expected_say_as_options) { {:interpret_as => 'time'} }
|
103
|
+
|
104
|
+
it 'plays the correct SSML' do
|
105
|
+
subject.should_receive(:play_ssml).once.with(expected_doc).and_return true
|
106
|
+
subject.play_time(input).should be true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "with a date" do
|
111
|
+
let(:input) { Date.parse('2011-01-23') }
|
112
|
+
let(:expected_say_as_options) { {:interpret_as => 'date'} }
|
113
|
+
|
114
|
+
it 'plays the correct SSML' do
|
115
|
+
subject.should_receive(:play_ssml).once.with(expected_doc).and_return true
|
116
|
+
subject.play_time(input).should be true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "with a date and a say_as format" do
|
121
|
+
let(:input) { Date.parse('2011-01-23') }
|
122
|
+
let(:format) { "d-m-y" }
|
123
|
+
let(:expected_say_as_options) { {:interpret_as => 'date', :format => format} }
|
124
|
+
|
125
|
+
it 'plays the correct SSML' do
|
126
|
+
subject.should_receive(:play_ssml).once.with(expected_doc).and_return true
|
127
|
+
subject.play_time(input, :format => format).should be true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "with a date and a strftime option" do
|
132
|
+
let(:strftime) { "%d-%m-%Y" }
|
133
|
+
let(:base_input) { Date.parse('2011-01-23') }
|
134
|
+
let(:input) { base_input.strftime(strftime) }
|
135
|
+
let(:expected_say_as_options) { {:interpret_as => 'date'} }
|
136
|
+
|
137
|
+
it 'plays the correct SSML' do
|
138
|
+
subject.should_receive(:play_ssml).once.with(expected_doc).and_return true
|
139
|
+
subject.play_time(base_input, :strftime => strftime).should be true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "with a date, a format option and a strftime option" do
|
144
|
+
let(:strftime) { "%d-%m-%Y" }
|
145
|
+
let(:format) { "d-m-y" }
|
146
|
+
let(:base_input) { Date.parse('2011-01-23') }
|
147
|
+
let(:input) { base_input.strftime(strftime) }
|
148
|
+
let(:expected_say_as_options) { {:interpret_as => 'date', :format => format} }
|
149
|
+
|
150
|
+
it 'plays the correct SSML' do
|
151
|
+
subject.should_receive(:play_ssml).once.with(expected_doc).and_return true
|
152
|
+
subject.play_time(base_input, :format => format, :strftime => strftime).should be true
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "with an object other than Time, DateTime, or Date" do
|
157
|
+
let(:input) { "foo" }
|
158
|
+
|
159
|
+
it 'returns false' do
|
160
|
+
subject.play_time(input).should be false
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '#play' do
|
166
|
+
describe "with a single string" do
|
167
|
+
let(:file) { "cents-per-minute" }
|
168
|
+
|
169
|
+
it 'plays the audio file' do
|
170
|
+
subject.should_receive(:play_ssml_for).once.with(file).and_return true
|
171
|
+
subject.play(file).should be true
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "with multiple strings" do
|
176
|
+
let(:args) { ['rock', 'paperz', 'scissors'] }
|
177
|
+
|
178
|
+
it 'plays multiple files' do
|
179
|
+
args.each do |file|
|
180
|
+
subject.should_receive(:play_ssml_for).once.with(file).and_return true
|
181
|
+
end
|
182
|
+
|
183
|
+
subject.play(*args).should be true
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "if an audio file cannot be found" do
|
187
|
+
before do
|
188
|
+
pending
|
189
|
+
subject.should_receive(:play_audio).with(args[0]).and_return(true).ordered
|
190
|
+
subject.should_receive(:play_audio).with(args[1]).and_return(false).ordered
|
191
|
+
subject.should_receive(:play_audio).with(args[2]).and_return(true).ordered
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should return false' do
|
195
|
+
subject.play(*args).should be false
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "with a number" do
|
201
|
+
it 'plays the number' do
|
202
|
+
subject.should_receive(:play_ssml_for).with(123).and_return(true)
|
203
|
+
subject.play(123).should be true
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "with a string representation of a number" do
|
208
|
+
it 'plays the number' do
|
209
|
+
subject.should_receive(:play_ssml_for).with('123').and_return(true)
|
210
|
+
subject.play('123').should be true
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "with a time" do
|
215
|
+
let(:time) { Time.parse("12/5/2000") }
|
216
|
+
|
217
|
+
it 'plays the time' do
|
218
|
+
subject.should_receive(:play_ssml_for).with(time).and_return(true)
|
219
|
+
subject.play(time).should be true
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "with a date" do
|
224
|
+
let(:date) { Date.parse('2011-01-23') }
|
225
|
+
|
226
|
+
it 'plays the time' do
|
227
|
+
subject.should_receive(:play_ssml_for).with(date).and_return(true)
|
228
|
+
subject.play(date).should be true
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe "with an array containing a Date/DateTime/Time object and a hash" do
|
233
|
+
let(:date) { Date.parse('2011-01-23') }
|
234
|
+
let(:format) { "d-m-y" }
|
235
|
+
let(:strftime) { "%d-%m%Y" }
|
236
|
+
|
237
|
+
it 'plays the time with the specified format and strftime' do
|
238
|
+
subject.should_receive(:play_ssml_for).with(date, {:format => format, :strftime => strftime}).and_return(true)
|
239
|
+
subject.play({:value => date, :format => format, :strftime => strftime}).should be true
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "with an SSML document" do
|
244
|
+
let(:ssml) { RubySpeech::SSML.draw { string "Hello world" } }
|
245
|
+
|
246
|
+
it "plays the SSML without generating" do
|
247
|
+
subject.should_receive(:play_ssml).with(ssml).and_return(true)
|
248
|
+
subject.play(ssml).should be true
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe "#play!" do
|
254
|
+
let(:prompt) { "Press any button." }
|
255
|
+
let(:second_prompt) { "Or press nothing." }
|
256
|
+
let(:non_existing) { "http://adhearsion.com/nonexistingfile.mp3" }
|
257
|
+
|
258
|
+
it "calls play a single time" do
|
259
|
+
subject.should_receive(:play).once.with(prompt).and_return(true)
|
260
|
+
subject.play!(prompt)
|
261
|
+
end
|
262
|
+
|
263
|
+
it "calls play two times" do
|
264
|
+
subject.should_receive(:play).once.with(prompt, second_prompt).and_return(true)
|
265
|
+
subject.play!(prompt, second_prompt)
|
266
|
+
end
|
267
|
+
|
268
|
+
it "raises an exception if play fails" do
|
269
|
+
subject.should_receive(:play).once.and_return false
|
270
|
+
expect { subject.play!(non_existing) }.to raise_error(Adhearsion::PlaybackError)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "#speak" do
|
275
|
+
describe "with a RubySpeech document" do
|
276
|
+
it 'plays the correct SSML' do
|
277
|
+
doc = RubySpeech::SSML.draw { string "Hello world" }
|
278
|
+
subject.should_receive(:play_ssml).once.with(doc, {}).and_return true
|
279
|
+
subject.should_receive(:output).never
|
280
|
+
subject.speak(doc).should be true
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "with a string" do
|
285
|
+
it 'outputs the correct text' do
|
286
|
+
string = "Hello world"
|
287
|
+
subject.should_receive(:play_ssml).once.with(string, {})
|
288
|
+
subject.should_receive(:output).once.with(:text, string, {}).and_return true
|
289
|
+
subject.speak(string).should be true
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
describe "#ssml_for" do
|
295
|
+
let(:prompt) { "Please stand by" }
|
296
|
+
|
297
|
+
let(:ssml) do
|
298
|
+
RubySpeech::SSML.draw do
|
299
|
+
string 'Please stand by'
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'returns SSML for a text argument' do
|
304
|
+
subject.ssml_for(prompt).should == ssml
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'returns the same SSML passed in if it is SSML' do
|
308
|
+
subject.ssml_for(ssml) == ssml
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
describe "#detect_type" do
|
313
|
+
it "detects an HTTP path" do
|
314
|
+
http_path = "http://adhearsion.com/sounds/hello.mp3"
|
315
|
+
subject.detect_type(http_path).should be :audio
|
316
|
+
end
|
317
|
+
|
318
|
+
it "detects a file path" do
|
319
|
+
http_path = "/usr/shared/sounds/hello.mp3"
|
320
|
+
subject.detect_type(http_path).should be :audio
|
321
|
+
end
|
322
|
+
|
323
|
+
it "detects a Date object" do
|
324
|
+
today = Date.today
|
325
|
+
subject.detect_type(today).should be :time
|
326
|
+
end
|
327
|
+
|
328
|
+
it "detects a Time object" do
|
329
|
+
now = Time.now
|
330
|
+
subject.detect_type(now).should be :time
|
331
|
+
end
|
332
|
+
|
333
|
+
it "detects a DateTime object" do
|
334
|
+
today = DateTime.now
|
335
|
+
subject.detect_type(today).should be :time
|
336
|
+
end
|
337
|
+
|
338
|
+
it "detects a Numeric object" do
|
339
|
+
number = 123
|
340
|
+
subject.detect_type(number).should be :numeric
|
341
|
+
end
|
342
|
+
|
343
|
+
it "returns text as a fallback" do
|
344
|
+
output = "Hello"
|
345
|
+
subject.detect_type(output).should be :text
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
describe "#stream_file" do
|
350
|
+
let(:allowed_digits) { '35' }
|
351
|
+
let(:prompt) { "Press 3 or 5 to make something happen." }
|
352
|
+
|
353
|
+
let(:ssml) {
|
354
|
+
RubySpeech::SSML.draw do
|
355
|
+
string "Press 3 or 5 to make something happen."
|
356
|
+
end
|
357
|
+
}
|
358
|
+
|
359
|
+
let(:grammar) {
|
360
|
+
RubySpeech::GRXML.draw :mode => 'dtmf', :root => 'acceptdigits' do
|
361
|
+
rule id: 'acceptdigits' do
|
362
|
+
one_of do
|
363
|
+
allowed_digits.each { |d| item { d.to_s } }
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
}
|
368
|
+
|
369
|
+
let(:output_component) {
|
370
|
+
Punchblock::Component::Output.new :ssml => ssml.to_s
|
371
|
+
}
|
372
|
+
|
373
|
+
let(:input_component) {
|
374
|
+
Punchblock::Component::Input.new :mode => :dtmf,
|
375
|
+
:grammar => { :value => grammar.to_s }
|
376
|
+
}
|
377
|
+
|
378
|
+
#test does pass and method works, but not sure if the empty method is a good idea
|
379
|
+
it "plays the correct output" do
|
380
|
+
def subject.write_and_await_response(input_component)
|
381
|
+
# it is actually a no-op here
|
382
|
+
end
|
383
|
+
|
384
|
+
def expect_component_complete_event
|
385
|
+
complete_event = Punchblock::Event::Complete.new
|
386
|
+
flexmock(complete_event).should_receive(:reason => flexmock(:interpretation => 'dtmf-5', :name => :input))
|
387
|
+
flexmock(Punchblock::Component::Input).new_instances do |input|
|
388
|
+
input.should_receive(:complete?).and_return(false)
|
389
|
+
input.should_receive(:complete_event).and_return(complete_event)
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
expect_component_complete_event
|
394
|
+
expect_component_execution Punchblock::Component::Output.new(:ssml => ssml.to_s)
|
395
|
+
subject.stream_file prompt, allowed_digits
|
396
|
+
end
|
397
|
+
|
398
|
+
it "returns a single digit amongst the allowed when pressed" do
|
399
|
+
flexmock(Punchblock::Event::Complete).new_instances.should_receive(:reason => flexmock(:interpretation => 'dtmf-5', :name => :input))
|
400
|
+
|
401
|
+
def subject.write_and_await_response(input_component)
|
402
|
+
input_component.trigger_event_handler Punchblock::Event::Complete.new
|
403
|
+
end
|
404
|
+
|
405
|
+
def expect_component_complete_event
|
406
|
+
complete_event = Punchblock::Event::Complete.new
|
407
|
+
flexmock(complete_event).should_receive(:reason => flexmock(:interpretation => 'dtmf-5', :name => :input))
|
408
|
+
flexmock(Punchblock::Component::Input).new_instances do |input|
|
409
|
+
input.should_receive(:complete?).and_return(false)
|
410
|
+
input.should_receive(:complete_event).and_return(complete_event)
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
expect_component_complete_event
|
415
|
+
flexmock(Punchblock::Component::Output).new_instances.should_receive(:stop!)
|
416
|
+
subject.should_receive(:execute_component_and_await_completion).once.with(output_component)
|
417
|
+
subject.stream_file(prompt, allowed_digits).should == '5'
|
418
|
+
end
|
419
|
+
end # describe #stream_file
|
420
|
+
|
421
|
+
|
422
|
+
describe "#interruptible_play!" do
|
423
|
+
let(:output1) { "one two" }
|
424
|
+
let(:output2) { "three four" }
|
425
|
+
let(:non_existing) { "http://adhearsion.com/nonexistingfile.mp3" }
|
426
|
+
|
427
|
+
it "plays two outputs in succession" do
|
428
|
+
subject.should_receive(:stream_file).twice
|
429
|
+
subject.interruptible_play! output1, output2
|
430
|
+
end
|
431
|
+
|
432
|
+
it "stops at the first play when input is received" do
|
433
|
+
subject.should_receive(:stream_file).once.and_return(2)
|
434
|
+
subject.interruptible_play! output1, output2
|
435
|
+
end
|
436
|
+
|
437
|
+
it 'raises an exception when output is unsuccessful' do
|
438
|
+
subject.should_receive(:stream_file).once.and_raise PlaybackError, "Output failed"
|
439
|
+
expect { subject.interruptible_play!(non_existing) }.to raise_error(Adhearsion::PlaybackError)
|
440
|
+
end
|
441
|
+
end # describe interruptible_play!
|
442
|
+
|
443
|
+
describe "#interruptible_play" do
|
444
|
+
let(:output1) { "one two" }
|
445
|
+
let(:output2) { "three four" }
|
446
|
+
let(:non_existing) { "http://adhearsion.com/nonexistingfile.mp3" }
|
447
|
+
|
448
|
+
it "plays two outputs in succession" do
|
449
|
+
subject.should_receive(:interruptible_play!).twice
|
450
|
+
subject.interruptible_play output1, output2
|
451
|
+
end
|
452
|
+
|
453
|
+
it "stops at the first play when input is received" do
|
454
|
+
subject.should_receive(:interruptible_play!).once.and_return(2)
|
455
|
+
subject.interruptible_play output1, output2
|
456
|
+
end
|
457
|
+
|
458
|
+
it "should not raise an exception when output is unsuccessful" do
|
459
|
+
subject.should_receive(:stream_file).once.and_raise PlaybackError, "Output failed"
|
460
|
+
lambda { subject.interruptible_play non_existing }.should_not raise_error(Adhearsion::PlaybackError)
|
461
|
+
end
|
462
|
+
end # describe interruptible_play
|
463
|
+
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|