adhearsion 2.0.0.beta1 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -4
- data/CHANGELOG.md +34 -4
- data/README.markdown +2 -1
- data/Rakefile +22 -1
- data/adhearsion.gemspec +1 -0
- data/bin/ahn +0 -2
- data/features/cli_daemon.feature +2 -0
- data/features/cli_restart.feature +19 -0
- data/features/cli_start.feature +4 -6
- data/features/cli_stop.feature +3 -0
- data/features/step_definitions/app_generator_steps.rb +2 -0
- data/features/step_definitions/cli_steps.rb +2 -0
- data/features/support/aruba_helper.rb +2 -0
- data/features/support/env.rb +8 -46
- data/features/support/utils.rb +2 -0
- data/lib/adhearsion.rb +4 -6
- data/lib/adhearsion/call.rb +71 -17
- data/lib/adhearsion/call_controller.rb +25 -14
- data/lib/adhearsion/call_controller/dial.rb +34 -15
- data/lib/adhearsion/call_controller/input.rb +186 -144
- data/lib/adhearsion/call_controller/output.rb +10 -6
- data/lib/adhearsion/call_controller/record.rb +11 -13
- data/lib/adhearsion/call_controller/utility.rb +2 -0
- data/lib/adhearsion/calls.rb +4 -2
- data/lib/adhearsion/cli.rb +4 -0
- data/lib/adhearsion/cli_commands.rb +8 -2
- data/lib/adhearsion/configuration.rb +7 -3
- data/lib/adhearsion/console.rb +17 -17
- data/lib/adhearsion/events.rb +10 -4
- data/lib/adhearsion/foundation.rb +9 -0
- data/lib/adhearsion/foundation/custom_daemonizer.rb +3 -1
- data/lib/adhearsion/foundation/exception_handler.rb +2 -0
- data/lib/adhearsion/foundation/libc.rb +2 -0
- data/lib/adhearsion/foundation/object.rb +3 -0
- data/lib/adhearsion/foundation/thread_safety.rb +5 -11
- data/lib/adhearsion/generators.rb +2 -0
- data/lib/adhearsion/generators/app/app_generator.rb +2 -0
- data/lib/adhearsion/generators/app/templates/README.md +9 -0
- data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +38 -16
- data/lib/adhearsion/generators/app/templates/config/environment.rb +2 -0
- data/lib/adhearsion/generators/app/templates/lib/simon_game.rb +5 -3
- data/lib/adhearsion/generators/controller/controller_generator.rb +2 -0
- data/lib/adhearsion/generators/controller/templates/lib/controller.rb +2 -0
- data/lib/adhearsion/generators/controller/templates/spec/controller_spec.rb +2 -0
- data/lib/adhearsion/generators/generator.rb +3 -1
- data/lib/adhearsion/generators/plugin/plugin_generator.rb +2 -0
- data/lib/adhearsion/initializer.rb +31 -17
- data/lib/adhearsion/linux_proc_name.rb +2 -0
- data/lib/adhearsion/logging.rb +5 -3
- data/lib/adhearsion/menu_dsl.rb +2 -0
- data/lib/adhearsion/menu_dsl/calculated_match.rb +2 -0
- data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +2 -0
- data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +2 -0
- data/lib/adhearsion/menu_dsl/match_calculator.rb +2 -0
- data/lib/adhearsion/menu_dsl/menu.rb +58 -4
- data/lib/adhearsion/menu_dsl/menu_builder.rb +14 -1
- data/lib/adhearsion/menu_dsl/range_match_calculator.rb +4 -1
- data/lib/adhearsion/menu_dsl/string_match_calculator.rb +2 -0
- data/lib/adhearsion/outbound_call.rb +2 -0
- data/lib/adhearsion/plugin.rb +9 -7
- data/lib/adhearsion/plugin/collection.rb +3 -1
- data/lib/adhearsion/plugin/initializer.rb +3 -1
- data/lib/adhearsion/process.rb +8 -2
- data/lib/adhearsion/punchblock_plugin.rb +3 -1
- data/lib/adhearsion/punchblock_plugin/initializer.rb +34 -11
- data/lib/adhearsion/router.rb +4 -2
- data/lib/adhearsion/router/route.rb +2 -0
- data/lib/adhearsion/script_ahn_loader.rb +2 -0
- data/lib/adhearsion/tasks.rb +2 -0
- data/lib/adhearsion/tasks/configuration.rb +2 -0
- data/lib/adhearsion/tasks/debugging.rb +8 -0
- data/lib/adhearsion/tasks/environment.rb +2 -0
- data/lib/adhearsion/tasks/plugins.rb +2 -0
- data/lib/adhearsion/tasks/testing.rb +2 -0
- data/lib/adhearsion/version.rb +3 -1
- data/pre-commit +2 -0
- data/spec/adhearsion/call_controller/dial_spec.rb +114 -25
- data/spec/adhearsion/call_controller/input_spec.rb +192 -169
- data/spec/adhearsion/call_controller/output_spec.rb +26 -12
- data/spec/adhearsion/call_controller/record_spec.rb +29 -77
- data/spec/adhearsion/call_controller/utility_spec.rb +69 -0
- data/spec/adhearsion/call_controller_spec.rb +90 -15
- data/spec/adhearsion/call_spec.rb +92 -24
- data/spec/adhearsion/calls_spec.rb +9 -7
- data/spec/adhearsion/configuration_spec.rb +58 -56
- data/spec/adhearsion/console_spec.rb +4 -2
- data/spec/adhearsion/events_spec.rb +9 -7
- data/spec/adhearsion/generators_spec.rb +3 -1
- data/spec/adhearsion/initializer_spec.rb +16 -14
- data/spec/adhearsion/logging_spec.rb +11 -9
- data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +6 -4
- data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +6 -4
- data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +3 -1
- data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +2 -0
- data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +42 -11
- data/spec/adhearsion/menu_dsl/menu_spec.rb +197 -36
- data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +4 -2
- data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +5 -3
- data/spec/adhearsion/outbound_call_spec.rb +7 -5
- data/spec/adhearsion/plugin_spec.rb +19 -15
- data/spec/adhearsion/process_spec.rb +12 -7
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +35 -15
- data/spec/adhearsion/punchblock_plugin_spec.rb +4 -1
- data/spec/adhearsion/router/route_spec.rb +8 -6
- data/spec/adhearsion/router_spec.rb +12 -10
- data/spec/adhearsion_spec.rb +13 -2
- data/spec/capture_warnings.rb +33 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/call_controller_test_helpers.rb +2 -4
- data/spec/support/initializer_stubs.rb +8 -5
- data/spec/support/logging_helpers.rb +2 -0
- data/spec/support/punchblock_mocks.rb +2 -0
- metadata +84 -71
- data/EVENTS +0 -11
- data/lib/adhearsion/call_controller/menu.rb +0 -124
- data/lib/adhearsion/foundation/all.rb +0 -8
- data/spec/adhearsion/call_controller/menu_spec.rb +0 -120
- data/spec/adhearsion/menu_dsl_spec.rb +0 -12
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Adhearsion
|
@@ -5,63 +7,33 @@ module Adhearsion
|
|
5
7
|
describe Input do
|
6
8
|
include CallControllerTestHelpers
|
7
9
|
|
8
|
-
describe "#
|
9
|
-
let(:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
one_of do
|
14
|
-
0.upto(9) { |d| item { d.to_s } }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
}
|
10
|
+
describe "#play_sound_files_for_menu" do
|
11
|
+
let(:options) { Hash.new }
|
12
|
+
let(:menu_instance) { Adhearsion::MenuDSL::Menu.new(options) }
|
13
|
+
let(:sound_file) { "press a button" }
|
14
|
+
let(:sound_files) { [sound_file] }
|
20
15
|
|
21
|
-
it
|
22
|
-
subject.
|
16
|
+
it "should play the sound files for the menu" do
|
17
|
+
subject.should_receive(:interruptible_play).with(sound_file).and_return("1")
|
18
|
+
subject.play_sound_files_for_menu(menu_instance, sound_files).should be == '1'
|
23
19
|
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
RubySpeech::GRXML.draw :mode => 'dtmf', :root => 'inputdigits' do
|
30
|
-
rule id: 'inputdigits', scope: 'public' do
|
31
|
-
one_of do
|
32
|
-
item { '3' }
|
33
|
-
item { '5' }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
}
|
38
|
-
|
39
|
-
it 'generates the correct GRXML grammar' do
|
40
|
-
subject.grammar_accept('35').to_s.should == grxml.to_s
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'filters meaningless characters out' do
|
44
|
-
subject.grammar_accept('3+5').to_s.should == grxml.to_s
|
45
|
-
end
|
46
|
-
end # grammar_accept
|
47
|
-
|
48
|
-
describe "#parse_single_dtmf" do
|
49
|
-
it "correctly returns the parsed input" do
|
50
|
-
subject.parse_single_dtmf("dtmf-3").should == '3'
|
51
|
-
end
|
52
|
-
|
53
|
-
it "correctly returns star as *" do
|
54
|
-
subject.parse_single_dtmf("dtmf-star").should == '*'
|
21
|
+
it "should wait for digit if nothing is pressed during playback" do
|
22
|
+
subject.should_receive(:interruptible_play).with(sound_file).and_return(nil)
|
23
|
+
subject.should_receive(:wait_for_digit).with(menu_instance.timeout).and_return("1")
|
24
|
+
subject.play_sound_files_for_menu(menu_instance, sound_files).should be == '1'
|
55
25
|
end
|
56
26
|
|
57
|
-
|
58
|
-
|
59
|
-
end
|
27
|
+
context "when the menu is not interruptible" do
|
28
|
+
let(:options) { { :interruptible => false } }
|
60
29
|
|
61
|
-
|
62
|
-
|
30
|
+
it "should play the sound files and wait for digit" do
|
31
|
+
subject.should_receive(:play).with(sound_file).and_return true
|
32
|
+
subject.should_receive(:wait_for_digit).with(menu_instance.timeout).and_return("1")
|
33
|
+
subject.play_sound_files_for_menu(menu_instance, sound_files).should be == '1'
|
34
|
+
end
|
63
35
|
end
|
64
|
-
end
|
36
|
+
end#play_sound_files_for_menu
|
65
37
|
|
66
38
|
describe "#wait_for_digit" do
|
67
39
|
let(:timeout) { 2 }
|
@@ -109,7 +81,7 @@ module Adhearsion
|
|
109
81
|
it "returns the correct pressed digit" do
|
110
82
|
expect_component_complete_event
|
111
83
|
subject.should_receive(:execute_component_and_await_completion).once.with(Punchblock::Component::Input).and_return input_component
|
112
|
-
subject.wait_for_digit(timeout).should == '5'
|
84
|
+
subject.wait_for_digit(timeout).should be == '5'
|
113
85
|
end
|
114
86
|
|
115
87
|
context "with a nil timeout" do
|
@@ -124,155 +96,206 @@ module Adhearsion
|
|
124
96
|
end
|
125
97
|
end # wait_for_digit
|
126
98
|
|
127
|
-
describe "#
|
128
|
-
|
129
|
-
|
99
|
+
describe "#jump_to" do
|
100
|
+
let(:match_object) { flexmock(Class.new) }
|
101
|
+
let(:overrides) { Hash.new(:extension => "1") }
|
102
|
+
let(:block) { Proc.new {} }
|
130
103
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
104
|
+
it "calls instance_exec if the match object has a block" do
|
105
|
+
match_object.should_receive(:block).and_return(block)
|
106
|
+
subject.should_receive(:instance_exec).with(overrides[:extension], block)
|
107
|
+
subject.jump_to(match_object, overrides)
|
108
|
+
end
|
136
109
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
110
|
+
it "calls invoke if the match object does not have a block" do
|
111
|
+
match_object.should_receive(:block).and_return(false)
|
112
|
+
match_object.should_receive(:match_payload).and_return(:payload)
|
113
|
+
subject.should_receive(:invoke).with(:payload, overrides)
|
114
|
+
subject.jump_to(match_object, overrides)
|
115
|
+
end
|
116
|
+
end#jump_to
|
141
117
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
118
|
+
describe "#menu" do
|
119
|
+
let(:sound_files) { ["press", "button"] }
|
120
|
+
|
121
|
+
let(:menu_instance) do
|
122
|
+
MenuDSL::Menu.new { match(1) {} }
|
146
123
|
end
|
147
124
|
|
148
|
-
|
149
|
-
|
125
|
+
let(:result_done) { MenuDSL::Menu::MenuResultDone.new }
|
126
|
+
let(:result_terminated) { MenuDSL::Menu::MenuTerminated.new }
|
127
|
+
let(:result_limit_reached) { MenuDSL::Menu::MenuLimitReached.new }
|
128
|
+
let(:result_invalid) { MenuDSL::Menu::MenuResultInvalid.new }
|
129
|
+
let(:result_get_another_or_timeout) { MenuDSL::Menu::MenuGetAnotherDigitOrTimeout.new }
|
130
|
+
let(:result_get_another_or_finish) { MenuDSL::Menu::MenuGetAnotherDigitOrFinish.new(:match_object, :new_extension) }
|
131
|
+
let(:result_found) { MenuDSL::Menu::MenuResultFound.new(:match_object, :new_extension) }
|
150
132
|
|
151
|
-
|
152
|
-
|
153
|
-
subject.should_receive(:wait_for_digit).once.with(nil).and_return('#')
|
154
|
-
subject.input!.should == '1'
|
155
|
-
end
|
133
|
+
let(:status) { :foo }
|
134
|
+
let(:response) { '1234' }
|
156
135
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
subject.input!(:terminator => terminator).should == '1'
|
161
|
-
end
|
136
|
+
before do
|
137
|
+
flexmock menu_instance, :status => status, :result => response
|
138
|
+
flexmock(MenuDSL::Menu).should_receive(:new).and_return(menu_instance)
|
162
139
|
end
|
163
140
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
end
|
141
|
+
it "exits the function if MenuResultDone" do
|
142
|
+
menu_instance.should_receive(:should_continue?).and_return(true)
|
143
|
+
menu_instance.should_receive(:continue).and_return(result_done)
|
144
|
+
result = subject.menu sound_files
|
145
|
+
result.menu.should be menu_instance
|
146
|
+
result.response.should be response
|
171
147
|
end
|
172
148
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
it "plays a string argument" do
|
181
|
-
subject.should_receive(:interruptible_play!).with(string_play)
|
182
|
-
subject.should_receive(:wait_for_digit).once.with(nil).and_return('#')
|
183
|
-
subject.input! :play => string_play
|
184
|
-
end
|
149
|
+
it "exits the function if MenuTerminated" do
|
150
|
+
menu_instance.should_receive(:should_continue?).and_return(true)
|
151
|
+
menu_instance.should_receive(:continue).and_return(result_terminated)
|
152
|
+
result = subject.menu sound_files
|
153
|
+
result.menu.should be menu_instance
|
154
|
+
result.response.should be response
|
155
|
+
end
|
185
156
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
157
|
+
it "exits the function if MenuLimitReached" do
|
158
|
+
menu_instance.should_receive(:should_continue?).and_return(true)
|
159
|
+
menu_instance.should_receive(:continue).and_return(result_limit_reached)
|
160
|
+
result = subject.menu sound_files
|
161
|
+
result.menu.should be menu_instance
|
162
|
+
result.response.should be response
|
163
|
+
end
|
191
164
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
165
|
+
it "executes failure hook and returns :failure if menu fails" do
|
166
|
+
menu_instance.should_receive(:should_continue?).and_return(false)
|
167
|
+
menu_instance.should_receive(:execute_failure_hook)
|
168
|
+
result = subject.menu sound_files
|
169
|
+
result.menu.should be menu_instance
|
170
|
+
result.response.should be response
|
171
|
+
end
|
197
172
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
173
|
+
it "executes invalid hook if input is invalid" do
|
174
|
+
menu_instance.should_receive(:should_continue?).twice.and_return(true)
|
175
|
+
menu_instance.should_receive(:continue).and_return(result_invalid, result_done)
|
176
|
+
menu_instance.should_receive(:execute_invalid_hook)
|
177
|
+
menu_instance.should_receive(:restart!)
|
178
|
+
result = subject.menu sound_files
|
179
|
+
result.menu.should be menu_instance
|
180
|
+
result.response.should be response
|
181
|
+
end
|
205
182
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
183
|
+
it "plays audio, then executes timeout hook if input times out" do
|
184
|
+
menu_instance.should_receive(:should_continue?).twice.and_return(true)
|
185
|
+
menu_instance.should_receive(:continue).and_return(result_get_another_or_timeout, result_done)
|
186
|
+
subject.should_receive(:play_sound_files_for_menu).with(menu_instance, sound_files).and_return(nil)
|
187
|
+
menu_instance.should_receive(:execute_timeout_hook)
|
188
|
+
menu_instance.should_receive(:restart!)
|
189
|
+
subject.menu sound_files
|
190
|
+
end
|
210
191
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
192
|
+
it "plays audio, then adds digit to digit buffer if input is received" do
|
193
|
+
menu_instance.should_receive(:should_continue?).twice.and_return(true)
|
194
|
+
menu_instance.should_receive(:continue).and_return(result_get_another_or_timeout, result_done)
|
195
|
+
subject.should_receive(:play_sound_files_for_menu).with(menu_instance, sound_files).and_return("1")
|
196
|
+
menu_instance.should_receive(:<<).with("1")
|
197
|
+
subject.menu sound_files
|
198
|
+
end
|
216
199
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
200
|
+
it "plays audio, then jumps to payload when input is finished" do
|
201
|
+
menu_instance.should_receive(:should_continue?).and_return(true)
|
202
|
+
menu_instance.should_receive(:continue).and_return(result_get_another_or_finish)
|
203
|
+
subject.should_receive(:play_sound_files_for_menu).with(menu_instance, sound_files).and_return(nil)
|
204
|
+
subject.should_receive(:jump_to).with(:match_object, :extension => :new_extension)
|
205
|
+
subject.menu sound_files
|
206
|
+
end
|
223
207
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
208
|
+
it "jumps to payload when result is found" do
|
209
|
+
menu_instance.should_receive(:should_continue?).and_return(true)
|
210
|
+
menu_instance.should_receive(:continue).and_return(result_found)
|
211
|
+
subject.should_receive(:jump_to).with(:match_object, :extension => :new_extension)
|
212
|
+
result = subject.menu sound_files
|
213
|
+
result.menu.should be menu_instance
|
214
|
+
result.response.should be response
|
215
|
+
end
|
230
216
|
|
231
|
-
|
232
|
-
|
217
|
+
context "if a digit limit is specified" do
|
218
|
+
it "should raise an ArgumentError"
|
219
|
+
end
|
233
220
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
221
|
+
context "if a terminator digit is specified" do
|
222
|
+
it "should raise an ArgumentError"
|
223
|
+
end
|
224
|
+
|
225
|
+
end#describe
|
226
|
+
|
227
|
+
describe "#ask" do
|
228
|
+
let(:sound_files) { ["press", "button"] }
|
229
|
+
|
230
|
+
context "mocking out the menu" do
|
231
|
+
let(:menu_instance) { MenuDSL::Menu.new :limit => 2 }
|
232
|
+
|
233
|
+
let(:result_done) { MenuDSL::Menu::MenuResultDone.new }
|
234
|
+
let(:result_terminated) { MenuDSL::Menu::MenuTerminated.new }
|
235
|
+
let(:result_limit_reached) { MenuDSL::Menu::MenuLimitReached.new }
|
236
|
+
let(:result_invalid) { MenuDSL::Menu::MenuResultInvalid.new }
|
237
|
+
let(:result_get_another_or_timeout) { MenuDSL::Menu::MenuGetAnotherDigitOrTimeout.new }
|
238
|
+
let(:result_get_another_or_finish) { MenuDSL::Menu::MenuGetAnotherDigitOrFinish.new(:match_object, :new_extension) }
|
239
|
+
let(:result_found) { MenuDSL::Menu::MenuResultFound.new(:match_object, :new_extension) }
|
239
240
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
241
|
+
let(:status) { :foo }
|
242
|
+
let(:response) { '1234' }
|
243
|
+
|
244
|
+
before do
|
245
|
+
flexmock menu_instance, :status => status, :result => response
|
246
|
+
flexmock(MenuDSL::Menu).should_receive(:new).and_return(menu_instance)
|
245
247
|
end
|
246
|
-
end # describe non interruptible play
|
247
248
|
|
248
|
-
|
249
|
-
|
249
|
+
it "exits the function if MenuResultDone" do
|
250
|
+
menu_instance.should_receive(:continue).and_return(result_done)
|
251
|
+
result = subject.ask sound_files
|
252
|
+
result.menu.should be menu_instance
|
253
|
+
result.response.should be response
|
254
|
+
end
|
250
255
|
|
251
|
-
it "
|
252
|
-
|
253
|
-
subject.
|
256
|
+
it "exits the function if MenuTerminated" do
|
257
|
+
menu_instance.should_receive(:continue).and_return(result_terminated)
|
258
|
+
result = subject.ask sound_files
|
259
|
+
result.menu.should be menu_instance
|
260
|
+
result.response.should be response
|
254
261
|
end
|
255
262
|
|
256
|
-
it "
|
257
|
-
|
258
|
-
subject.
|
259
|
-
|
263
|
+
it "exits the function if MenuLimitReached" do
|
264
|
+
menu_instance.should_receive(:continue).and_return(result_limit_reached)
|
265
|
+
result = subject.ask sound_files
|
266
|
+
result.menu.should be menu_instance
|
267
|
+
result.response.should be response
|
260
268
|
end
|
261
|
-
end
|
262
269
|
|
263
|
-
|
264
|
-
|
270
|
+
it "plays audio, then executes timeout hook if input times out" do
|
271
|
+
menu_instance.should_receive(:continue).and_return(result_get_another_or_timeout, result_done)
|
272
|
+
subject.should_receive(:play_sound_files_for_menu).with(menu_instance, sound_files).and_return(nil)
|
273
|
+
menu_instance.should_receive(:execute_timeout_hook)
|
274
|
+
menu_instance.should_receive(:restart!)
|
275
|
+
subject.ask sound_files
|
276
|
+
end
|
265
277
|
|
266
|
-
|
267
|
-
|
278
|
+
it "plays audio, then adds digit to digit buffer if input is received" do
|
279
|
+
menu_instance.should_receive(:continue).and_return(result_get_another_or_timeout, result_done)
|
280
|
+
subject.should_receive(:play_sound_files_for_menu).with(menu_instance, sound_files).and_return("1")
|
281
|
+
menu_instance.should_receive(:<<).with("1")
|
282
|
+
subject.ask sound_files
|
283
|
+
end
|
284
|
+
end
|
268
285
|
|
269
|
-
|
270
|
-
|
271
|
-
|
286
|
+
context "with a block passed" do
|
287
|
+
it "should set that block as the buffer validator" do
|
288
|
+
foo = nil
|
289
|
+
subject.should_receive(:play_sound_files_for_menu).and_return("1")
|
290
|
+
subject.ask sound_files, :limit => 0 do |buffer|
|
291
|
+
foo = :bar
|
292
|
+
end.menu.execute_validator_hook
|
293
|
+
foo.should be == :bar
|
294
|
+
end
|
272
295
|
end
|
273
296
|
|
274
|
-
|
275
|
-
|
276
|
-
end
|
297
|
+
end#describe
|
298
|
+
|
299
|
+
end#shared
|
277
300
|
end
|
278
301
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Adhearsion
|
@@ -267,17 +269,23 @@ module Adhearsion
|
|
267
269
|
|
268
270
|
it "raises an exception if play fails" do
|
269
271
|
subject.should_receive(:play).once.and_return false
|
270
|
-
expect { subject.play!(non_existing) }.to raise_error(
|
272
|
+
expect { subject.play!(non_existing) }.to raise_error(Output::PlaybackError)
|
271
273
|
end
|
272
274
|
end
|
273
275
|
|
274
276
|
describe "#speak" do
|
277
|
+
it "should be an alias for #say" do
|
278
|
+
subject.method(:speak).should be == subject.method(:say)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe "#say" do
|
275
283
|
describe "with a RubySpeech document" do
|
276
284
|
it 'plays the correct SSML' do
|
277
285
|
doc = RubySpeech::SSML.draw { string "Hello world" }
|
278
286
|
subject.should_receive(:play_ssml).once.with(doc, {}).and_return true
|
279
287
|
subject.should_receive(:output).never
|
280
|
-
subject.
|
288
|
+
subject.say(doc).should be true
|
281
289
|
end
|
282
290
|
end
|
283
291
|
|
@@ -286,7 +294,7 @@ module Adhearsion
|
|
286
294
|
string = "Hello world"
|
287
295
|
subject.should_receive(:play_ssml).once.with(string, {})
|
288
296
|
subject.should_receive(:output).once.with(:text, string, {}).and_return true
|
289
|
-
subject.
|
297
|
+
subject.say(string).should be true
|
290
298
|
end
|
291
299
|
end
|
292
300
|
|
@@ -296,7 +304,7 @@ module Adhearsion
|
|
296
304
|
argument = 123
|
297
305
|
subject.should_receive(:play_ssml).once.with(argument, {})
|
298
306
|
subject.should_receive(:output).once.with(:text, expected_string, {}).and_return true
|
299
|
-
subject.
|
307
|
+
subject.say(argument)
|
300
308
|
end
|
301
309
|
end
|
302
310
|
end
|
@@ -311,7 +319,7 @@ module Adhearsion
|
|
311
319
|
end
|
312
320
|
|
313
321
|
it 'returns SSML for a text argument' do
|
314
|
-
subject.ssml_for(prompt).should == ssml
|
322
|
+
subject.ssml_for(prompt).should be == ssml
|
315
323
|
end
|
316
324
|
|
317
325
|
it 'returns the same SSML passed in if it is SSML' do
|
@@ -326,8 +334,14 @@ module Adhearsion
|
|
326
334
|
end
|
327
335
|
|
328
336
|
it "detects a file path" do
|
329
|
-
|
330
|
-
subject.detect_type(
|
337
|
+
file_path = "file:///usr/shared/sounds/hello.mp3"
|
338
|
+
subject.detect_type(file_path).should be :audio
|
339
|
+
|
340
|
+
absolute_path = "/usr/shared/sounds/hello.mp3"
|
341
|
+
subject.detect_type(absolute_path).should be :audio
|
342
|
+
|
343
|
+
relative_path = "foo/bar"
|
344
|
+
subject.detect_type(relative_path).should_not be :audio
|
331
345
|
end
|
332
346
|
|
333
347
|
it "detects a Date object" do
|
@@ -424,7 +438,7 @@ module Adhearsion
|
|
424
438
|
expect_component_complete_event
|
425
439
|
flexmock(Punchblock::Component::Output).new_instances.should_receive(:stop!)
|
426
440
|
subject.should_receive(:execute_component_and_await_completion).once.with(output_component)
|
427
|
-
subject.stream_file(prompt, allowed_digits).should == '5'
|
441
|
+
subject.stream_file(prompt, allowed_digits).should be == '5'
|
428
442
|
end
|
429
443
|
end # describe #stream_file
|
430
444
|
|
@@ -445,8 +459,8 @@ module Adhearsion
|
|
445
459
|
end
|
446
460
|
|
447
461
|
it 'raises an exception when output is unsuccessful' do
|
448
|
-
subject.should_receive(:stream_file).once.and_raise PlaybackError, "Output failed"
|
449
|
-
expect { subject.interruptible_play!(non_existing) }.to raise_error(
|
462
|
+
subject.should_receive(:stream_file).once.and_raise Output::PlaybackError, "Output failed"
|
463
|
+
expect { subject.interruptible_play!(non_existing) }.to raise_error(Output::PlaybackError)
|
450
464
|
end
|
451
465
|
end # describe interruptible_play!
|
452
466
|
|
@@ -466,8 +480,8 @@ module Adhearsion
|
|
466
480
|
end
|
467
481
|
|
468
482
|
it "should not raise an exception when output is unsuccessful" do
|
469
|
-
subject.should_receive(:stream_file).once.and_raise PlaybackError, "Output failed"
|
470
|
-
lambda { subject.interruptible_play non_existing }.should_not raise_error(
|
483
|
+
subject.should_receive(:stream_file).once.and_raise Output::PlaybackError, "Output failed"
|
484
|
+
lambda { subject.interruptible_play non_existing }.should_not raise_error(Output::PlaybackError)
|
471
485
|
end
|
472
486
|
end # describe interruptible_play
|
473
487
|
|