twilio-test-toolkit-alt 3.4.1

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.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +265 -0
  4. data/Rakefile +38 -0
  5. data/lib/twilio-test-toolkit.rb +4 -0
  6. data/lib/twilio-test-toolkit/call_in_progress.rb +48 -0
  7. data/lib/twilio-test-toolkit/call_scope.rb +247 -0
  8. data/lib/twilio-test-toolkit/dsl.rb +15 -0
  9. data/lib/twilio-test-toolkit/version.rb +3 -0
  10. data/spec/dummy/README.rdoc +261 -0
  11. data/spec/dummy/Rakefile +7 -0
  12. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  13. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  14. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  15. data/spec/dummy/app/controllers/twilio_controller.rb +12 -0
  16. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  17. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  18. data/spec/dummy/app/views/layouts/twilio.layout.xml.erb +4 -0
  19. data/spec/dummy/app/views/twilio/test_action.xml.erb +2 -0
  20. data/spec/dummy/app/views/twilio/test_call_status.xml.erb +6 -0
  21. data/spec/dummy/app/views/twilio/test_dial_with_action.xml.erb +3 -0
  22. data/spec/dummy/app/views/twilio/test_dial_with_no_action.xml.erb +3 -0
  23. data/spec/dummy/app/views/twilio/test_dial_with_sip.xml +6 -0
  24. data/spec/dummy/app/views/twilio/test_gather_finish_on_asterisk.xml.erb +3 -0
  25. data/spec/dummy/app/views/twilio/test_hangup.xml.erb +1 -0
  26. data/spec/dummy/app/views/twilio/test_play.xml.erb +1 -0
  27. data/spec/dummy/app/views/twilio/test_record.xml +2 -0
  28. data/spec/dummy/app/views/twilio/test_redirect.xml.erb +1 -0
  29. data/spec/dummy/app/views/twilio/test_say.xml.erb +1 -0
  30. data/spec/dummy/app/views/twilio/test_start.xml.erb +5 -0
  31. data/spec/dummy/config.ru +4 -0
  32. data/spec/dummy/config/application.rb +59 -0
  33. data/spec/dummy/config/boot.rb +10 -0
  34. data/spec/dummy/config/database.yml +25 -0
  35. data/spec/dummy/config/environment.rb +5 -0
  36. data/spec/dummy/config/environments/development.rb +37 -0
  37. data/spec/dummy/config/environments/production.rb +67 -0
  38. data/spec/dummy/config/environments/test.rb +37 -0
  39. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  40. data/spec/dummy/config/initializers/inflections.rb +15 -0
  41. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  42. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  43. data/spec/dummy/config/initializers/session_store.rb +8 -0
  44. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  45. data/spec/dummy/config/locales/en.yml +5 -0
  46. data/spec/dummy/config/routes.rb +17 -0
  47. data/spec/dummy/db/development.sqlite3 +0 -0
  48. data/spec/dummy/db/schema.rb +16 -0
  49. data/spec/dummy/db/test.sqlite3 +0 -0
  50. data/spec/dummy/log/test.log +20546 -0
  51. data/spec/dummy/public/404.html +26 -0
  52. data/spec/dummy/public/422.html +26 -0
  53. data/spec/dummy/public/500.html +25 -0
  54. data/spec/dummy/public/favicon.ico +0 -0
  55. data/spec/dummy/script/rails +6 -0
  56. data/spec/requests/call_scope_spec.rb +399 -0
  57. data/spec/requests/dsl_spec.rb +69 -0
  58. data/spec/spec_helper.rb +20 -0
  59. metadata +264 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,399 @@
