This repository has been archived by the owner on Jan 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
play_spec.rb
136 lines (100 loc) · 4.48 KB
/
play_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
require "spec_helper"
describe Adhearsion::Twilio::ControllerMethods, type: :call_controller, include_deprecated_helpers: true do
describe "<Play>" do
# From: https://www.twilio.com/docs/api/twiml/play
# "The <Play> verb plays an audio file back to the caller.
# Twilio retrieves the file from a URL that you provide."
let(:cassette) { :play }
let(:asserted_verb) { :play_audio }
let(:asserted_verb_args) { [file_url, hash_including(asserted_verb_options)] }
def setup_scenario
allow(subject).to receive(:play_audio)
end
def cassette_options
super.merge(file_url: file_url)
end
before do
setup_scenario
end
describe "Nouns" do
# From: https://www.twilio.com/docs/api/twiml/play
# The "noun" of a TwiML verb is the stuff nested within the verb
# that's not a verb itself; it's the stuff the verb acts upon.
# These are the nouns for <Play>:
# | Noun | Description |
# | plain text | The URL of an audio file that Twilio will retrieve and play to the caller. |
# Twilio supports the following audio MIME types for audio files retrieved by the <Play> verb:
# | MIME type | Description |
# | audio/mpeg | mpeg layer 3 audio |
# | audio/wav | wav format audio |
# | audio/wave | wav format audio |
# | audio/x-wav | wav format audio |
# | audio/aiff | audio interchange file format |
# | audio/x-aifc | audio interchange file format |
# | audio/x-aiff | audio interchange file format |
# | audio/x-gsm | GSM audio format |
# | audio/gsm | GSM audio format |
# | audio/ulaw | μ-law audio format |
context "plain text" do
# <?xml version="1.0" encoding="UTF-8" ?>
# <Response>
# <Play>http://api.twilio.com/cowbell.mp3</Play>
# </Response>
it { run_and_assert! }
end # context "plain text"
end # describe "Nouns"
describe "Verb Attributes" do
# From: https://www.twilio.com/docs/api/twiml/play
# The <Play> verb supports the following attributes that modify its behavior:
# | Attribute Name | Allowed Values | Default Value |
# | loop | integer >= 0 | 1 |
describe "'loop'" do
# From: https://www.twilio.com/docs/api/twiml/play
# The 'loop' attribute specifies how many times the audio file is played.
# The default behavior is to play the audio once.
# Specifying '0' will cause the the <Play> verb to loop until the call is hung up.
context "not specified" do
# From: https://www.twilio.com/docs/api/twiml/play
# "The default behavior is to play the audio once."
# <?xml version="1.0" encoding="UTF-8" ?>
# <Response>
# <Play>http://api.twilio.com/cowbell.mp3</Play>
# </Response>
it { run_and_assert! }
end # context "not specified"
context "specified" do
let(:cassette) { :play_with_loop }
def cassette_options
super.merge(loop: loop)
end
context "'0'" do
# From: https://www.twilio.com/docs/api/twiml/play
# "Specifying '0' will cause the the <Play> verb to loop until the call is hung up."
# <?xml version="1.0" encoding="UTF-8" ?>
# <Response>
# <Play loop="0">http://api.twilio.com/cowbell.mp3</Play>
# </Response>
let(:loop) { "0" }
let(:asserted_verb_num_runs) { infinity }
def setup_scenario
super
stub_infinite_loop
end
it { run_and_assert! }
end # context "'0'"
context "'5'" do
# From: https://www.twilio.com/docs/api/twiml/play
# "The 'loop' attribute specifies how many times the audio file is played."
# <?xml version="1.0" encoding="UTF-8" ?>
# <Response>
# <Play loop="5">http://api.twilio.com/cowbell.mp3</Play>
# </Response>
let(:loop) { "5" }
let(:asserted_verb_num_runs) { 5 }
it { run_and_assert! }
end # context "'5'"
end # context "specified"
end # describe "'loop'"
end # describe "Verb Attributes"
end # describe "<Play>"
end