voice_form 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,232 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe VoiceForm::Form do
4
+ include VoiceForm
5
+
6
+ attr_accessor :call
7
+
8
+ before do
9
+ @call = mock('CallContext', :play => nil, :speak => nil)
10
+ @call.stub!(:input).with(any_args).and_return('')
11
+ end
12
+
13
+ it "should define form and run it" do
14
+ call_me = i_should_be_called
15
+ voice_form do
16
+ field(:my_field) { prompt :play => nil }
17
+ setup { call_me.call }
18
+ end
19
+ start_voice_form(@call)
20
+ end
21
+
22
+ it "should call setup block" do
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
28
+ run_form
29
+ end
30
+
31
+ it "should run single form field" do
32
+ call_me = i_should_be_called
33
+
34
+ voice_form do
35
+ field(:my_field) do
36
+ prompt :play => nil
37
+ setup { call_me.call }
38
+ end
39
+ end
40
+
41
+ run_form
42
+ end
43
+
44
+ it "should run all form fields" do
45
+ first_call_me = i_should_be_called
46
+ second_call_me = i_should_be_called
47
+
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
58
+
59
+ run_form
60
+ end
61
+
62
+ it "should run do_blocks" do
63
+ do_block_call_me = i_should_be_called
64
+
65
+ voice_form do
66
+ do_block { do_block_call_me.call }
67
+ field(:my_field) { prompt :play => nil }
68
+ end
69
+
70
+ run_form
71
+ end
72
+
73
+ it "should run all fields and do_blocks" do
74
+ field_call_me = i_should_be_called
75
+ do_block_call_me = i_should_be_called
76
+
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 }
83
+ end
84
+
85
+ run_form
86
+ end
87
+
88
+ it "should jump forward in form stack to field in goto" do
89
+ first_call_me = i_should_be_called
90
+ do_block_call_me = i_should_not_be_called
91
+ second_call_me = i_should_be_called
92
+
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 }
101
+
102
+ field(:second_field) do
103
+ prompt :play => nil
104
+ setup { second_call_me.call }
105
+ end
106
+ end
107
+
108
+ run_form
109
+ end
110
+
111
+ it "should jump back in form stack to goto field and repeat form stack items" do
112
+ first_call_me = i_should_be_called(2)
113
+ do_block_call_me = i_should_be_called(2)
114
+ second_call_me = i_should_be_called(2)
115
+
116
+ voice_form do
117
+ field(:first_field, :attempts => 1) do
118
+ prompt :play => nil
119
+ setup { first_call_me.call }
120
+ end
121
+
122
+ do_block { do_block_call_me.call }
123
+
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
134
+ end
135
+
136
+ run_form
137
+ end
138
+
139
+ it "should restart form and repeat all form stack items" do
140
+ first_call_me = i_should_be_called(2)
141
+ do_block_call_me = i_should_be_called(2)
142
+ second_call_me = i_should_be_called(2)
143
+
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 }
151
+
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
162
+ end
163
+
164
+ run_form
165
+ end
166
+
167
+ it "should exit form and not run subsequent fields" do
168
+ first_call_me = i_should_be_called
169
+ do_block_call_me = i_should_not_be_called
170
+ second_call_me = i_should_not_be_called
171
+
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 }
180
+
181
+ field(:second_field) do
182
+ prompt :play => nil
183
+ setup { second_call_me.call }
184
+ end
185
+ end
186
+
187
+ run_form
188
+ end
189
+
190
+ describe "current_field" do
191
+ it "should be name of current field being run" do
192
+ voice_form do
193
+ field(:my_field) do
194
+ prompt :play => nil
195
+ setup { @field = form.current_field }
196
+ end
197
+ end
198
+ run_form
199
+
200
+ @field.should == :my_field
201
+ end
202
+
203
+ it "should be nil in do_block" do
204
+ voice_form do
205
+ field(:my_field) { prompt :play => nil }
206
+ do_block { @field = form.current_field }
207
+ end
208
+ run_form
209
+
210
+ @field.should be_nil
211
+ end
212
+
213
+ it "should be nil after form is run" do
214
+ voice_form do
215
+ field(:my_field) { prompt :play => nil }
216
+ end
217
+ run_form
218
+
219
+ form.current_field.should be_nil
220
+ end
221
+ end
222
+
223
+ def voice_form(&block)
224
+ self.class.voice_form &block
225
+ options, block = *self.class.voice_form_options
226
+ self.form = VoiceForm::Form.new(options, &block)
227
+ end
228
+
229
+ def run_form
230
+ form.run(self)
231
+ end
232
+ end
@@ -0,0 +1,28 @@
1
+ $: << File.dirname(__FILE__) + '/../lib'
2
+ $: << File.dirname(__FILE__)
3
+
4
+ require 'rubygems'
5
+ require 'spec'
6
+ require 'active_support'
7
+
8
+ require 'voice_form/form_methods'
9
+ require 'voice_form/form'
10
+ require 'voice_form/form_field'
11
+
12
+ module SpecHelpers
13
+ def i_should_be_called(times=1, &block)
14
+ proc = mock('Proc should be called')
15
+ proc.should_receive(:call).exactly(times).times.instance_eval(&(block || Proc.new {}))
16
+ Proc.new { |*args| proc.call(*args) }
17
+ end
18
+
19
+ def i_should_not_be_called(&block)
20
+ proc = mock('Proc should be called')
21
+ proc.should_not_receive(:call).instance_eval(&(block || Proc.new {}))
22
+ Proc.new { |*args| proc.call(*args) }
23
+ end
24
+ end
25
+
26
+ Spec::Runner.configure do |config|
27
+ config.include SpecHelpers
28
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: voice_form
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Meehan
8
+ autorequire: voice_form
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-23 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A plugin for Adhearsion to create forms in the style of the VoiceXML form element.
17
+ email: adam.meehan@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - History.txt
24
+ files:
25
+ - MIT-LICENSE
26
+ - README.markdown
27
+ - Rakefile
28
+ - lib/voice_form.rb
29
+ - lib/voice_form
30
+ - lib/voice_form/form.rb
31
+ - lib/voice_form/form_field.rb
32
+ - lib/voice_form/form_methods.rb
33
+ - spec/form_field_spec.rb
34
+ - spec/spec_helper.rb
35
+ - spec/form_spec.rb
36
+ - examples/my_component.rb
37
+ - examples/simon_game_voice_form.rb
38
+ - History.txt
39
+ has_rdoc: false
40
+ homepage: http://github.com/adzap/voice_form
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.1
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: A plugin for Adhearsion to create forms in the style of the VoiceXML form element.
65
+ test_files: []
66
+