1
+ require 'spec_helper'
2
+
3
+ describe TwilioTestToolkit::CallScope do
4
+ before(:each) do
5
+ @our_number = "2065551212"
6
+ @their_number = "2065553434"
7
+ end
8
+
9
+ describe "basics" do
10
+ before(:each) do
11
+ @call = ttt_call(test_start_twilio_index_path, @our_number, @their_number)
12
+ end
13
+
14
+ it "should be a CallScope" do
15
+ @call.should be_a(TwilioTestToolkit::CallScope)
16
+ end
17
+
18
+ it "should have the informational methods" do
19
+ @call.should respond_to(:current_path)
20
+ @call.should respond_to(:response_xml)
21
+ end
22
+
23
+ it "should have the right path" do
24
+ @call.current_path.should == test_start_twilio_index_path
25
+ end
26
+
27
+ it "should have a response xml value" do
28
+ @call.response_xml.should_not be_blank
29
+ end
30
+
31
+ it "should have the right root call" do
32
+ @call.should respond_to(:root_call)
33
+ @call.root_call.should == @call
34
+ end
35
+ end
36
+
37
+ describe "redirect" do
38
+ describe "success" do
39
+ before(:each) do
40
+ @call = ttt_call(test_redirect_twilio_index_path, @our_number, @their_number)
41
+ end
42
+
43
+ it "should have the redirect methods" do
44
+ @call.should respond_to(:has_redirect?)
45
+ @call.should respond_to(:has_redirect_to?)
46
+ @call.should respond_to(:follow_redirect)
47
+ @call.should respond_to(:follow_redirect!)
48
+ end
49
+
50
+ it "should have the right value for has_redirect?" do
51
+ @call.should have_redirect
52
+ end
53
+
54
+ it "should have the right values for has_redirect_to?" do
55
+ @call.has_redirect_to?("http://foo").should be_false
56
+ @call.has_redirect_to?(test_start_twilio_index_path).should be_true
57
+ @call.has_redirect_to?(test_start_twilio_index_path + ".xml").should be_true # Should force normalization
58
+ end
59
+
60
+ it "should follow the redirect (immutable version)" do
61
+ # follow_redirect returns a new CallScope
62
+ newcall = @call.follow_redirect
63
+
64
+ # Make sure it followed
65
+ newcall.current_path.should == test_start_twilio_index_path
66
+
67
+ # And is not the same call
68
+ newcall.response_xml.should_not == @call.response_xml
69
+ # But it's linked
70
+ newcall.root_call.should == @call
71
+
72
+ # And we did not modify the original call
73
+ @call.current_path.should == test_redirect_twilio_index_path
74
+ end
75
+
76
+ it "should follow the redirect (mutable version)" do
77
+ # follow_redirect! modifies the CallScope
78
+ @call.follow_redirect!
79
+
80
+ # Make sure it followed
81
+ @call.current_path.should == test_start_twilio_index_path
82
+ end
83
+
84
+ it "should submit default params on follow_redirect" do
85
+ default_request_params = {
86
+ :format => :xml,
87
+ :From => "2065551212",
88
+ :Digits => "",
89
+ :To => "2065553434",
90
+ :AnsweredBy => "human",
91
+ :CallStatus => "in-progress"
92
+ }
93
+ Capybara.current_session.driver
94
+ .should_receive(:post)
95
+ .with("/twilio/test_start", hash_including(default_request_params))
96
+ .and_call_original
97
+
98
+ @call.follow_redirect
99
+ end
100
+
101
+ it "should consider options for follow_redirect!" do
102
+ Capybara.current_session.driver
103
+ .should_receive(:post)
104
+ .with("/twilio/test_start", hash_including(:CallStatus => "completed"))
105
+ .and_call_original
106
+
107
+ @call.follow_redirect!(call_status: "completed")
108
+ end
109
+
110
+ it "should consider options for follow_redirect" do
111
+ Capybara.current_session.driver
112
+ .should_receive(:post)
113
+ .with("/twilio/test_start", hash_including(:CallStatus => "completed"))
114
+ .and_call_original
115
+
116
+ @call.follow_redirect(call_status: "completed")
117
+ end
118
+ end
119
+
120
+ describe "failure" do
121
+ before(:each) do
122
+ # Initiate a call that's not on a redirect - various calls will fail
123
+ @call = ttt_call(test_say_twilio_index_path, @our_number, @their_number)
124
+ end
125
+
126
+ it "should have the right value for has_redirect?" do
127
+ @call.should_not have_redirect
128
+ end
129
+
130
+ it "should have the right values for has_redirect_to?" do
131
+ @call.has_redirect_to?("http://foo").should be_false
132
+ @call.has_redirect_to?(test_start_twilio_index_path).should be_false
133
+ @call.has_redirect_to?(test_start_twilio_index_path + ".xml").should be_false
134
+ end
135
+
136
+ it "should raise an error on follow_redirect" do
137
+ lambda {@call.follow_redirect}.should raise_error
138
+ end
139
+
140
+ it "should raise an error on follow_redirect!" do
141
+ lambda {@call.follow_redirect!}.should raise_error
142
+ end
143
+ end
144
+ end
145
+
146
+ describe "say" do
147
+ before(:each) do
148
+ @call = ttt_call(test_say_twilio_index_path, @our_number, @their_number)
149
+ end
150
+
151
+ it "should have the expected say methods" do
152
+ @call.should respond_to(:has_say?)
153
+ end
154
+
155
+ it "should have the right values for has_say?" do
156
+ @call.has_say?("Blah blah").should be_false
157
+ @call.has_say?("This is a say page.").should be_true
158
+ @call.has_say?("This is").should be_true # Partial match
159
+ end
160
+ end
161
+
162
+ describe "play" do
163
+ before(:each) do
164
+ @call = ttt_call(test_play_twilio_index_path, @our_number, @their_number)
165
+ end
166
+
167
+ it "should have the expected say play methods" do
168
+ @call.should respond_to(:has_play?)
169
+ end
170
+
171
+ it "should have the right values for has_say?" do
172
+ @call.has_play?("/path/to/a/different/audio/clip.mp3").should be_false
173
+ @call.has_play?("/path/to/an/audio/clip.mp3").should be_true
174
+ @call.has_play?("clip.mp3").should be_false
175
+ end
176
+ end
177
+
178
+ describe "dial" do
179
+ before(:each) do
180
+ @call = ttt_call(test_dial_with_action_twilio_index_path, @our_number, @their_number)
181
+ end
182
+
183
+ it "should have the expected dial methods" do
184
+ @call.should respond_to(:has_dial?)
185
+ end
186
+
187
+ it "should have the right values for has_dial?" do
188
+ @call.has_dial?("911").should be_false
189
+ @call.has_dial?("18001234567").should be_true
190
+ @call.has_dial?("12345").should be_true # Partial match
191
+ end
192
+
193
+ it "should not match the dial action if there isn't one" do
194
+ @call = ttt_call(test_dial_with_no_action_twilio_index_path, @our_number, @their_number)
195
+
196
+ @call.has_action_on_dial?("http://example.org:3000/call_me_back").should eq false
197
+ end
198
+
199
+ it "should match the action on dial if there is one" do
200
+ @call.has_action_on_dial?("http://example.org:3000/call_me_back").should be_true
201
+ end
202
+
203
+ it "should not match the action on dial if it's different than the one specified" do
204
+ @call.has_action_on_dial?("http://example.org:3000/dont_call").should be_false
205
+ end
206
+
207
+ it "should dial a sip peer with the correct structure" do
208
+ @call = ttt_call(test_dial_with_sip_twilio_index_path, @our_number, @their_number)
209
+ @call.within_dial do |dial|
210
+ dial.has_sip?.should be_true
211
+ dial.within_sip do |sip|
212
+ sip.has_uri?("18885551234@sip.foo.bar").should be_true
213
+ sip.has_username_on_uri?("foo").should be_true
214
+ sip.has_password_on_uri?("bar").should be_true
215
+ end
216
+ end
217
+ end
218
+ end
219
+
220
+ describe "hangup" do
221
+ describe "success" do
222
+ before(:each) do
223
+ @call = ttt_call(test_hangup_twilio_index_path, @our_number, @their_number)
224
+ end
225
+
226
+ it "should have the expected hangup methods" do
227
+ @call.should respond_to(:has_hangup?)
228
+ end
229
+
230
+ it "should have the right value for has_hangup?" do
231
+ @call.should have_hangup
232
+ end
233
+ end
234
+
235
+ describe "failure" do
236
+ before(:each) do
237
+ @call = ttt_call(test_start_twilio_index_path, @our_number, @their_number)
238
+ end
239
+
240
+ it "should have the right value for has_hangup?" do
241
+ @call.should_not have_hangup
242
+ end
243
+ end
244
+ end
245
+
246
+ describe "gather" do
247
+ describe "success" do
248
+ before(:each) do
249
+ @call = ttt_call(test_start_twilio_index_path, @our_number, @their_number)
250
+ end
251
+
252
+ it "should have the expected gather methods" do
253
+ @call.should respond_to(:has_gather?)
254
+ @call.should respond_to(:within_gather)
255
+ @call.should respond_to(:gather?)
256
+ @call.should respond_to(:gather_action)
257
+ @call.should respond_to(:press)
258
+ end
259
+
260
+ it "should have the right value for has_gather?" do
261
+ @call.has_gather?.should be_true
262
+ end
263
+
264
+ it "should have the right value for gather?" do
265
+ # Although we have a gather, the current call scope is not itself a gather, so this returns false.
266
+ @call.gather?.should be_false
267
+ end
268
+
269
+ it "should fail on gather-scoped methods outside of a gather scope" do
270
+ lambda {@call.gather_action}.should raise_error
271
+ lambda {@call.press "1234"}.should raise_error
272
+ end
273
+
274
+ it "should gather" do
275
+ # We should not have a say that's contained within a gather.
276
+ @call.should_not have_say("Please enter some digits.")
277
+
278
+ # Now enter the gather block.
279
+ @call.within_gather do |gather|
280
+ # We should have a say here
281
+ gather.should have_say("Please enter some digits.")
282
+
283
+ # We should be in a gather
284
+ gather.gather?.should be_true
285
+ # And we should have an action
286
+ gather.gather_action.should == test_action_twilio_index_path
287
+
288
+ # And we should have the right root call
289
+ gather.root_call.should == @call
290
+
291
+ # Press some digits.
292
+ gather.press "98765"
293
+ end
294
+
295
+ # This should update the path
296
+ @call.current_path.should == test_action_twilio_index_path
297
+
298
+ # This view says the digits we pressed - make sure
299
+ @call.should have_say "You entered 98765."
300
+ end
301
+
302
+ it "should gather without a press" do
303
+ @call.within_gather do |gather|
304
+ # Do nothing
305
+ end
306
+
307
+ # We should still be on the same page
308
+ @call.current_path.should == test_start_twilio_index_path
309
+ end
310
+
311
+ it "should respond to the default finish key of hash" do
312
+ @call.within_gather do |gather|
313
+ gather.press "98765#"
314
+ end
315
+ @call.should have_say "You entered 98765."
316
+ end
317
+ end
318
+
319
+ describe "with finishOnKey specified" do
320
+ before(:each) do
321
+ @call = ttt_call(test_gather_finish_on_asterisk_twilio_index_path, @our_number, @their_number)
322
+ end
323
+
324
+ it "should strip the finish key from the digits" do
325
+ @call.within_gather do |gather|
326
+ gather.press "98765*"
327
+ end
328
+
329
+ @call.should have_say "You entered 98765."
330
+ end
331
+
332
+ it "should still accept the digits without a finish key (due to timeout)" do
333
+ @call.within_gather do |gather|
334
+ gather.press "98765"
335
+ end
336
+
337
+ @call.should have_say "You entered 98765."
338
+ end
339
+
340
+ end
341
+
342
+ describe "failure" do
343
+ before(:each) do
344
+ @call = ttt_call(test_say_twilio_index_path, @our_number, @their_number)
345
+ end
346
+
347
+ it "should have the right value for has_gather?" do
348
+ @call.has_gather?.should be_false
349
+ end
350
+
351
+ it "should have the right value for gather?" do
352
+ @call.gather?.should be_false
353
+ end
354
+
355
+ it "should fail on within_gather if there is no gather" do
356
+ lambda {@call.within_gather do |gather|; end}.should raise_error
357
+ end
358
+
359
+ it "should fail on gather-scoped methods outside of a gather scope" do
360
+ lambda {@call.gather_action}.should raise_error
361
+ lambda {@call.press "1234"}.should raise_error
362
+ end
363
+ end
364
+ end
365
+
366
+ describe "record" do
367
+ before(:each) do
368
+ @call = ttt_call(test_record_twilio_index_path, @our_number, @their_number)
369
+ end
370
+
371
+ it "should have the expected say record methods" do
372
+ @call.should respond_to(:has_record?)
373
+ end
374
+
375
+ it "should have the right action for record" do
376
+ @call.has_action_on_record?("http://example.org:3000/record_this_call").should be_true
377
+ end
378
+
379
+ it "should have the right maxLength for record" do
380
+ @call.has_max_length_on_record?("20").should be_true
381
+ end
382
+
383
+ it "should have the right finishOnKey for record" do
384
+ @call.has_finish_on_key_on_record?("*").should be_true
385
+ end
386
+ end
387
+
388
+ describe "conditional handling on call_status" do
389
+ it "should default to in progress" do
390
+ @call = ttt_call(test_call_status_twilio_index_path, @our_number, @their_number)
391
+ @call.should have_say "Your call is in progress."
392
+ end
393
+
394
+ it "should respond differently to a ringing call" do
395
+ @call = ttt_call(test_call_status_twilio_index_path, @our_number, @their_number, :call_status => 'ringing')
396
+ @call.should have_say "Your call is ringing."
397
+ end
398
+ end
399
+ end