adhearsion 2.5.4 → 2.6.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.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/CHANGELOG.md +15 -0
- data/README.markdown +2 -1
- data/Rakefile +1 -6
- data/adhearsion.gemspec +4 -3
- data/features/cli_daemon.feature +2 -4
- data/features/cli_restart.feature +14 -5
- data/features/cli_start.feature +0 -2
- data/features/cli_stop.feature +15 -6
- data/lib/adhearsion.rb +21 -23
- data/lib/adhearsion/call.rb +49 -5
- data/lib/adhearsion/call_controller.rb +29 -11
- data/lib/adhearsion/call_controller/dial.rb +21 -9
- data/lib/adhearsion/call_controller/menu_dsl.rb +12 -12
- data/lib/adhearsion/call_controller/menu_dsl/array_match_calculator.rb +1 -1
- data/lib/adhearsion/call_controller/menu_dsl/fixnum_match_calculator.rb +1 -0
- data/lib/adhearsion/call_controller/menu_dsl/string_match_calculator.rb +1 -1
- data/lib/adhearsion/call_controller/output.rb +36 -7
- data/lib/adhearsion/call_controller/output/abstract_player.rb +4 -0
- data/lib/adhearsion/call_controller/record.rb +1 -0
- data/lib/adhearsion/cli_commands/ahn_command.rb +7 -4
- data/lib/adhearsion/cli_commands/plugin_command.rb +2 -0
- data/lib/adhearsion/generators.rb +2 -4
- data/lib/adhearsion/generators/app/templates/simon_game_spec.rb +20 -20
- data/lib/adhearsion/initializer.rb +2 -2
- data/lib/adhearsion/plugin.rb +6 -6
- data/lib/adhearsion/punchblock_plugin.rb +3 -4
- data/lib/adhearsion/punchblock_plugin/initializer.rb +2 -1
- data/lib/adhearsion/router.rb +7 -7
- data/lib/adhearsion/router/route.rb +10 -4
- data/lib/adhearsion/rspec.rb +2 -0
- data/lib/adhearsion/version.rb +1 -1
- data/spec/adhearsion/call_controller/dial_spec.rb +589 -557
- data/spec/adhearsion/call_controller/input_spec.rb +91 -91
- data/spec/adhearsion/call_controller/menu_dsl/array_match_calculator_spec.rb +29 -29
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_collection_spec.rb +6 -6
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_spec.rb +19 -19
- data/spec/adhearsion/call_controller/menu_dsl/fixnum_match_calculator_spec.rb +6 -6
- data/spec/adhearsion/call_controller/menu_dsl/match_calculator_spec.rb +1 -1
- data/spec/adhearsion/call_controller/menu_dsl/menu_builder_spec.rb +21 -17
- data/spec/adhearsion/call_controller/menu_dsl/menu_spec.rb +96 -83
- data/spec/adhearsion/call_controller/menu_dsl/range_match_calculator_spec.rb +5 -5
- data/spec/adhearsion/call_controller/menu_dsl/string_match_calculator_spec.rb +9 -9
- data/spec/adhearsion/call_controller/output/async_player_spec.rb +14 -4
- data/spec/adhearsion/call_controller/output/formatter_spec.rb +14 -14
- data/spec/adhearsion/call_controller/output/player_spec.rb +15 -5
- data/spec/adhearsion/call_controller/output_spec.rb +126 -78
- data/spec/adhearsion/call_controller/record_spec.rb +38 -26
- data/spec/adhearsion/call_controller/utility_spec.rb +11 -11
- data/spec/adhearsion/call_controller_spec.rb +176 -136
- data/spec/adhearsion/call_spec.rb +443 -218
- data/spec/adhearsion/calls_spec.rb +33 -33
- data/spec/adhearsion/configuration_spec.rb +61 -61
- data/spec/adhearsion/console_spec.rb +29 -29
- data/spec/adhearsion/events_spec.rb +14 -14
- data/spec/adhearsion/generators_spec.rb +1 -1
- data/spec/adhearsion/initializer_spec.rb +42 -42
- data/spec/adhearsion/logging_spec.rb +33 -33
- data/spec/adhearsion/outbound_call_spec.rb +69 -55
- data/spec/adhearsion/plugin_spec.rb +53 -44
- data/spec/adhearsion/process_spec.rb +21 -21
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +68 -52
- data/spec/adhearsion/punchblock_plugin_spec.rb +6 -6
- data/spec/adhearsion/router/evented_route_spec.rb +2 -2
- data/spec/adhearsion/router/openended_route_spec.rb +9 -9
- data/spec/adhearsion/router/route_spec.rb +61 -31
- data/spec/adhearsion/router/unaccepting_route_spec.rb +13 -13
- data/spec/adhearsion/router_spec.rb +47 -33
- data/spec/adhearsion/statistics/dump_spec.rb +6 -6
- data/spec/adhearsion/statistics_spec.rb +9 -9
- data/spec/adhearsion_spec.rb +23 -20
- data/spec/spec_helper.rb +3 -6
- data/spec/support/call_controller_test_helpers.rb +7 -7
- data/spec/support/initializer_stubs.rb +1 -1
- data/spec/support/punchblock_mocks.rb +1 -1
- metadata +22 -10
- data/features/support/utils.rb +0 -9
@@ -7,53 +7,53 @@ module Adhearsion
|
|
7
7
|
module MenuDSL
|
8
8
|
describe CalculatedMatch do
|
9
9
|
it "should make accessible the context name" do
|
10
|
-
CalculatedMatch.new(:match_payload => :foobar).match_payload.
|
10
|
+
expect(CalculatedMatch.new(:match_payload => :foobar).match_payload).to be :foobar
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should make accessible the original pattern" do
|
14
|
-
CalculatedMatch.new(:pattern => :something).pattern.
|
14
|
+
expect(CalculatedMatch.new(:pattern => :something).pattern).to be :something
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should make accessible the matched query" do
|
18
|
-
CalculatedMatch.new(:query => 123).query.
|
18
|
+
expect(CalculatedMatch.new(:query => 123).query).to be 123
|
19
19
|
end
|
20
20
|
|
21
21
|
it "#type_of_match should return :exact, :potential, or nil" do
|
22
|
-
CalculatedMatch.new(:potential_matches => [1]).type_of_match.
|
23
|
-
CalculatedMatch.new(:exact_matches => [3,3]).type_of_match.
|
24
|
-
CalculatedMatch.new(:exact_matches => [8,3], :potential_matches => [0,9]).type_of_match.
|
22
|
+
expect(CalculatedMatch.new(:potential_matches => [1]).type_of_match).to be :potential
|
23
|
+
expect(CalculatedMatch.new(:exact_matches => [3,3]).type_of_match).to be :exact
|
24
|
+
expect(CalculatedMatch.new(:exact_matches => [8,3], :potential_matches => [0,9]).type_of_match).to be :exact
|
25
25
|
end
|
26
26
|
|
27
27
|
it "#exact_match? should return true if the match was exact" do
|
28
|
-
CalculatedMatch.new(:exact_matches => [0,3,5]).exact_match
|
28
|
+
expect(CalculatedMatch.new(:exact_matches => [0,3,5]).exact_match?).to be true
|
29
29
|
end
|
30
30
|
|
31
31
|
it "#potential_match? should return true if the match was exact" do
|
32
|
-
CalculatedMatch.new(:potential_matches => [88,99,77]).potential_match
|
32
|
+
expect(CalculatedMatch.new(:potential_matches => [88,99,77]).potential_match?).to be true
|
33
33
|
end
|
34
34
|
|
35
35
|
it "#failed_match? should return false if the match was exact" do
|
36
|
-
CalculatedMatch.new(:potential_matches => [88,99,77]).failed_match
|
36
|
+
expect(CalculatedMatch.new(:potential_matches => [88,99,77]).failed_match?).to be false
|
37
37
|
end
|
38
38
|
|
39
39
|
it "#exact_matches should return an array of exact matches" do
|
40
|
-
CalculatedMatch.new(:exact_matches => [0,3,5]).exact_matches.
|
40
|
+
expect(CalculatedMatch.new(:exact_matches => [0,3,5]).exact_matches).to eq([0,3,5])
|
41
41
|
end
|
42
42
|
|
43
43
|
it "#potential_matches should return an array of potential matches" do
|
44
|
-
CalculatedMatch.new(:potential_matches => [88,99,77]).potential_matches.
|
44
|
+
expect(CalculatedMatch.new(:potential_matches => [88,99,77]).potential_matches).to eq([88,99,77])
|
45
45
|
end
|
46
46
|
|
47
47
|
it "::failed_match! should return a match that *really* failed" do
|
48
48
|
failure = CalculatedMatch.failed_match! 10..20, 30, :match_payload_does_not_matter
|
49
|
-
failure.exact_match
|
50
|
-
failure.potential_match
|
51
|
-
failure.failed_match
|
52
|
-
failure.type_of_match.
|
53
|
-
|
54
|
-
failure.match_payload.
|
55
|
-
failure.pattern.
|
56
|
-
failure.query.
|
49
|
+
expect(failure.exact_match?).not_to be true
|
50
|
+
expect(failure.potential_match?).not_to be true
|
51
|
+
expect(failure.failed_match?).to be true
|
52
|
+
expect(failure.type_of_match).to be nil
|
53
|
+
|
54
|
+
expect(failure.match_payload).to be :match_payload_does_not_matter
|
55
|
+
expect(failure.pattern).to eq(10..20)
|
56
|
+
expect(failure.query).to eq(30)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -11,27 +11,27 @@ module Adhearsion
|
|
11
11
|
it "a potential match scenario" do
|
12
12
|
calculator = FixnumMatchCalculator.new(444, match_payload)
|
13
13
|
match = calculator.match '4'
|
14
|
-
match.
|
15
|
-
match.
|
16
|
-
match.potential_matches.
|
14
|
+
expect(match).to be_potential_match
|
15
|
+
expect(match).not_to be_exact_match
|
16
|
+
expect(match.potential_matches).to eq([444])
|
17
17
|
end
|
18
18
|
|
19
19
|
it "a multi-digit exact match scenario" do
|
20
20
|
calculator = FixnumMatchCalculator.new(5555, match_payload)
|
21
21
|
match = calculator.match '5555'
|
22
|
-
match.
|
22
|
+
expect(match).to be_exact_match
|
23
23
|
end
|
24
24
|
|
25
25
|
it "a single-digit exact match scenario" do
|
26
26
|
calculator = FixnumMatchCalculator.new(1, match_payload)
|
27
27
|
match = calculator.match '1'
|
28
|
-
match.
|
28
|
+
expect(match).to be_exact_match
|
29
29
|
end
|
30
30
|
|
31
31
|
it "the context name given to the calculator should be passed on the CalculatedMatch" do
|
32
32
|
match_payload = :icanhascheezburger
|
33
33
|
calculator = FixnumMatchCalculator.new(1337, match_payload)
|
34
|
-
calculator.match('1337').match_payload.
|
34
|
+
expect(calculator.match('1337').match_payload).to be match_payload
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -8,7 +8,7 @@ module Adhearsion
|
|
8
8
|
describe MatchCalculator do
|
9
9
|
describe ".build_with_pattern" do
|
10
10
|
it "should return an appropriate subclass instance based on the pattern's class" do
|
11
|
-
MatchCalculator.build_with_pattern(1..2, :main).
|
11
|
+
expect(MatchCalculator.build_with_pattern(1..2, :main)).to be_an_instance_of RangeMatchCalculator
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -7,11 +7,11 @@ module Adhearsion
|
|
7
7
|
module MenuDSL
|
8
8
|
|
9
9
|
describe MenuBuilder do
|
10
|
-
subject{ MenuDSL::MenuBuilder.new }
|
10
|
+
subject { MenuDSL::MenuBuilder.new }
|
11
11
|
|
12
12
|
describe "#build" do
|
13
13
|
it "sets the context and instance_eval's the block" do
|
14
|
-
subject.
|
14
|
+
expect(subject).to receive(:foo).with(:bar)
|
15
15
|
subject.build do
|
16
16
|
foo :bar
|
17
17
|
end
|
@@ -24,7 +24,7 @@ module Adhearsion
|
|
24
24
|
subject.build do
|
25
25
|
doo = foo
|
26
26
|
end
|
27
|
-
doo.
|
27
|
+
expect(doo).to eq(:bar)
|
28
28
|
end
|
29
29
|
end#build
|
30
30
|
|
@@ -44,25 +44,27 @@ module Adhearsion
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "creates a pattern based on a payload" do
|
47
|
-
MenuDSL::MatchCalculator.
|
47
|
+
expect(MenuDSL::MatchCalculator).to receive(:build_with_pattern).with("1", Object)
|
48
48
|
subject.match "1", Object
|
49
49
|
end
|
50
50
|
|
51
51
|
it "creates a pattern based on a block" do
|
52
|
-
MenuDSL::MatchCalculator.
|
52
|
+
expect(MenuDSL::MatchCalculator).to receive(:build_with_pattern).with("1", nil, &match_block)
|
53
53
|
subject.match("1", &match_block)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "creates multiple patterns if multiple arguments are passed in" do
|
57
|
-
MenuDSL::MatchCalculator.
|
58
|
-
MenuDSL::MatchCalculator.
|
57
|
+
expect(MenuDSL::MatchCalculator).to receive(:build_with_pattern).with(1, Object)
|
58
|
+
expect(MenuDSL::MatchCalculator).to receive(:build_with_pattern).with(2, Object)
|
59
59
|
subject.match(1, 2, Object)
|
60
60
|
end
|
61
61
|
end#match
|
62
62
|
|
63
63
|
describe "#has_matchers?" do
|
64
64
|
context "with no matchers specified" do
|
65
|
-
|
65
|
+
describe '#has_matchers?' do
|
66
|
+
it { expect(subject.has_matchers?).to be false }
|
67
|
+
end
|
66
68
|
end
|
67
69
|
|
68
70
|
context "with at least one matcher specified" do
|
@@ -70,7 +72,9 @@ module Adhearsion
|
|
70
72
|
subject.match(1) {}
|
71
73
|
end
|
72
74
|
|
73
|
-
|
75
|
+
describe '#has_matchers?' do
|
76
|
+
it { expect(subject.has_matchers?).to be true }
|
77
|
+
end
|
74
78
|
end
|
75
79
|
end
|
76
80
|
|
@@ -78,9 +82,9 @@ module Adhearsion
|
|
78
82
|
let(:expected_pattern) { MenuDSL::MatchCalculator.build_with_pattern("1", Object) }
|
79
83
|
|
80
84
|
it "returns the generated patterns" do
|
81
|
-
MenuDSL::MatchCalculator.
|
85
|
+
expect(MenuDSL::MatchCalculator).to receive(:build_with_pattern).with("1", Object).at_least(:once).and_return(expected_pattern)
|
82
86
|
subject.match("1", Object)
|
83
|
-
subject.weighted_match_calculators.
|
87
|
+
expect(subject.weighted_match_calculators).to eq([expected_pattern])
|
84
88
|
end
|
85
89
|
end#weighted_match_calculators
|
86
90
|
|
@@ -93,7 +97,7 @@ module Adhearsion
|
|
93
97
|
|
94
98
|
it "sets the invalid callback" do
|
95
99
|
subject.invalid(&callback)
|
96
|
-
subject.menu_callbacks[:invalid].
|
100
|
+
expect(subject.menu_callbacks[:invalid]).to eq(callback)
|
97
101
|
end
|
98
102
|
end#invalid
|
99
103
|
|
@@ -106,7 +110,7 @@ module Adhearsion
|
|
106
110
|
|
107
111
|
it "sets the timeout callback" do
|
108
112
|
subject.timeout(&callback)
|
109
|
-
subject.menu_callbacks[:timeout].
|
113
|
+
expect(subject.menu_callbacks[:timeout]).to eq(callback)
|
110
114
|
end
|
111
115
|
end#timeout
|
112
116
|
|
@@ -119,7 +123,7 @@ module Adhearsion
|
|
119
123
|
|
120
124
|
it "sets the failure callback" do
|
121
125
|
subject.failure(&callback)
|
122
|
-
subject.menu_callbacks[:failure].
|
126
|
+
expect(subject.menu_callbacks[:failure]).to eq(callback)
|
123
127
|
end
|
124
128
|
end#failure
|
125
129
|
|
@@ -132,7 +136,7 @@ module Adhearsion
|
|
132
136
|
|
133
137
|
it "sets the invalid callback" do
|
134
138
|
subject.validator(&callback)
|
135
|
-
subject.menu_callbacks[:validator].
|
139
|
+
expect(subject.menu_callbacks[:validator]).to eq(callback)
|
136
140
|
end
|
137
141
|
end#invalid
|
138
142
|
|
@@ -143,14 +147,14 @@ module Adhearsion
|
|
143
147
|
bar = baz
|
144
148
|
end
|
145
149
|
subject.execute_hook_for(:invalid, "1")
|
146
|
-
bar.
|
150
|
+
expect(bar).to eq("1")
|
147
151
|
end
|
148
152
|
end#execute_hook_for
|
149
153
|
|
150
154
|
describe "#calculate_matches_for" do
|
151
155
|
it "returns a calculated match collection" do
|
152
156
|
subject.match("1", Object)
|
153
|
-
subject.calculate_matches_for("1").
|
157
|
+
expect(subject.calculate_matches_for("1")).to be_a CalculatedMatchCollection
|
154
158
|
end
|
155
159
|
end
|
156
160
|
|
@@ -11,11 +11,14 @@ module Adhearsion
|
|
11
11
|
subject { Menu.new(options) }
|
12
12
|
|
13
13
|
describe "#initialize" do
|
14
|
-
|
14
|
+
describe '#tries_count' do
|
15
|
+
subject { super().tries_count }
|
16
|
+
it { is_expected.to eq(0) }
|
17
|
+
end
|
15
18
|
|
16
19
|
context 'when no timeout is set' do
|
17
20
|
it "should have the default timeout" do
|
18
|
-
subject.timeout.
|
21
|
+
expect(subject.timeout).to eq(5)
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
@@ -25,13 +28,13 @@ module Adhearsion
|
|
25
28
|
}
|
26
29
|
|
27
30
|
it 'should have the passed timeout' do
|
28
|
-
subject.timeout.
|
31
|
+
expect(subject.timeout).to eq(20)
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
32
35
|
context 'when no max number of tries is set' do
|
33
36
|
it "should have the default max number of tries" do
|
34
|
-
subject.max_number_of_tries.
|
37
|
+
expect(subject.max_number_of_tries).to eq(1)
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
@@ -41,17 +44,17 @@ module Adhearsion
|
|
41
44
|
}
|
42
45
|
|
43
46
|
it 'should have the passed max number of tries' do
|
44
|
-
subject.max_number_of_tries.
|
47
|
+
expect(subject.max_number_of_tries).to eq(3)
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
48
51
|
context 'when no terminator is set' do
|
49
52
|
it "should have no terminator" do
|
50
|
-
subject.terminator.
|
53
|
+
expect(subject.terminator).to eq('')
|
51
54
|
end
|
52
55
|
|
53
56
|
it 'should not validate successfully' do
|
54
|
-
|
57
|
+
expect { subject.validate }.to raise_error(Menu::InvalidStructureError)
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
@@ -61,25 +64,25 @@ module Adhearsion
|
|
61
64
|
}
|
62
65
|
|
63
66
|
it 'should have the passed terminator' do
|
64
|
-
subject.terminator.
|
67
|
+
expect(subject.terminator).to eq('3')
|
65
68
|
end
|
66
69
|
|
67
70
|
it 'should validate(:basic) successfully' do
|
68
|
-
subject.validate(:basic).
|
71
|
+
expect(subject.validate(:basic)).to be true
|
69
72
|
end
|
70
73
|
|
71
74
|
it 'should not validate successfully' do
|
72
|
-
|
75
|
+
expect { subject.validate }.to raise_error(Menu::InvalidStructureError)
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
76
79
|
context 'when no limit is set' do
|
77
80
|
it "should have no limit" do
|
78
|
-
subject.limit.
|
81
|
+
expect(subject.limit).to be nil
|
79
82
|
end
|
80
83
|
|
81
84
|
it 'should not validate successfully' do
|
82
|
-
|
85
|
+
expect { subject.validate }.to raise_error(Menu::InvalidStructureError)
|
83
86
|
end
|
84
87
|
end
|
85
88
|
|
@@ -89,21 +92,21 @@ module Adhearsion
|
|
89
92
|
}
|
90
93
|
|
91
94
|
it 'should have the passed limit' do
|
92
|
-
subject.limit.
|
95
|
+
expect(subject.limit).to eq(3)
|
93
96
|
end
|
94
97
|
|
95
98
|
it 'should validate(:basic) successfully' do
|
96
|
-
subject.validate(:basic).
|
99
|
+
expect(subject.validate(:basic)).to be true
|
97
100
|
end
|
98
101
|
|
99
102
|
it 'should not validate successfully' do
|
100
|
-
|
103
|
+
expect { subject.validate }.to raise_error(Menu::InvalidStructureError)
|
101
104
|
end
|
102
105
|
end
|
103
106
|
|
104
107
|
context 'when no interruptibility is set' do
|
105
108
|
it "should be interruptible" do
|
106
|
-
subject.interruptible.
|
109
|
+
expect(subject.interruptible).to be true
|
107
110
|
end
|
108
111
|
end
|
109
112
|
|
@@ -113,13 +116,13 @@ module Adhearsion
|
|
113
116
|
}
|
114
117
|
|
115
118
|
it 'should be interruptible' do
|
116
|
-
subject.interruptible.
|
119
|
+
expect(subject.interruptible).to be false
|
117
120
|
end
|
118
121
|
end
|
119
122
|
|
120
123
|
context 'when renderer is not specified' do
|
121
124
|
it 'should have a nil renderer' do
|
122
|
-
subject.renderer.
|
125
|
+
expect(subject.renderer).to be nil
|
123
126
|
end
|
124
127
|
end
|
125
128
|
|
@@ -129,7 +132,7 @@ module Adhearsion
|
|
129
132
|
}
|
130
133
|
|
131
134
|
it 'should have the specified renderer' do
|
132
|
-
subject.renderer.
|
135
|
+
expect(subject.renderer).to eq(:native)
|
133
136
|
end
|
134
137
|
end
|
135
138
|
|
@@ -141,21 +144,24 @@ module Adhearsion
|
|
141
144
|
end
|
142
145
|
|
143
146
|
it 'should validate successfully' do
|
144
|
-
subject.validate.
|
147
|
+
expect(subject.validate).to be true
|
145
148
|
end
|
146
149
|
|
147
150
|
it 'should not validate(:basic) successfully' do
|
148
|
-
|
151
|
+
expect { subject.validate :basic }.to raise_error(Menu::InvalidStructureError)
|
149
152
|
end
|
150
153
|
end
|
151
154
|
|
152
155
|
context 'menu builder setup' do
|
153
|
-
|
156
|
+
describe '#builder' do
|
157
|
+
subject { super().builder }
|
158
|
+
it { is_expected.to be_a MenuBuilder }
|
159
|
+
end
|
154
160
|
|
155
161
|
it "should evaluate the block on the builder object" do
|
156
162
|
mock_menu_builder = MenuBuilder.new
|
157
|
-
MenuBuilder.
|
158
|
-
mock_menu_builder.
|
163
|
+
expect(MenuBuilder).to receive(:new).and_return(mock_menu_builder)
|
164
|
+
expect(mock_menu_builder).to receive(:match).once.with(1)
|
159
165
|
Menu.new { match 1 }
|
160
166
|
end
|
161
167
|
end
|
@@ -163,41 +169,48 @@ module Adhearsion
|
|
163
169
|
end # describe #initialize
|
164
170
|
|
165
171
|
describe "#digit_buffer" do
|
166
|
-
|
167
|
-
|
172
|
+
describe '#digit_buffer' do
|
173
|
+
subject { super().digit_buffer }
|
174
|
+
it { is_expected.to be_a Menu::ClearableStringBuffer }
|
175
|
+
end
|
176
|
+
|
177
|
+
describe '#digit_buffer' do
|
178
|
+
subject { super().digit_buffer }
|
179
|
+
it { is_expected.to eq("") }
|
180
|
+
end
|
168
181
|
end
|
169
182
|
|
170
183
|
describe "#<<" do
|
171
184
|
it "should add a digit to the buffer" do
|
172
185
|
subject << 'a'
|
173
|
-
subject.digit_buffer.
|
174
|
-
subject.result.
|
186
|
+
expect(subject.digit_buffer).to eq('a')
|
187
|
+
expect(subject.result).to eq('a')
|
175
188
|
end
|
176
189
|
end
|
177
190
|
|
178
191
|
describe "#digit_buffer_empty?" do
|
179
192
|
it "returns true if buffer is empty" do
|
180
|
-
subject.digit_buffer_empty
|
193
|
+
expect(subject.digit_buffer_empty?).to eq(true)
|
181
194
|
end
|
182
195
|
|
183
196
|
it "returns false if buffer is not empty" do
|
184
197
|
subject << 1
|
185
|
-
subject.digit_buffer_empty
|
198
|
+
expect(subject.digit_buffer_empty?).to eq(false)
|
186
199
|
end
|
187
200
|
end
|
188
201
|
|
189
202
|
describe "#digit_buffer_string" do
|
190
203
|
it "returns the digit buffer as a string" do
|
191
204
|
subject << 1
|
192
|
-
subject.digit_buffer_string.
|
205
|
+
expect(subject.digit_buffer_string).to eq("1")
|
193
206
|
end
|
194
207
|
end
|
195
208
|
|
196
209
|
describe "#should_continue?" do
|
197
210
|
it "returns true if the number of tries is less than the maximum" do
|
198
|
-
subject.max_number_of_tries.
|
199
|
-
subject.tries_count.
|
200
|
-
subject.should_continue
|
211
|
+
expect(subject.max_number_of_tries).to eq(1)
|
212
|
+
expect(subject.tries_count).to eq(0)
|
213
|
+
expect(subject.should_continue?).to eq(true)
|
201
214
|
end
|
202
215
|
end
|
203
216
|
|
@@ -205,16 +218,16 @@ module Adhearsion
|
|
205
218
|
it "increments tries and clears the digit buffer" do
|
206
219
|
subject << 1
|
207
220
|
subject.restart!
|
208
|
-
subject.tries_count.
|
209
|
-
subject.digit_buffer_empty
|
221
|
+
expect(subject.tries_count).to eq(1)
|
222
|
+
expect(subject.digit_buffer_empty?).to eq(true)
|
210
223
|
end
|
211
224
|
end
|
212
225
|
|
213
226
|
describe "#execute_invalid_hook" do
|
214
227
|
it "calls the builder's execute_hook_for with :invalid" do
|
215
228
|
mock_menu_builder = MenuBuilder.new
|
216
|
-
MenuBuilder.
|
217
|
-
mock_menu_builder.
|
229
|
+
expect(MenuBuilder).to receive(:new).and_return(mock_menu_builder)
|
230
|
+
expect(mock_menu_builder).to receive(:execute_hook_for).with(:invalid, "")
|
218
231
|
menu_instance = Menu.new
|
219
232
|
menu_instance.execute_invalid_hook
|
220
233
|
end
|
@@ -223,8 +236,8 @@ module Adhearsion
|
|
223
236
|
describe "#execute_timeout_hook" do
|
224
237
|
it "calls the builder's execute_hook_for with :timeout" do
|
225
238
|
mock_menu_builder = MenuBuilder.new
|
226
|
-
MenuBuilder.
|
227
|
-
mock_menu_builder.
|
239
|
+
expect(MenuBuilder).to receive(:new).and_return(mock_menu_builder)
|
240
|
+
expect(mock_menu_builder).to receive(:execute_hook_for).with(:timeout, "")
|
228
241
|
menu_instance = Menu.new
|
229
242
|
menu_instance.execute_timeout_hook
|
230
243
|
end
|
@@ -233,8 +246,8 @@ module Adhearsion
|
|
233
246
|
describe "#execute_failure_hook" do
|
234
247
|
it "calls the builder's execute_hook_for with :failure" do
|
235
248
|
mock_menu_builder = MenuBuilder.new
|
236
|
-
MenuBuilder.
|
237
|
-
mock_menu_builder.
|
249
|
+
expect(MenuBuilder).to receive(:new).and_return(mock_menu_builder)
|
250
|
+
expect(mock_menu_builder).to receive(:execute_hook_for).with(:failure, "")
|
238
251
|
menu_instance = Menu.new
|
239
252
|
menu_instance.execute_failure_hook
|
240
253
|
end
|
@@ -243,8 +256,8 @@ module Adhearsion
|
|
243
256
|
describe "#execute_validator_hook" do
|
244
257
|
it "calls the builder's execute_hook_for with :validator" do
|
245
258
|
mock_menu_builder = MenuBuilder.new
|
246
|
-
MenuBuilder.
|
247
|
-
mock_menu_builder.
|
259
|
+
expect(MenuBuilder).to receive(:new).and_return(mock_menu_builder)
|
260
|
+
expect(mock_menu_builder).to receive(:execute_hook_for).with(:validator, "")
|
248
261
|
menu_instance = Menu.new
|
249
262
|
menu_instance.execute_validator_hook
|
250
263
|
end
|
@@ -269,44 +282,44 @@ module Adhearsion
|
|
269
282
|
}
|
270
283
|
|
271
284
|
it "returns a MenuGetAnotherDigitOrTimeout if the digit buffer is empty" do
|
272
|
-
subject.continue.
|
273
|
-
menu_instance.status.
|
285
|
+
expect(subject.continue).to be_a Menu::MenuGetAnotherDigitOrTimeout
|
286
|
+
expect(menu_instance.status).to be nil
|
274
287
|
end
|
275
288
|
|
276
289
|
it "asks for another digit if it has potential matches" do
|
277
290
|
menu_instance << 2
|
278
|
-
menu_instance.continue.
|
279
|
-
menu_instance.status.
|
291
|
+
expect(menu_instance.continue).to be_a Menu::MenuGetAnotherDigitOrTimeout
|
292
|
+
expect(menu_instance.status).to eq(:potential)
|
280
293
|
end
|
281
294
|
|
282
295
|
it "returns a MenuResultInvalid if there are no matches" do
|
283
296
|
menu_instance << 9
|
284
|
-
menu_instance.continue.
|
285
|
-
menu_instance.status.
|
297
|
+
expect(menu_instance.continue).to be_a Menu::MenuResultInvalid
|
298
|
+
expect(menu_instance.status).to eq(:invalid)
|
286
299
|
end
|
287
300
|
|
288
301
|
it "returns the first exact match when it has exact and potentials" do
|
289
302
|
menu_instance << 3
|
290
303
|
menu_result = menu_instance.continue
|
291
|
-
menu_result.
|
292
|
-
menu_result.match_object.
|
293
|
-
menu_result.new_extension.
|
294
|
-
menu_instance.status.
|
304
|
+
expect(menu_result).to be_a Menu::MenuGetAnotherDigitOrFinish
|
305
|
+
expect(menu_result.match_object).to eq(MockControllerB)
|
306
|
+
expect(menu_result.new_extension).to eq("3")
|
307
|
+
expect(menu_instance.status).to eq(:multi_matched)
|
295
308
|
end
|
296
309
|
|
297
310
|
it "returns a MenuResultFound if it has exact matches" do
|
298
311
|
menu_instance << 6
|
299
312
|
menu_result = menu_instance.continue
|
300
|
-
menu_result.
|
301
|
-
menu_instance.status.
|
313
|
+
expect(menu_result).to be_a Menu::MenuResultFound
|
314
|
+
expect(menu_instance.status).to eq(:matched)
|
302
315
|
end
|
303
316
|
|
304
317
|
it "returns the first exact match when it has only exact matches" do
|
305
318
|
menu_instance << 6
|
306
319
|
menu_result = menu_instance.continue
|
307
|
-
menu_result.
|
308
|
-
menu_result.match_object.match_payload.
|
309
|
-
menu_result.match_object.pattern.to_s.
|
320
|
+
expect(menu_result).to be_a Menu::MenuResultFound
|
321
|
+
expect(menu_result.match_object.match_payload).to eq(MockControllerC)
|
322
|
+
expect(menu_result.match_object.pattern.to_s).to eq("6")
|
310
323
|
end
|
311
324
|
|
312
325
|
context "with no matchers" do
|
@@ -318,13 +331,13 @@ module Adhearsion
|
|
318
331
|
it "buffers until the terminator is issued then returns a MenuTerminated and sets the status to :terminated, removing the terminator from the buffer" do
|
319
332
|
menu_instance << 2
|
320
333
|
menu_instance << 4
|
321
|
-
menu_instance.continue.
|
322
|
-
menu_instance.status.
|
334
|
+
expect(menu_instance.continue).to be_a Menu::MenuGetAnotherDigitOrTimeout
|
335
|
+
expect(menu_instance.status).to eq(:potential)
|
323
336
|
menu_instance << '#'
|
324
|
-
menu_instance.continue.
|
325
|
-
menu_instance.continue.
|
326
|
-
menu_instance.status.
|
327
|
-
menu_instance.result.
|
337
|
+
expect(menu_instance.continue).to be_a Menu::MenuTerminated
|
338
|
+
expect(menu_instance.continue).to be_a Menu::MenuResultDone
|
339
|
+
expect(menu_instance.status).to eq(:terminated)
|
340
|
+
expect(menu_instance.result).to eq('24')
|
328
341
|
end
|
329
342
|
end
|
330
343
|
|
@@ -334,13 +347,13 @@ module Adhearsion
|
|
334
347
|
it "buffers until the limit is reached, then returns MenuLimitReached and sets the status to :limited" do
|
335
348
|
menu_instance << 2
|
336
349
|
menu_instance << 4
|
337
|
-
menu_instance.continue.
|
338
|
-
menu_instance.status.
|
350
|
+
expect(menu_instance.continue).to be_a Menu::MenuGetAnotherDigitOrTimeout
|
351
|
+
expect(menu_instance.status).to eq(:potential)
|
339
352
|
menu_instance << 2
|
340
|
-
menu_instance.continue.
|
341
|
-
menu_instance.continue.
|
342
|
-
menu_instance.status.
|
343
|
-
menu_instance.result.
|
353
|
+
expect(menu_instance.continue).to be_a Menu::MenuLimitReached
|
354
|
+
expect(menu_instance.continue).to be_a Menu::MenuResultDone
|
355
|
+
expect(menu_instance.status).to eq(:limited)
|
356
|
+
expect(menu_instance.result).to eq('242')
|
344
357
|
end
|
345
358
|
end
|
346
359
|
|
@@ -354,13 +367,13 @@ module Adhearsion
|
|
354
367
|
it "buffers until the validator returns true, then returns MenuValidatorTerminated and sets the status to :validator_terminated" do
|
355
368
|
menu_instance << 2
|
356
369
|
menu_instance << 4
|
357
|
-
menu_instance.continue.
|
358
|
-
menu_instance.status.
|
370
|
+
expect(menu_instance.continue).to be_a Menu::MenuGetAnotherDigitOrTimeout
|
371
|
+
expect(menu_instance.status).to eq(:potential)
|
359
372
|
menu_instance << 2
|
360
|
-
menu_instance.continue.
|
361
|
-
menu_instance.continue.
|
362
|
-
menu_instance.status.
|
363
|
-
menu_instance.result.
|
373
|
+
expect(menu_instance.continue).to be_a Menu::MenuValidatorTerminated
|
374
|
+
expect(menu_instance.continue).to be_a Menu::MenuResultDone
|
375
|
+
expect(menu_instance.status).to eq(:validator_terminated)
|
376
|
+
expect(menu_instance.result).to eq('242')
|
364
377
|
end
|
365
378
|
end
|
366
379
|
|
@@ -375,10 +388,10 @@ module Adhearsion
|
|
375
388
|
menu_instance << 2
|
376
389
|
menu_instance << 4
|
377
390
|
menu_instance << 2
|
378
|
-
menu_instance.continue.
|
379
|
-
menu_instance.continue.
|
380
|
-
menu_instance.status.
|
381
|
-
menu_instance.result.
|
391
|
+
expect(menu_instance.continue).to be_a Menu::MenuValidatorTerminated
|
392
|
+
expect(menu_instance.continue).to be_a Menu::MenuResultDone
|
393
|
+
expect(menu_instance.status).to eq(:validator_terminated)
|
394
|
+
expect(menu_instance.result).to eq('242')
|
382
395
|
end
|
383
396
|
end
|
384
397
|
end
|
@@ -391,13 +404,13 @@ module Adhearsion
|
|
391
404
|
it "adds a string to itself" do
|
392
405
|
subject << 'b'
|
393
406
|
subject << 'c'
|
394
|
-
subject.
|
407
|
+
expect(subject).to eq('bc')
|
395
408
|
end
|
396
409
|
|
397
410
|
it "clears itself" do
|
398
411
|
subject << 'a'
|
399
412
|
subject.clear!
|
400
|
-
subject.
|
413
|
+
expect(subject).to eq("")
|
401
414
|
end
|
402
415
|
end
|
403
416
|
|