punchblock 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,181 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Punchblock
4
- module Component
5
- module Tropo
6
- describe Ask do
7
- it 'registers itself' do
8
- RayoNode.class_from_registration(:ask, 'urn:xmpp:tropo:ask:1').should == Ask
9
- end
10
-
11
- describe "when setting options in initializer" do
12
- subject do
13
- Ask.new :choices => {:value => '[5 DIGITS]', :content_type => 'application/grammar+custom'},
14
- :prompt => {:text => 'Please enter your postal code.', :voice => 'kate'},
15
- :bargein => true,
16
- :min_confidence => 0.3,
17
- :mode => :speech,
18
- :recognizer => 'en-US',
19
- :terminator => '#',
20
- :timeout => 12000
21
- end
22
-
23
-
24
- its(:choices) { should == Ask::Choices.new(:value => '[5 DIGITS]', :content_type => 'application/grammar+custom') }
25
- its(:prompt) { should == Ask::Prompt.new(:voice => 'kate', :text => 'Please enter your postal code.') }
26
- its(:bargein) { should == true }
27
- its(:min_confidence) { should == 0.3 }
28
- its(:mode) { should == :speech }
29
- its(:recognizer) { should == 'en-US' }
30
- its(:terminator) { should == '#' }
31
- its(:timeout) { should == 12000 }
32
- end
33
-
34
- def grxml_doc(mode = :dtmf)
35
- RubySpeech::GRXML.draw :mode => mode.to_s, :root => 'digits' do
36
- rule id: 'digits' do
37
- one_of do
38
- 0.upto(1) { |d| item { d.to_s } }
39
- end
40
- end
41
- end
42
- end
43
-
44
- describe Ask::Choices do
45
- describe "when not passing a grammar" do
46
- subject { Ask::Choices.new :value => grxml_doc }
47
- its(:content_type) { should == 'application/grammar+grxml' }
48
- end
49
-
50
- describe 'with a simple grammar' do
51
- subject { Ask::Choices.new :value => '[5 DIGITS]', :content_type => 'application/grammar+custom' }
52
-
53
- let(:expected_message) { "<![CDATA[ [5 DIGITS] ]]>" }
54
-
55
- it "should wrap grammar in CDATA" do
56
- subject.child.to_xml.should == expected_message.strip
57
- end
58
- end
59
-
60
- describe 'with a GRXML grammar' do
61
- subject { Ask::Choices.new :value => grxml_doc, :content_type => 'application/grammar+grxml' }
62
-
63
- its(:content_type) { should == 'application/grammar+grxml' }
64
-
65
- let(:expected_message) { "<![CDATA[ #{grxml_doc} ]]>" }
66
-
67
- it "should wrap GRXML in CDATA" do
68
- subject.child.to_xml.should == expected_message.strip
69
- end
70
-
71
- its(:value) { should == grxml_doc }
72
-
73
- describe "comparison" do
74
- let(:grammar2) { Ask::Choices.new :value => '<grammar xmlns="http://www.w3.org/2001/06/grammar" version="1.0" xml:lang="en-US" mode="dtmf" root="digits"><rule id="digits"><one-of><item>0</item><item>1</item></one-of></rule></grammar>' }
75
- let(:grammar3) { Ask::Choices.new :value => grxml_doc }
76
- let(:grammar4) { Ask::Choices.new :value => grxml_doc(:speech) }
77
-
78
- it { should == grammar2 }
79
- it { should == grammar3 }
80
- it { should_not == grammar4 }
81
- end
82
- end
83
- end
84
-
85
- describe "actions" do
86
- let(:mock_client) { mock 'Client' }
87
- let(:command) { Ask.new :choices => '[5 DIGITS]' }
88
-
89
- before do
90
- command.component_id = 'abc123'
91
- command.call_id = '123abc'
92
- command.client = mock_client
93
- end
94
-
95
- describe '#stop_action' do
96
- subject { command.stop_action }
97
-
98
- its(:to_xml) { should == '<stop xmlns="urn:xmpp:rayo:1"/>' }
99
- its(:component_id) { should == 'abc123' }
100
- its(:call_id) { should == '123abc' }
101
- end
102
-
103
- describe '#stop!' do
104
- describe "when the command is executing" do
105
- before do
106
- command.request!
107
- command.execute!
108
- end
109
-
110
- it "should send its command properly" do
111
- mock_client.expects(:execute_command).with(command.stop_action, :call_id => '123abc', :component_id => 'abc123')
112
- command.stop!
113
- end
114
- end
115
-
116
- describe "when the command is not executing" do
117
- it "should raise an error" do
118
- lambda { command.stop! }.should raise_error(InvalidActionError, "Cannot stop a Ask that is not executing")
119
- end
120
- end
121
- end
122
- end
123
-
124
- describe Ask::Complete::Success do
125
- let :stanza do
126
- <<-MESSAGE
127
- <complete xmlns='urn:xmpp:rayo:ext:1'>
128
- <success mode="speech" confidence="0.45" xmlns='urn:xmpp:tropo:ask:complete:1'>
129
- <interpretation>1234</interpretation>
130
- <utterance>one two three four</utterance>
131
- </success>
132
- </complete>
133
- MESSAGE
134
- end
135
-
136
- subject { RayoNode.import(parse_stanza(stanza).root).reason }
137
-
138
- it { should be_instance_of Ask::Complete::Success }
139
-
140
- its(:name) { should == :success }
141
- its(:mode) { should == :speech }
142
- its(:confidence) { should == 0.45 }
143
- its(:interpretation) { should == '1234' }
144
- its(:utterance) { should == 'one two three four' }
145
- end
146
-
147
- describe Ask::Complete::NoMatch do
148
- let :stanza do
149
- <<-MESSAGE
150
- <complete xmlns='urn:xmpp:rayo:ext:1'>
151
- <nomatch xmlns='urn:xmpp:tropo:ask:complete:1' />
152
- </complete>
153
- MESSAGE
154
- end
155
-
156
- subject { RayoNode.import(parse_stanza(stanza).root).reason }
157
-
158
- it { should be_instance_of Ask::Complete::NoMatch }
159
-
160
- its(:name) { should == :nomatch }
161
- end
162
-
163
- describe Ask::Complete::NoInput do
164
- let :stanza do
165
- <<-MESSAGE
166
- <complete xmlns='urn:xmpp:rayo:ext:1'>
167
- <noinput xmlns='urn:xmpp:tropo:ask:complete:1' />
168
- </complete>
169
- MESSAGE
170
- end
171
-
172
- subject { RayoNode.import(parse_stanza(stanza).root).reason }
173
-
174
- it { should be_instance_of Ask::Complete::NoInput }
175
-
176
- its(:name) { should == :noinput }
177
- end
178
- end
179
- end
180
- end
181
- end # Punchblock
@@ -1,172 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Punchblock
4
- module Component
5
- module Tropo
6
- describe Say do
7
- it 'registers itself' do
8
- RayoNode.class_from_registration(:say, 'urn:xmpp:tropo:say:1').should == Say
9
- end
10
-
11
- describe "for text" do
12
- subject { Say.new :text => 'Once upon a time there was a message...', :voice => 'kate' }
13
-
14
- its(:voice) { should == 'kate' }
15
- its(:text) { should == 'Once upon a time there was a message...' }
16
- end
17
-
18
- describe "for SSML" do
19
- subject { Say.new :ssml => '<say-as interpret-as="ordinal">100</say-as>', :voice => 'kate' }
20
-
21
- its(:voice) { should == 'kate' }
22
- it "should have the correct content" do
23
- subject.child.to_s.should == '<say-as interpret-as="ordinal">100</say-as>'
24
- end
25
- end
26
-
27
- describe "actions" do
28
- let(:mock_client) { mock 'Client' }
29
- let(:command) { Say.new :text => 'Once upon a time there was a message...', :voice => 'kate' }
30
-
31
- before do
32
- command.component_id = 'abc123'
33
- command.call_id = '123abc'
34
- command.client = mock_client
35
- end
36
-
37
- describe '#pause_action' do
38
- subject { command.pause_action }
39
-
40
- its(:to_xml) { should == '<pause xmlns="urn:xmpp:tropo:say:1"/>' }
41
- its(:component_id) { should == 'abc123' }
42
- its(:call_id) { should == '123abc' }
43
- end
44
-
45
- describe '#pause!' do
46
- describe "when the command is executing" do
47
- before do
48
- command.request!
49
- command.execute!
50
- end
51
-
52
- it "should send its command properly" do
53
- mock_client.expects(:execute_command).with(command.pause_action, :call_id => '123abc', :component_id => 'abc123').returns true
54
- command.expects :paused!
55
- command.pause!
56
- end
57
- end
58
-
59
- describe "when the command is not executing" do
60
- it "should raise an error" do
61
- lambda { command.pause! }.should raise_error(InvalidActionError, "Cannot pause a Say that is not executing")
62
- end
63
- end
64
- end
65
-
66
- describe "#paused!" do
67
- before do
68
- subject.request!
69
- subject.execute!
70
- subject.paused!
71
- end
72
-
73
- its(:state_name) { should == :paused }
74
-
75
- it "should raise a StateMachine::InvalidTransition when received a second time" do
76
- lambda { subject.paused! }.should raise_error(StateMachine::InvalidTransition)
77
- end
78
- end
79
-
80
- describe '#resume_action' do
81
- subject { command.resume_action }
82
-
83
- its(:to_xml) { should == '<resume xmlns="urn:xmpp:tropo:say:1"/>' }
84
- its(:component_id) { should == 'abc123' }
85
- its(:call_id) { should == '123abc' }
86
- end
87
-
88
- describe '#resume!' do
89
- describe "when the command is paused" do
90
- before do
91
- command.request!
92
- command.execute!
93
- command.paused!
94
- end
95
-
96
- it "should send its command properly" do
97
- mock_client.expects(:execute_command).with(command.resume_action, :call_id => '123abc', :component_id => 'abc123').returns true
98
- command.expects :resumed!
99
- command.resume!
100
- end
101
- end
102
-
103
- describe "when the command is not paused" do
104
- it "should raise an error" do
105
- lambda { command.resume! }.should raise_error(InvalidActionError, "Cannot resume a Say that is not paused.")
106
- end
107
- end
108
- end
109
-
110
- describe "#resumed!" do
111
- before do
112
- subject.request!
113
- subject.execute!
114
- subject.paused!
115
- subject.resumed!
116
- end
117
-
118
- its(:state_name) { should == :executing }
119
-
120
- it "should raise a StateMachine::InvalidTransition when received a second time" do
121
- lambda { subject.resumed! }.should raise_error(StateMachine::InvalidTransition)
122
- end
123
- end
124
-
125
- describe '#stop_action' do
126
- subject { command.stop_action }
127
-
128
- its(:to_xml) { should == '<stop xmlns="urn:xmpp:rayo:1"/>' }
129
- its(:component_id) { should == 'abc123' }
130
- its(:call_id) { should == '123abc' }
131
- end
132
-
133
- describe '#stop!' do
134
- describe "when the command is executing" do
135
- before do
136
- command.request!
137
- command.execute!
138
- end
139
-
140
- it "should send its command properly" do
141
- mock_client.expects(:execute_command).with(command.stop_action, :call_id => '123abc', :component_id => 'abc123')
142
- command.stop!
143
- end
144
- end
145
-
146
- describe "when the command is not executing" do
147
- it "should raise an error" do
148
- lambda { command.stop! }.should raise_error(InvalidActionError, "Cannot stop a Say that is not executing")
149
- end
150
- end
151
- end # #stop!
152
- end
153
- end
154
-
155
- describe Say::Complete::Success do
156
- let :stanza do
157
- <<-MESSAGE
158
- <complete xmlns='urn:xmpp:rayo:ext:1'>
159
- <success xmlns='urn:xmpp:tropo:say:complete:1' />
160
- </complete>
161
- MESSAGE
162
- end
163
-
164
- subject { RayoNode.import(parse_stanza(stanza).root).reason }
165
-
166
- it { should be_instance_of Say::Complete::Success }
167
-
168
- its(:name) { should == :success }
169
- end
170
- end
171
- end
172
- end # Punchblock
@@ -1,154 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Punchblock
4
- module Component
5
- module Tropo
6
- describe Transfer do
7
- it 'registers itself' do
8
- RayoNode.class_from_registration(:transfer, 'urn:xmpp:tropo:transfer:1').should == Transfer
9
- end
10
-
11
- describe 'when setting options in initializer' do
12
- subject do
13
- Transfer.new :to => 'tel:+14045551212',
14
- :from => 'tel:+14155551212',
15
- :terminator => '*',
16
- :timeout => 120000,
17
- :answer_on_media => true,
18
- :media => :direct,
19
- :ring => {:voice => 'allison', :text => "Welcome to Rayo", :url => "http://it.doesnt.matter.does.it/?"}
20
- end
21
-
22
- its(:to) { should == %w{tel:+14045551212} }
23
- its(:from) { should == 'tel:+14155551212' }
24
- its(:terminator) { should == '*' }
25
- its(:timeout) { should == 120000 }
26
- its(:answer_on_media) { should == true }
27
- its(:media) { should == :direct }
28
- its(:ring) { should == Transfer::Ring.new(:voice => 'allison', :text => "Welcome to Rayo", :url => "http://it.doesnt.matter.does.it/?") }
29
- end
30
-
31
- it_should_behave_like 'command_headers'
32
- end
33
-
34
- describe "actions" do
35
- let(:mock_client) { mock 'Client' }
36
- let(:command) { Transfer.new :to => 'tel:+14045551212', :from => 'tel:+14155551212' }
37
-
38
- before do
39
- command.component_id = 'abc123'
40
- command.call_id = '123abc'
41
- command.client = mock_client
42
- end
43
-
44
- describe '#stop_action' do
45
- subject { command.stop_action }
46
-
47
- its(:to_xml) { should == '<stop xmlns="urn:xmpp:rayo:1"/>' }
48
- its(:component_id) { should == 'abc123' }
49
- its(:call_id) { should == '123abc' }
50
- end
51
-
52
- describe '#stop!' do
53
- describe "when the command is executing" do
54
- before do
55
- command.request!
56
- command.execute!
57
- end
58
-
59
- it "should send its command properly" do
60
- mock_client.expects(:execute_command).with(command.stop_action, :call_id => '123abc', :component_id => 'abc123')
61
- command.stop!
62
- end
63
- end
64
-
65
- describe "when the command is not executing" do
66
- it "should raise an error" do
67
- lambda { command.stop! }.should raise_error(InvalidActionError, "Cannot stop a Transfer that is not executing")
68
- end
69
- end
70
- end
71
- end
72
-
73
- describe Transfer::Complete::Success do
74
- let :stanza do
75
- <<-MESSAGE
76
- <complete xmlns='urn:xmpp:rayo:ext:1'>
77
- <success xmlns='urn:xmpp:tropo:transfer:complete:1' />
78
- </complete>
79
- MESSAGE
80
- end
81
-
82
- subject { RayoNode.import(parse_stanza(stanza).root).reason }
83
-
84
- it { should be_instance_of Transfer::Complete::Success }
85
-
86
- its(:name) { should == :success }
87
- end
88
-
89
- describe Transfer::Complete::Timeout do
90
- let :stanza do
91
- <<-MESSAGE
92
- <complete xmlns='urn:xmpp:rayo:ext:1'>
93
- <timeout xmlns='urn:xmpp:tropo:transfer:complete:1' />
94
- </complete>
95
- MESSAGE
96
- end
97
-
98
- subject { RayoNode.import(parse_stanza(stanza).root).reason }
99
-
100
- it { should be_instance_of Transfer::Complete::Timeout }
101
-
102
- its(:name) { should == :timeout }
103
- end
104
-
105
- describe Transfer::Complete::Terminator do
106
- let :stanza do
107
- <<-MESSAGE
108
- <complete xmlns='urn:xmpp:rayo:ext:1'>
109
- <terminator xmlns='urn:xmpp:tropo:transfer:complete:1' />
110
- </complete>
111
- MESSAGE
112
- end
113
-
114
- subject { RayoNode.import(parse_stanza(stanza).root).reason }
115
-
116
- it { should be_instance_of Transfer::Complete::Terminator }
117
-
118
- its(:name) { should == :terminator }
119
- end
120
-
121
- describe Transfer::Complete::Busy do
122
- let :stanza do
123
- <<-MESSAGE
124
- <complete xmlns='urn:xmpp:rayo:ext:1'>
125
- <busy xmlns='urn:xmpp:tropo:transfer:complete:1' />
126
- </complete>
127
- MESSAGE
128
- end
129
-
130
- subject { RayoNode.import(parse_stanza(stanza).root).reason }
131
-
132
- it { should be_instance_of Transfer::Complete::Busy }
133
-
134
- its(:name) { should == :busy }
135
- end
136
-
137
- describe Transfer::Complete::Reject do
138
- let :stanza do
139
- <<-MESSAGE
140
- <complete xmlns='urn:xmpp:rayo:ext:1'>
141
- <reject xmlns='urn:xmpp:tropo:transfer:complete:1' />
142
- </complete>
143
- MESSAGE
144
- end
145
-
146
- subject { RayoNode.import(parse_stanza(stanza).root).reason }
147
-
148
- it { should be_instance_of Transfer::Complete::Reject }
149
-
150
- its(:name) { should == :reject }
151
- end
152
- end
153
- end
154
- end # Punchblock