adzap-voice_form 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +7 -0
- data/README.markdown +74 -32
- data/Rakefile +1 -1
- data/examples/my_component.rb +12 -8
- data/examples/simon_game_voice_form.rb +47 -0
- data/lib/voice_form/form.rb +22 -14
- data/lib/voice_form/form_field.rb +81 -56
- data/lib/voice_form/form_methods.rb +15 -9
- data/spec/form_field_spec.rb +92 -61
- data/spec/form_spec.rb +108 -89
- metadata +3 -4
@@ -1,13 +1,13 @@
|
|
1
1
|
module VoiceForm
|
2
2
|
|
3
3
|
def self.included(base)
|
4
|
-
base.extend
|
4
|
+
base.extend ClassMethods
|
5
5
|
base.class_eval do
|
6
6
|
include FormMethods
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
module
|
10
|
+
module ClassMethods
|
11
11
|
|
12
12
|
def voice_form(options={}, &block)
|
13
13
|
raise "Voice form requires block" unless block_given?
|
@@ -16,24 +16,32 @@ module VoiceForm
|
|
16
16
|
include InstanceMethods
|
17
17
|
|
18
18
|
cattr_accessor :voice_form_options
|
19
|
-
attr_accessor :form, :
|
19
|
+
attr_accessor :form, :call
|
20
20
|
end
|
21
21
|
|
22
22
|
self.voice_form_options = [options, block]
|
23
23
|
end
|
24
|
+
|
25
|
+
def start_voice_form(call)
|
26
|
+
raise "No voice form defined" unless voice_form_options
|
27
|
+
self.new.start_voice_form(call)
|
28
|
+
end
|
24
29
|
|
25
30
|
end
|
26
31
|
|
27
32
|
module InstanceMethods
|
28
|
-
|
33
|
+
|
29
34
|
def start_voice_form(call)
|
30
|
-
raise "No voice form defined" unless self.voice_form_options
|
35
|
+
raise "No voice form defined" unless self.class.voice_form_options
|
31
36
|
options, block = *self.class.voice_form_options
|
32
|
-
@
|
37
|
+
@call = call
|
33
38
|
self.form = VoiceForm::Form.new(options, &block)
|
34
39
|
self.form.run(self)
|
35
40
|
end
|
36
41
|
|
42
|
+
def as_digits(string)
|
43
|
+
string.scan(/\d/).map {|v| v.to_i }
|
44
|
+
end
|
37
45
|
end
|
38
46
|
|
39
47
|
module FormMethods
|
@@ -44,9 +52,7 @@ module VoiceForm
|
|
44
52
|
|
45
53
|
form_field = VoiceForm::FormField.new(field_name, options, self, &block)
|
46
54
|
|
47
|
-
|
48
|
-
|
49
|
-
if self.class == VoiceForm::Form
|
55
|
+
if self.is_a?(VoiceForm::Form)
|
50
56
|
self.form_stack << form_field
|
51
57
|
else
|
52
58
|
unless self.respond_to?(field_name)
|
data/spec/form_field_spec.rb
CHANGED
@@ -3,67 +3,67 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
3
3
|
describe VoiceForm::FormField do
|
4
4
|
include VoiceForm::FormMethods
|
5
5
|
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :call, :my_field
|
7
7
|
|
8
8
|
before do
|
9
|
-
@
|
10
|
-
@
|
9
|
+
@call = mock('Call', :play => nil, :speak => nil)
|
10
|
+
@call.stub!(:input).with(any_args).and_return('')
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should define accessor for field in component" do
|
14
14
|
field(:my_field) do
|
15
|
-
prompt :
|
15
|
+
prompt :play => 'test'
|
16
16
|
end
|
17
17
|
self.methods.include?(:my_field)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should raise error if no prompts defined" do
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
lambda {
|
22
|
+
form_field(:my_field) {}
|
23
|
+
}.should raise_error
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should raise error if reprompt defined before prompt" do
|
27
27
|
lambda {
|
28
28
|
form_field(:my_field) do
|
29
|
-
reprompt :
|
29
|
+
reprompt :play => 'again'
|
30
30
|
end
|
31
31
|
}.should raise_error
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should return same prompt for for all attempts if single prompt" do
|
35
35
|
item = form_field(:my_field) do
|
36
|
-
prompt :
|
36
|
+
prompt :play => "first"
|
37
37
|
end
|
38
|
-
item.send(:prompt_for_attempt, 1)[:
|
39
|
-
item.send(:prompt_for_attempt, 2)[:
|
38
|
+
item.send(:prompt_for_attempt, 1)[:message].should == 'first'
|
39
|
+
item.send(:prompt_for_attempt, 2)[:message].should == 'first'
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should return reprompt for subsequent prompts" do
|
43
43
|
item = form_field(:my_field) do
|
44
|
-
prompt :
|
45
|
-
reprompt :
|
44
|
+
prompt :play => "first"
|
45
|
+
reprompt :play => 'next'
|
46
46
|
end
|
47
|
-
item.send(:prompt_for_attempt, 1)[:
|
48
|
-
item.send(:prompt_for_attempt, 2)[:
|
49
|
-
item.send(:prompt_for_attempt, 3)[:
|
47
|
+
item.send(:prompt_for_attempt, 1)[:message].should == 'first'
|
48
|
+
item.send(:prompt_for_attempt, 2)[:message].should == 'next'
|
49
|
+
item.send(:prompt_for_attempt, 3)[:message].should == 'next'
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should return prompt for given number of repeats before subsequent prompts" do
|
53
53
|
item = form_field(:my_field) do
|
54
|
-
prompt :
|
55
|
-
reprompt :
|
54
|
+
prompt :play => "first", :repeats => 2
|
55
|
+
reprompt :play => 'next'
|
56
56
|
end
|
57
|
-
item.send(:prompt_for_attempt, 1)[:
|
58
|
-
item.send(:prompt_for_attempt, 2)[:
|
59
|
-
item.send(:prompt_for_attempt, 3)[:
|
57
|
+
item.send(:prompt_for_attempt, 1)[:message].should == 'first'
|
58
|
+
item.send(:prompt_for_attempt, 2)[:message].should == 'first'
|
59
|
+
item.send(:prompt_for_attempt, 3)[:message].should == 'next'
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should set input value in component" do
|
63
63
|
item = form_field(:my_field, :length => 3) do
|
64
|
-
prompt :
|
64
|
+
prompt :play => "first"
|
65
65
|
end
|
66
|
-
|
66
|
+
call.stub!(:input).and_return('123')
|
67
67
|
item.run
|
68
68
|
|
69
69
|
my_field.should == '123'
|
@@ -72,10 +72,10 @@ describe VoiceForm::FormField do
|
|
72
72
|
it "should run setup callback once" do
|
73
73
|
call_me = i_should_be_called
|
74
74
|
item = form_field(:my_field, :attempts => 3) do
|
75
|
-
prompt :
|
75
|
+
prompt :play => "first"
|
76
76
|
setup { call_me.call }
|
77
77
|
end
|
78
|
-
|
78
|
+
call.should_receive(:input).and_return('')
|
79
79
|
|
80
80
|
item.run
|
81
81
|
end
|
@@ -83,38 +83,49 @@ describe VoiceForm::FormField do
|
|
83
83
|
it "should run timeout callback if no input" do
|
84
84
|
call_me = i_should_be_called
|
85
85
|
item = form_field(:my_field, :attempts => 1) do
|
86
|
-
prompt :
|
86
|
+
prompt :play => "first"
|
87
87
|
timeout { call_me.call }
|
88
88
|
end
|
89
|
-
|
89
|
+
call.should_receive(:input).and_return('')
|
90
|
+
|
91
|
+
item.run
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should run timeout callback if input not valid length" do
|
95
|
+
call_me = i_should_be_called
|
96
|
+
item = form_field(:my_field, :attempts => 1, :length => 3) do
|
97
|
+
prompt :play => "first"
|
98
|
+
timeout { call_me.call }
|
99
|
+
end
|
100
|
+
call.should_receive(:input).and_return('12')
|
90
101
|
|
91
102
|
item.run
|
92
103
|
end
|
93
104
|
|
94
105
|
it "should make all attempts to get valid input" do
|
95
106
|
item = form_field(:my_field) do
|
96
|
-
prompt :
|
107
|
+
prompt :play => "first"
|
97
108
|
end
|
98
|
-
|
109
|
+
call.should_receive(:input).exactly(3).times
|
99
110
|
|
100
111
|
item.run
|
101
112
|
end
|
102
113
|
|
103
114
|
it "should make one attempt if input is valid" do
|
104
115
|
item = form_field(:my_field) do
|
105
|
-
prompt :
|
116
|
+
prompt :play => "first"
|
106
117
|
end
|
107
118
|
item.stub!(:input_valid?).and_return(true)
|
108
|
-
|
119
|
+
call.should_receive(:input).once
|
109
120
|
|
110
121
|
item.run
|
111
122
|
end
|
112
123
|
|
113
124
|
it "should check if input_valid?" do
|
114
125
|
item = form_field(:my_field, :length => 3) do
|
115
|
-
prompt :
|
126
|
+
prompt :play => "first"
|
116
127
|
end
|
117
|
-
|
128
|
+
call.should_receive(:input).and_return('123')
|
118
129
|
item.should_receive(:input_valid?)
|
119
130
|
|
120
131
|
item.run
|
@@ -123,10 +134,10 @@ describe VoiceForm::FormField do
|
|
123
134
|
it "should run validation callback if defined" do
|
124
135
|
call_me = i_should_be_called
|
125
136
|
item = form_field(:my_field, :length => 3, :attempts => 1) do
|
126
|
-
prompt :
|
137
|
+
prompt :play => "first"
|
127
138
|
validate { call_me.call }
|
128
139
|
end
|
129
|
-
|
140
|
+
call.stub!(:input).and_return('123')
|
130
141
|
|
131
142
|
item.run
|
132
143
|
end
|
@@ -134,10 +145,10 @@ describe VoiceForm::FormField do
|
|
134
145
|
it "should run confirm callback if defined" do
|
135
146
|
call_me = i_should_be_called
|
136
147
|
item = form_field(:my_field, :length => 3, :attempts => 1) do
|
137
|
-
prompt :
|
148
|
+
prompt :play => "first"
|
138
149
|
confirm { call_me.call; [] }
|
139
150
|
end
|
140
|
-
|
151
|
+
call.stub!(:input).and_return('123')
|
141
152
|
|
142
153
|
item.run
|
143
154
|
end
|
@@ -147,81 +158,81 @@ describe VoiceForm::FormField do
|
|
147
158
|
it "should not run if not valid input" do
|
148
159
|
dont_call_me = i_should_not_be_called
|
149
160
|
item = form_field(:my_field, :length => 3, :attempts => 1) do
|
150
|
-
prompt :
|
161
|
+
prompt :play => "first"
|
151
162
|
validate { false }
|
152
163
|
confirm { dont_call_me.call }
|
153
164
|
end
|
154
|
-
|
165
|
+
call.stub!(:input).and_return('123')
|
155
166
|
|
156
167
|
item.run
|
157
168
|
end
|
158
169
|
|
159
170
|
it "should be run the number of attempts if no valid response" do
|
160
|
-
|
171
|
+
call.should_receive(:input).with(3, anything).and_return('123')
|
161
172
|
item = form_field(:my_field, :length => 3, :attempts => 1) do
|
162
|
-
prompt :
|
173
|
+
prompt :play => "first"
|
163
174
|
|
164
175
|
confirm(:attempts => 3) { [] }
|
165
176
|
end
|
166
|
-
|
177
|
+
call.should_receive(:input).with(1, anything).exactly(3).times.and_return('')
|
167
178
|
|
168
179
|
item.run
|
169
180
|
end
|
170
181
|
|
171
182
|
it "should run success callback if accept value entered" do
|
172
183
|
call_me = i_should_be_called
|
173
|
-
|
184
|
+
call.should_receive(:input).with(3, anything).and_return('123')
|
174
185
|
item = form_field(:my_field, :length => 3, :attempts => 1) do
|
175
|
-
prompt :
|
186
|
+
prompt :play => "first"
|
176
187
|
|
177
188
|
success { call_me.call }
|
178
189
|
confirm(:accept => '1', :reject => '2') { [] }
|
179
190
|
end
|
180
|
-
|
191
|
+
call.should_receive(:input).with(1, anything).and_return('1')
|
181
192
|
|
182
193
|
item.run
|
183
194
|
end
|
184
195
|
|
185
196
|
it "should run failure callback if reject value entered" do
|
186
197
|
call_me = i_should_be_called
|
187
|
-
|
198
|
+
call.should_receive(:input).with(3, anything).and_return('123')
|
188
199
|
item = form_field(:my_field, :length => 3, :attempts => 1) do
|
189
|
-
prompt :
|
200
|
+
prompt :play => "first"
|
190
201
|
|
191
202
|
failure { call_me.call }
|
192
203
|
confirm(:accept => '1', :reject => '2') { [] }
|
193
204
|
end
|
194
|
-
|
205
|
+
call.should_receive(:input).with(1, anything).and_return('2')
|
195
206
|
|
196
207
|
item.run
|
197
208
|
end
|
198
209
|
|
199
210
|
it "should play confirmation input prompt if confirm block return value is array" do
|
200
211
|
call_me = i_should_be_called
|
201
|
-
|
212
|
+
call.should_receive(:input).with(3, anything).and_return('123')
|
202
213
|
|
203
214
|
item = form_field(:my_field, :length => 3, :attempts => 1) do
|
204
|
-
prompt :
|
215
|
+
prompt :play => "first"
|
205
216
|
|
206
217
|
success { call_me.call }
|
207
218
|
confirm(:timeout => 3) { [] }
|
208
219
|
end
|
209
|
-
|
220
|
+
call.should_receive(:input).with(1, {:play => [], :timeout => 3}).and_return('1')
|
210
221
|
|
211
222
|
item.run
|
212
223
|
end
|
213
224
|
|
214
225
|
it "should speak confirmation input prompt if confirm block return value is string" do
|
215
226
|
call_me = i_should_be_called
|
216
|
-
|
227
|
+
call.should_receive(:input).with(3, anything).and_return('123')
|
217
228
|
|
218
229
|
item = form_field(:my_field, :length => 3, :attempts => 1) do
|
219
|
-
prompt :
|
230
|
+
prompt :play => "first"
|
220
231
|
|
221
232
|
success { call_me.call }
|
222
|
-
confirm(:timeout => 3) { '' }
|
233
|
+
confirm(:timeout => 3) { 'speak me' }
|
223
234
|
end
|
224
|
-
|
235
|
+
call.should_receive(:input).with(1, {:speak => 'speak me', :timeout => 3}).and_return('1')
|
225
236
|
|
226
237
|
item.run
|
227
238
|
end
|
@@ -230,10 +241,10 @@ describe VoiceForm::FormField do
|
|
230
241
|
it "should run failure callback if no input" do
|
231
242
|
call_me = i_should_be_called
|
232
243
|
item = form_field(:my_field, :length => 3) do
|
233
|
-
prompt :
|
244
|
+
prompt :play => "first"
|
234
245
|
failure { call_me.call }
|
235
246
|
end
|
236
|
-
|
247
|
+
call.should_receive(:input).and_return('')
|
237
248
|
|
238
249
|
item.run
|
239
250
|
end
|
@@ -241,10 +252,10 @@ describe VoiceForm::FormField do
|
|
241
252
|
it "should run success callback if input valid length" do
|
242
253
|
call_me = i_should_be_called
|
243
254
|
item = form_field(:my_field, :length => 3) do
|
244
|
-
prompt :
|
255
|
+
prompt :play => "first"
|
245
256
|
success { call_me.call }
|
246
257
|
end
|
247
|
-
|
258
|
+
call.should_receive(:input).and_return('123')
|
248
259
|
|
249
260
|
item.run
|
250
261
|
end
|
@@ -253,14 +264,34 @@ describe VoiceForm::FormField do
|
|
253
264
|
validate_me = i_should_be_called
|
254
265
|
call_me = i_should_be_called
|
255
266
|
item = form_field(:my_field, :length => 3) do
|
256
|
-
prompt :
|
267
|
+
prompt :play => "first"
|
257
268
|
validate do
|
258
269
|
validate_me.call
|
259
270
|
my_field.to_i > 100
|
260
271
|
end
|
261
272
|
success { call_me.call }
|
262
273
|
end
|
263
|
-
|
274
|
+
call.should_receive(:input).and_return('123')
|
275
|
+
|
276
|
+
item.run
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should execute input with message when bargein is true" do
|
280
|
+
item = form_field(:my_field, :length => 3) do
|
281
|
+
prompt :play => "first", :bargein => true
|
282
|
+
end
|
283
|
+
call.should_not_receive(:play)
|
284
|
+
call.should_receive(:input).with(3, :play => "first", :timeout => 5)
|
285
|
+
|
286
|
+
item.run
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should execute playback method with message and input without message when bargein is false" do
|
290
|
+
item = form_field(:my_field, :length => 3) do
|
291
|
+
prompt :play => "first", :bargein => false
|
292
|
+
end
|
293
|
+
call.should_receive(:play).with('first')
|
294
|
+
call.should_receive(:input).with(3, :timeout => 5)
|
264
295
|
|
265
296
|
item.run
|
266
297
|
end
|
data/spec/form_spec.rb
CHANGED
@@ -3,36 +3,41 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
3
3
|
describe VoiceForm::Form do
|
4
4
|
include VoiceForm
|
5
5
|
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :call
|
7
7
|
|
8
8
|
before do
|
9
|
-
|
10
|
-
@
|
11
|
-
@call_context.stub!(:input).with(any_args).and_return('')
|
9
|
+
@call = mock('CallContext', :play => nil, :speak => nil)
|
10
|
+
@call.stub!(:input).with(any_args).and_return('')
|
12
11
|
end
|
13
12
|
|
14
13
|
it "should define form and run it" do
|
15
14
|
call_me = i_should_be_called
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
voice_form do
|
16
|
+
field(:my_field) { prompt :play => nil }
|
17
|
+
setup { call_me.call }
|
18
|
+
end
|
19
|
+
start_voice_form(@call)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should call setup block" do
|
23
|
-
|
24
|
-
|
23
|
+
call_me = i_should_be_called
|
24
|
+
voice_form do
|
25
|
+
setup { call_me.call }
|
26
|
+
field(:my_field) { prompt :play => nil }
|
27
|
+
end
|
25
28
|
run_form
|
26
29
|
end
|
27
30
|
|
28
31
|
it "should run single form field" do
|
29
32
|
call_me = i_should_be_called
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
voice_form do
|
35
|
+
field(:my_field) do
|
36
|
+
prompt :play => nil
|
37
|
+
setup { call_me.call }
|
38
|
+
end
|
34
39
|
end
|
35
|
-
|
40
|
+
|
36
41
|
run_form
|
37
42
|
end
|
38
43
|
|
@@ -40,14 +45,16 @@ describe VoiceForm::Form do
|
|
40
45
|
first_call_me = i_should_be_called
|
41
46
|
second_call_me = i_should_be_called
|
42
47
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
voice_form do
|
49
|
+
field(:first_field) do
|
50
|
+
prompt :play => nil
|
51
|
+
setup { first_call_me.call }
|
52
|
+
end
|
53
|
+
field(:second_field) do
|
54
|
+
prompt :play => nil
|
55
|
+
setup { second_call_me.call }
|
56
|
+
end
|
57
|
+
end
|
51
58
|
|
52
59
|
run_form
|
53
60
|
end
|
@@ -55,7 +62,10 @@ describe VoiceForm::Form do
|
|
55
62
|
it "should run do_blocks" do
|
56
63
|
do_block_call_me = i_should_be_called
|
57
64
|
|
58
|
-
|
65
|
+
voice_form do
|
66
|
+
do_block { do_block_call_me.call }
|
67
|
+
field(:my_field) { prompt :play => nil }
|
68
|
+
end
|
59
69
|
|
60
70
|
run_form
|
61
71
|
end
|
@@ -64,11 +74,13 @@ describe VoiceForm::Form do
|
|
64
74
|
field_call_me = i_should_be_called
|
65
75
|
do_block_call_me = i_should_be_called
|
66
76
|
|
67
|
-
|
68
|
-
|
69
|
-
|
77
|
+
voice_form do
|
78
|
+
field(:first_field) do
|
79
|
+
prompt :play => nil
|
80
|
+
setup { field_call_me.call }
|
81
|
+
end
|
82
|
+
do_block { do_block_call_me.call }
|
70
83
|
end
|
71
|
-
form.do_block { do_block_call_me.call }
|
72
84
|
|
73
85
|
run_form
|
74
86
|
end
|
@@ -78,17 +90,19 @@ describe VoiceForm::Form do
|
|
78
90
|
do_block_call_me = i_should_not_be_called
|
79
91
|
second_call_me = i_should_be_called
|
80
92
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
93
|
+
voice_form do
|
94
|
+
field(:first_field, :attempts => 1) do
|
95
|
+
prompt :play => nil
|
96
|
+
setup { first_call_me.call }
|
97
|
+
failure { form.goto :second_field }
|
98
|
+
end
|
99
|
+
|
100
|
+
do_block { do_block_call_me.call }
|
88
101
|
|
89
|
-
|
90
|
-
|
91
|
-
|
102
|
+
field(:second_field) do
|
103
|
+
prompt :play => nil
|
104
|
+
setup { second_call_me.call }
|
105
|
+
end
|
92
106
|
end
|
93
107
|
|
94
108
|
run_form
|
@@ -99,22 +113,24 @@ describe VoiceForm::Form do
|
|
99
113
|
do_block_call_me = i_should_be_called(2)
|
100
114
|
second_call_me = i_should_be_called(2)
|
101
115
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
116
|
+
voice_form do
|
117
|
+
field(:first_field, :attempts => 1) do
|
118
|
+
prompt :play => nil
|
119
|
+
setup { first_call_me.call }
|
120
|
+
end
|
106
121
|
|
107
|
-
|
122
|
+
do_block { do_block_call_me.call }
|
108
123
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
124
|
+
field(:second_field) do
|
125
|
+
prompt :play => nil
|
126
|
+
setup { second_call_me.call }
|
127
|
+
failure {
|
128
|
+
unless @once
|
129
|
+
@once = true
|
130
|
+
form.goto :first_field
|
131
|
+
end
|
132
|
+
}
|
133
|
+
end
|
118
134
|
end
|
119
135
|
|
120
136
|
run_form
|
@@ -125,22 +141,24 @@ describe VoiceForm::Form do
|
|
125
141
|
do_block_call_me = i_should_be_called(2)
|
126
142
|
second_call_me = i_should_be_called(2)
|
127
143
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
144
|
+
voice_form do
|
145
|
+
field(:first_field, :attempts => 1) do
|
146
|
+
prompt :play => nil
|
147
|
+
setup { first_call_me.call }
|
148
|
+
end
|
149
|
+
|
150
|
+
do_block { do_block_call_me.call }
|
134
151
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
152
|
+
field(:second_field) do
|
153
|
+
prompt :play => nil
|
154
|
+
setup { second_call_me.call }
|
155
|
+
failure {
|
156
|
+
unless @once
|
157
|
+
@once = true
|
158
|
+
form.restart
|
159
|
+
end
|
160
|
+
}
|
161
|
+
end
|
144
162
|
end
|
145
163
|
|
146
164
|
run_form
|
@@ -151,31 +169,31 @@ describe VoiceForm::Form do
|
|
151
169
|
do_block_call_me = i_should_not_be_called
|
152
170
|
second_call_me = i_should_not_be_called
|
153
171
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
172
|
+
voice_form do
|
173
|
+
field(:first_field, :attempts => 1) do
|
174
|
+
prompt :play => nil
|
175
|
+
setup { first_call_me.call }
|
176
|
+
failure { form.exit }
|
177
|
+
end
|
178
|
+
|
179
|
+
do_block { do_block_call_me.call }
|
161
180
|
|
162
|
-
|
163
|
-
|
164
|
-
|
181
|
+
field(:second_field) do
|
182
|
+
prompt :play => nil
|
183
|
+
setup { second_call_me.call }
|
184
|
+
end
|
165
185
|
end
|
166
186
|
|
167
187
|
run_form
|
168
188
|
end
|
169
189
|
|
170
190
|
describe "current_field" do
|
171
|
-
before do
|
172
|
-
@field = nil
|
173
|
-
end
|
174
|
-
|
175
191
|
it "should be name of current field being run" do
|
176
|
-
|
177
|
-
|
178
|
-
|
192
|
+
voice_form do
|
193
|
+
field(:my_field) do
|
194
|
+
prompt :play => nil
|
195
|
+
setup { @field = form.current_field }
|
196
|
+
end
|
179
197
|
end
|
180
198
|
run_form
|
181
199
|
|
@@ -183,8 +201,9 @@ describe VoiceForm::Form do
|
|
183
201
|
end
|
184
202
|
|
185
203
|
it "should be nil in do_block" do
|
186
|
-
|
187
|
-
|
204
|
+
voice_form do
|
205
|
+
field(:my_field) { prompt :play => nil }
|
206
|
+
do_block { @field = form.current_field }
|
188
207
|
end
|
189
208
|
run_form
|
190
209
|
|
@@ -192,8 +211,8 @@ describe VoiceForm::Form do
|
|
192
211
|
end
|
193
212
|
|
194
213
|
it "should be nil after form is run" do
|
195
|
-
|
196
|
-
prompt :
|
214
|
+
voice_form do
|
215
|
+
field(:my_field) { prompt :play => nil }
|
197
216
|
end
|
198
217
|
run_form
|
199
218
|
|
@@ -201,8 +220,8 @@ describe VoiceForm::Form do
|
|
201
220
|
end
|
202
221
|
end
|
203
222
|
|
204
|
-
def
|
205
|
-
self.class.voice_form
|
223
|
+
def voice_form(&block)
|
224
|
+
self.class.voice_form &block
|
206
225
|
options, block = *self.class.voice_form_options
|
207
226
|
self.form = VoiceForm::Form.new(options, &block)
|
208
227
|
end
|