adhearsion 2.6.4 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -9
- data/CHANGELOG.md +22 -7
- data/Gemfile +2 -0
- data/README.markdown +4 -5
- data/Rakefile +1 -2
- data/adhearsion.gemspec +19 -8
- data/features/cli_create.feature +19 -3
- data/features/step_definitions/cli_steps.rb +0 -11
- data/features/support/env.rb +3 -4
- data/lib/adhearsion.rb +48 -27
- data/lib/adhearsion/call.rb +34 -50
- data/lib/adhearsion/call_controller.rb +6 -12
- data/lib/adhearsion/call_controller/dial.rb +15 -53
- data/lib/adhearsion/call_controller/input.rb +39 -162
- data/lib/adhearsion/call_controller/input/ask_grammar_builder.rb +44 -0
- data/lib/adhearsion/call_controller/input/menu_builder.rb +136 -0
- data/lib/adhearsion/call_controller/input/prompt_builder.rb +78 -0
- data/lib/adhearsion/call_controller/input/result.rb +46 -0
- data/lib/adhearsion/call_controller/output.rb +48 -67
- data/lib/adhearsion/call_controller/output/abstract_player.rb +3 -3
- data/lib/adhearsion/call_controller/output/async_player.rb +3 -3
- data/lib/adhearsion/call_controller/output/player.rb +1 -1
- data/lib/adhearsion/call_controller/record.rb +23 -8
- data/lib/adhearsion/calls.rb +1 -1
- data/lib/adhearsion/cli_commands/ahn_command.rb +2 -65
- data/lib/adhearsion/cli_commands/thor_errors.rb +0 -6
- data/lib/adhearsion/configuration.rb +91 -39
- data/lib/adhearsion/core_ext/blather/stanza.rb +41 -0
- data/lib/adhearsion/core_ext/blather/stanza/presence.rb +13 -0
- data/lib/adhearsion/error.rb +5 -0
- data/lib/adhearsion/event.rb +21 -0
- data/lib/adhearsion/event/active_speaker.rb +11 -0
- data/lib/adhearsion/event/answered.rb +11 -0
- data/lib/adhearsion/event/asterisk.rb +10 -0
- data/lib/adhearsion/event/asterisk/ami.rb +34 -0
- data/lib/adhearsion/event/complete.rb +75 -0
- data/lib/adhearsion/event/dtmf.rb +11 -0
- data/lib/adhearsion/event/end.rb +22 -0
- data/lib/adhearsion/event/input_timers_started.rb +9 -0
- data/lib/adhearsion/event/joined.rb +17 -0
- data/lib/adhearsion/event/offer.rb +14 -0
- data/lib/adhearsion/event/ringing.rb +11 -0
- data/lib/adhearsion/event/started_speaking.rb +13 -0
- data/lib/adhearsion/event/stopped_speaking.rb +13 -0
- data/lib/adhearsion/event/unjoined.rb +17 -0
- data/lib/adhearsion/events.rb +47 -66
- data/lib/adhearsion/foundation.rb +0 -1
- data/lib/adhearsion/foundation/object.rb +0 -5
- data/lib/adhearsion/generators/app/app_generator.rb +4 -1
- data/lib/adhearsion/generators/app/templates/Gemfile.erb +2 -10
- data/lib/adhearsion/generators/app/templates/adhearsion.erb +9 -9
- data/lib/adhearsion/generators/app/templates/config.ru +7 -0
- data/lib/adhearsion/generators/app/templates/en.yml +4 -0
- data/lib/adhearsion/generators/app/templates/events.erb +2 -2
- data/lib/adhearsion/generators/app/templates/hello_world.wav +0 -0
- data/lib/adhearsion/generators/app/templates/simon_game.rb +2 -1
- data/lib/adhearsion/generators/app/templates/simon_game_spec.rb +2 -2
- data/lib/adhearsion/has_headers.rb +34 -0
- data/lib/adhearsion/http_server.rb +37 -0
- data/lib/adhearsion/initializer.rb +19 -153
- data/lib/adhearsion/logging.rb +6 -25
- data/lib/adhearsion/outbound_call.rb +5 -5
- data/lib/adhearsion/plugin.rb +1 -0
- data/lib/adhearsion/protocol_error.rb +26 -0
- data/lib/adhearsion/rayo.rb +30 -0
- data/lib/adhearsion/rayo/client.rb +62 -0
- data/lib/adhearsion/rayo/client/component_registry.rb +33 -0
- data/lib/adhearsion/rayo/command.rb +21 -0
- data/lib/adhearsion/rayo/command/accept.rb +16 -0
- data/lib/adhearsion/rayo/command/answer.rb +16 -0
- data/lib/adhearsion/rayo/command/dial.rb +57 -0
- data/lib/adhearsion/rayo/command/hangup.rb +16 -0
- data/lib/adhearsion/rayo/command/join.rb +43 -0
- data/lib/adhearsion/rayo/command/mute.rb +13 -0
- data/lib/adhearsion/rayo/command/redirect.rb +23 -0
- data/lib/adhearsion/rayo/command/reject.rb +40 -0
- data/lib/adhearsion/rayo/command/unjoin.rb +24 -0
- data/lib/adhearsion/rayo/command/unmute.rb +13 -0
- data/lib/adhearsion/rayo/command_node.rb +47 -0
- data/lib/adhearsion/rayo/component.rb +21 -0
- data/lib/adhearsion/rayo/component/asterisk.rb +13 -0
- data/lib/adhearsion/rayo/component/asterisk/agi.rb +14 -0
- data/lib/adhearsion/rayo/component/asterisk/agi/command.rb +46 -0
- data/lib/adhearsion/rayo/component/asterisk/ami.rb +14 -0
- data/lib/adhearsion/rayo/component/asterisk/ami/action.rb +61 -0
- data/lib/adhearsion/rayo/component/component_node.rb +90 -0
- data/lib/adhearsion/rayo/component/input.rb +186 -0
- data/lib/adhearsion/rayo/component/output.rb +471 -0
- data/lib/adhearsion/rayo/component/prompt.rb +53 -0
- data/lib/adhearsion/rayo/component/receive_fax.rb +26 -0
- data/lib/adhearsion/rayo/component/record.rb +165 -0
- data/lib/adhearsion/rayo/component/send_fax.rb +64 -0
- data/lib/adhearsion/rayo/component/stop.rb +11 -0
- data/lib/adhearsion/rayo/connection.rb +12 -0
- data/lib/adhearsion/rayo/connection/asterisk.rb +74 -0
- data/lib/adhearsion/rayo/connection/connected.rb +22 -0
- data/lib/adhearsion/rayo/connection/generic_connection.rb +22 -0
- data/lib/adhearsion/rayo/connection/xmpp.rb +198 -0
- data/lib/adhearsion/rayo/disconnected_error.rb +22 -0
- data/lib/adhearsion/{punchblock_plugin → rayo}/initializer.rb +19 -19
- data/lib/adhearsion/rayo/rayo_node.rb +127 -0
- data/lib/adhearsion/rayo/ref.rb +57 -0
- data/lib/adhearsion/statistics.rb +1 -1
- data/lib/adhearsion/tasks.rb +1 -2
- data/lib/adhearsion/tasks/configuration.rb +1 -1
- data/lib/adhearsion/tasks/environment.rb +0 -2
- data/lib/adhearsion/tasks/i18n.rb +49 -0
- data/lib/adhearsion/translator.rb +11 -0
- data/lib/adhearsion/translator/asterisk.rb +234 -0
- data/lib/adhearsion/translator/asterisk/agi_app.rb +17 -0
- data/lib/adhearsion/translator/asterisk/agi_command.rb +45 -0
- data/lib/adhearsion/translator/asterisk/ami_error_converter.rb +20 -0
- data/lib/adhearsion/translator/asterisk/call.rb +416 -0
- data/lib/adhearsion/translator/asterisk/channel.rb +43 -0
- data/lib/adhearsion/translator/asterisk/component.rb +88 -0
- data/lib/adhearsion/translator/asterisk/component/asterisk.rb +15 -0
- data/lib/adhearsion/translator/asterisk/component/asterisk/agi_command.rb +42 -0
- data/lib/adhearsion/translator/asterisk/component/asterisk/ami_action.rb +68 -0
- data/lib/adhearsion/translator/asterisk/component/composed_prompt.rb +76 -0
- data/lib/adhearsion/translator/asterisk/component/dtmf_recognizer.rb +137 -0
- data/lib/adhearsion/translator/asterisk/component/input.rb +34 -0
- data/lib/adhearsion/translator/asterisk/component/input_component.rb +90 -0
- data/lib/adhearsion/translator/asterisk/component/mrcp_native_prompt.rb +71 -0
- data/lib/adhearsion/translator/asterisk/component/mrcp_prompt.rb +55 -0
- data/lib/adhearsion/translator/asterisk/component/mrcp_recog_prompt.rb +165 -0
- data/lib/adhearsion/translator/asterisk/component/output.rb +233 -0
- data/lib/adhearsion/translator/asterisk/component/record.rb +101 -0
- data/lib/adhearsion/translator/asterisk/component/stop_by_redirect.rb +30 -0
- data/lib/adhearsion/translator/asterisk/unimrcp_app.rb +28 -0
- data/lib/adhearsion/uri_list.rb +21 -0
- data/lib/adhearsion/version.rb +1 -1
- data/spec/adhearsion/call_controller/dial_spec.rb +79 -1420
- data/spec/adhearsion/call_controller/input_spec.rb +1141 -237
- data/spec/adhearsion/call_controller/output/async_player_spec.rb +10 -10
- data/spec/adhearsion/call_controller/output/player_spec.rb +8 -8
- data/spec/adhearsion/call_controller/output_spec.rb +162 -215
- data/spec/adhearsion/call_controller/record_spec.rb +15 -16
- data/spec/adhearsion/call_controller_spec.rb +23 -40
- data/spec/adhearsion/call_spec.rb +123 -129
- data/spec/adhearsion/calls_spec.rb +3 -3
- data/spec/adhearsion/configuration_spec.rb +94 -108
- data/spec/adhearsion/event/answered_spec.rb +50 -0
- data/spec/adhearsion/event/asterisk/Find Results +402 -0
- data/spec/adhearsion/event/asterisk/ami_spec.rb +81 -0
- data/spec/adhearsion/event/complete_spec.rb +176 -0
- data/spec/adhearsion/event/dtmf_spec.rb +35 -0
- data/spec/adhearsion/event/end_spec.rb +85 -0
- data/spec/adhearsion/event/input_timers_started_spec.rb +19 -0
- data/spec/adhearsion/event/joined_spec.rb +53 -0
- data/spec/adhearsion/event/offer_spec.rb +106 -0
- data/spec/adhearsion/event/ringing_spec.rb +50 -0
- data/spec/adhearsion/event/started_speaking_spec.rb +37 -0
- data/spec/adhearsion/event/stopped_speaking_spec.rb +37 -0
- data/spec/adhearsion/event/unjoined_spec.rb +48 -0
- data/spec/adhearsion/event/untitled +0 -0
- data/spec/adhearsion/events_spec.rb +19 -45
- data/spec/adhearsion/initializer_spec.rb +12 -184
- data/spec/adhearsion/logging_spec.rb +5 -20
- data/spec/adhearsion/outbound_call_spec.rb +13 -13
- data/spec/adhearsion/plugin_spec.rb +3 -4
- data/spec/adhearsion/protocol_error_spec.rb +91 -0
- data/spec/adhearsion/rayo/client/component_registry_spec.rb +26 -0
- data/spec/adhearsion/rayo/client_spec.rb +134 -0
- data/spec/adhearsion/rayo/command/accept_spec.rb +63 -0
- data/spec/adhearsion/rayo/command/answer_spec.rb +73 -0
- data/spec/adhearsion/rayo/command/dial_spec.rb +156 -0
- data/spec/adhearsion/rayo/command/hangup_spec.rb +63 -0
- data/spec/adhearsion/rayo/command/join_spec.rb +158 -0
- data/spec/adhearsion/rayo/command/mute_spec.rb +32 -0
- data/spec/adhearsion/rayo/command/redirect_spec.rb +89 -0
- data/spec/adhearsion/rayo/command/reject_spec.rb +117 -0
- data/spec/adhearsion/rayo/command/unjoin_spec.rb +82 -0
- data/spec/adhearsion/rayo/command/unmute_spec.rb +32 -0
- data/spec/adhearsion/rayo/command_node_spec.rb +101 -0
- data/spec/adhearsion/rayo/component/asterisk/agi/command_spec.rb +111 -0
- data/spec/adhearsion/rayo/component/asterisk/ami/action_spec.rb +173 -0
- data/spec/adhearsion/rayo/component/component_node_spec.rb +110 -0
- data/spec/adhearsion/rayo/component/input_spec.rb +715 -0
- data/spec/adhearsion/rayo/component/output_spec.rb +1030 -0
- data/spec/adhearsion/rayo/component/prompt_spec.rb +171 -0
- data/spec/adhearsion/rayo/component/receive_fax_spec.rb +136 -0
- data/spec/adhearsion/rayo/component/record_spec.rb +497 -0
- data/spec/adhearsion/rayo/component/send_fax_spec.rb +144 -0
- data/spec/adhearsion/rayo/connection/asterisk_spec.rb +118 -0
- data/spec/adhearsion/rayo/connection/xmpp_spec.rb +449 -0
- data/spec/adhearsion/rayo/initializer_spec.rb +353 -0
- data/spec/adhearsion/rayo/ref_spec.rb +168 -0
- data/spec/adhearsion/rayo_spec.rb +7 -0
- data/spec/adhearsion/router/route_spec.rb +1 -1
- data/spec/adhearsion/statistics_spec.rb +2 -5
- data/spec/adhearsion/translator/asterisk/call_spec.rb +2047 -0
- data/spec/adhearsion/translator/asterisk/component/asterisk/agi_command_spec.rb +256 -0
- data/spec/adhearsion/translator/asterisk/component/asterisk/ami_action_spec.rb +151 -0
- data/spec/adhearsion/translator/asterisk/component/composed_prompt_spec.rb +257 -0
- data/spec/adhearsion/translator/asterisk/component/input_spec.rb +571 -0
- data/spec/adhearsion/translator/asterisk/component/mrcp_native_prompt_spec.rb +774 -0
- data/spec/adhearsion/translator/asterisk/component/mrcp_prompt_spec.rb +1244 -0
- data/spec/adhearsion/translator/asterisk/component/output_spec.rb +1850 -0
- data/spec/adhearsion/translator/asterisk/component/record_spec.rb +426 -0
- data/spec/adhearsion/translator/asterisk/component/stop_by_redirect_spec.rb +62 -0
- data/spec/adhearsion/translator/asterisk/component_spec.rb +83 -0
- data/spec/adhearsion/translator/asterisk_spec.rb +685 -0
- data/spec/adhearsion/uri_list_spec.rb +88 -0
- data/spec/adhearsion_spec.rb +89 -14
- data/spec/fixtures/locale/en.yml +13 -0
- data/spec/fixtures/locale/it.yml +13 -0
- data/spec/spec_helper.rb +18 -5
- data/spec/support/call_controller_test_helpers.rb +3 -2
- data/spec/support/initializer_stubs.rb +3 -1
- data/spec/support/punchblock_examples.rb +65 -0
- data/spec/support/punchblock_mocks.rb +12 -0
- metadata +412 -70
- data/features/cli_daemon.feature +0 -20
- data/features/cli_restart.feature +0 -52
- data/features/cli_stop.feature +0 -50
- data/lib/adhearsion/call_controller/menu_dsl.rb +0 -21
- data/lib/adhearsion/call_controller/menu_dsl/array_match_calculator.rb +0 -26
- data/lib/adhearsion/call_controller/menu_dsl/calculated_match.rb +0 -43
- data/lib/adhearsion/call_controller/menu_dsl/calculated_match_collection.rb +0 -45
- data/lib/adhearsion/call_controller/menu_dsl/fixnum_match_calculator.rb +0 -11
- data/lib/adhearsion/call_controller/menu_dsl/match_calculator.rb +0 -40
- data/lib/adhearsion/call_controller/menu_dsl/menu.rb +0 -207
- data/lib/adhearsion/call_controller/menu_dsl/menu_builder.rb +0 -92
- data/lib/adhearsion/call_controller/menu_dsl/range_match_calculator.rb +0 -60
- data/lib/adhearsion/call_controller/menu_dsl/string_match_calculator.rb +0 -25
- data/lib/adhearsion/call_controller/utility.rb +0 -77
- data/lib/adhearsion/foundation/custom_daemonizer.rb +0 -52
- data/lib/adhearsion/punchblock_plugin.rb +0 -63
- data/scripts/cloc-1.64.pl +0 -10483
- data/spec/adhearsion/call_controller/menu_dsl/array_match_calculator_spec.rb +0 -76
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_collection_spec.rb +0 -60
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_spec.rb +0 -61
- data/spec/adhearsion/call_controller/menu_dsl/fixnum_match_calculator_spec.rb +0 -39
- data/spec/adhearsion/call_controller/menu_dsl/match_calculator_spec.rb +0 -17
- data/spec/adhearsion/call_controller/menu_dsl/menu_builder_spec.rb +0 -165
- data/spec/adhearsion/call_controller/menu_dsl/menu_spec.rb +0 -420
- data/spec/adhearsion/call_controller/menu_dsl/range_match_calculator_spec.rb +0 -32
- data/spec/adhearsion/call_controller/menu_dsl/string_match_calculator_spec.rb +0 -40
- data/spec/adhearsion/call_controller/utility_spec.rb +0 -90
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +0 -356
- data/spec/adhearsion/punchblock_plugin_spec.rb +0 -59
@@ -1,76 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Adhearsion
|
6
|
-
class CallController
|
7
|
-
module MenuDSL
|
8
|
-
describe ArrayMatchCalculator do
|
9
|
-
|
10
|
-
let(:match_payload) { :doesnt_matter }
|
11
|
-
|
12
|
-
it "matching arrays with fixnums" do
|
13
|
-
calculator = ArrayMatchCalculator.new [11,5,14,115], match_payload
|
14
|
-
match_case = calculator.match '11'
|
15
|
-
expect(match_case).to be_exact_match
|
16
|
-
expect(match_case).to be_potential_match
|
17
|
-
expect(match_case.exact_matches).to eq([11])
|
18
|
-
expect(match_case.potential_matches).to eq([115])
|
19
|
-
end
|
20
|
-
|
21
|
-
it "matching arrays with strings with digits and special digits" do
|
22
|
-
calculator = ArrayMatchCalculator.new %w[*57 4 *54 115 ###], match_payload
|
23
|
-
match_case = calculator.match '*5'
|
24
|
-
expect(match_case).not_to be_exact_match
|
25
|
-
expect(match_case).to be_potential_match
|
26
|
-
expect(match_case.potential_matches).to eq(%w[*57 *54])
|
27
|
-
|
28
|
-
match_case = calculator.match '*57'
|
29
|
-
expect(match_case).to be_exact_match
|
30
|
-
expect(match_case).not_to be_potential_match
|
31
|
-
expect(match_case.exact_matches).to eq(%w[*57])
|
32
|
-
end
|
33
|
-
|
34
|
-
it "matching an array with a combination of Fixnums and Strings" do
|
35
|
-
calculator = ArrayMatchCalculator.new ['11',5,'14',115], match_payload
|
36
|
-
match_case = calculator.match '11'
|
37
|
-
expect(match_case).to be_exact_match
|
38
|
-
expect(match_case).to be_potential_match
|
39
|
-
expect(match_case.exact_matches).to eq(['11'])
|
40
|
-
expect(match_case.potential_matches).to eq([115])
|
41
|
-
end
|
42
|
-
|
43
|
-
it "matching empty array should never match" do
|
44
|
-
calculator = ArrayMatchCalculator.new [], match_payload
|
45
|
-
match_case = calculator.match '98'
|
46
|
-
expect(match_case).not_to be_exact_match
|
47
|
-
expect(match_case).not_to be_potential_match
|
48
|
-
expect(match_case.exact_matches).to eq([])
|
49
|
-
expect(match_case.potential_matches).to eq([])
|
50
|
-
|
51
|
-
match_case = calculator.match '*2'
|
52
|
-
expect(match_case).not_to be_exact_match
|
53
|
-
expect(match_case).not_to be_potential_match
|
54
|
-
expect(match_case.exact_matches).to eq([])
|
55
|
-
expect(match_case.potential_matches).to eq([])
|
56
|
-
end
|
57
|
-
|
58
|
-
it "matching array with nil should skip nil field" do
|
59
|
-
pattern = [1,2,nil,5,10]
|
60
|
-
calculator = ArrayMatchCalculator.new pattern, match_payload
|
61
|
-
match_case = calculator.match '1'
|
62
|
-
expect(match_case).to be_exact_match
|
63
|
-
expect(match_case).to be_potential_match
|
64
|
-
expect(match_case.exact_matches).to eq([1])
|
65
|
-
expect(match_case.potential_matches).to eq([10])
|
66
|
-
|
67
|
-
match_case = calculator.match '99'
|
68
|
-
expect(match_case).not_to be_exact_match
|
69
|
-
expect(match_case).not_to be_potential_match
|
70
|
-
|
71
|
-
expect(pattern).to eq([1,2,nil,5,10])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Adhearsion
|
6
|
-
class CallController
|
7
|
-
module MenuDSL
|
8
|
-
describe CalculatedMatchCollection do
|
9
|
-
def mock_with_potential_matches(potential_matches)
|
10
|
-
CalculatedMatch.new :potential_matches => potential_matches
|
11
|
-
end
|
12
|
-
|
13
|
-
def mock_with_exact_matches(exact_matches)
|
14
|
-
CalculatedMatch.new :exact_matches => exact_matches
|
15
|
-
end
|
16
|
-
|
17
|
-
def mock_with_potential_and_exact_matches(potential_matches, exact_matches)
|
18
|
-
CalculatedMatch.new :potential_matches => potential_matches,
|
19
|
-
:exact_matches => exact_matches
|
20
|
-
end
|
21
|
-
|
22
|
-
it "the <<() method should collect the potential matches into the actual_potential_matches Array" do
|
23
|
-
mock_matches_array_1 = [:foo, :bar, :qaz],
|
24
|
-
mock_matches_array_2 = [10, 20, 30]
|
25
|
-
mock_matches_1 = mock_with_potential_matches mock_matches_array_1
|
26
|
-
mock_matches_2 = mock_with_potential_matches mock_matches_array_2
|
27
|
-
|
28
|
-
subject << mock_matches_1
|
29
|
-
expect(subject.actual_potential_matches).to eq(mock_matches_array_1)
|
30
|
-
|
31
|
-
subject << mock_matches_2
|
32
|
-
expect(subject.actual_potential_matches).to eq(mock_matches_array_1 + mock_matches_array_2)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "the <<() method should collect the exact matches into the actual_exact_matches Array" do
|
36
|
-
mock_matches_array_1 = [:blam, :blargh],
|
37
|
-
mock_matches_array_2 = [5,4,3,2,1]
|
38
|
-
mock_matches_1 = mock_with_exact_matches mock_matches_array_1
|
39
|
-
mock_matches_2 = mock_with_exact_matches mock_matches_array_2
|
40
|
-
|
41
|
-
subject << mock_matches_1
|
42
|
-
expect(subject.actual_exact_matches).to eq(mock_matches_array_1)
|
43
|
-
|
44
|
-
subject << mock_matches_2
|
45
|
-
expect(subject.actual_exact_matches).to eq(mock_matches_array_1 + mock_matches_array_2)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "if any exact matches exist, the exact_match?() method should return true" do
|
49
|
-
subject << mock_with_exact_matches([1,2,3])
|
50
|
-
expect(subject.exact_match?).to be true
|
51
|
-
end
|
52
|
-
|
53
|
-
it "if any potential matches exist, the potential_match?() method should return true" do
|
54
|
-
subject << mock_with_potential_matches([1,2,3])
|
55
|
-
expect(subject.potential_match?).to be true
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Adhearsion
|
6
|
-
class CallController
|
7
|
-
module MenuDSL
|
8
|
-
describe CalculatedMatch do
|
9
|
-
it "should make accessible the context name" do
|
10
|
-
expect(CalculatedMatch.new(:match_payload => :foobar).match_payload).to be :foobar
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should make accessible the original pattern" do
|
14
|
-
expect(CalculatedMatch.new(:pattern => :something).pattern).to be :something
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should make accessible the matched query" do
|
18
|
-
expect(CalculatedMatch.new(:query => 123).query).to be 123
|
19
|
-
end
|
20
|
-
|
21
|
-
it "#type_of_match should return :exact, :potential, or nil" do
|
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
|
-
end
|
26
|
-
|
27
|
-
it "#exact_match? should return true if the match was exact" do
|
28
|
-
expect(CalculatedMatch.new(:exact_matches => [0,3,5]).exact_match?).to be true
|
29
|
-
end
|
30
|
-
|
31
|
-
it "#potential_match? should return true if the match was exact" do
|
32
|
-
expect(CalculatedMatch.new(:potential_matches => [88,99,77]).potential_match?).to be true
|
33
|
-
end
|
34
|
-
|
35
|
-
it "#failed_match? should return false if the match was exact" do
|
36
|
-
expect(CalculatedMatch.new(:potential_matches => [88,99,77]).failed_match?).to be false
|
37
|
-
end
|
38
|
-
|
39
|
-
it "#exact_matches should return an array of exact matches" do
|
40
|
-
expect(CalculatedMatch.new(:exact_matches => [0,3,5]).exact_matches).to eq([0,3,5])
|
41
|
-
end
|
42
|
-
|
43
|
-
it "#potential_matches should return an array of potential matches" do
|
44
|
-
expect(CalculatedMatch.new(:potential_matches => [88,99,77]).potential_matches).to eq([88,99,77])
|
45
|
-
end
|
46
|
-
|
47
|
-
it "::failed_match! should return a match that *really* failed" do
|
48
|
-
failure = CalculatedMatch.failed_match! 10..20, 30, :match_payload_does_not_matter
|
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
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Adhearsion
|
6
|
-
class CallController
|
7
|
-
module MenuDSL
|
8
|
-
describe FixnumMatchCalculator do
|
9
|
-
let(:match_payload) { :main }
|
10
|
-
|
11
|
-
it "a potential match scenario" do
|
12
|
-
calculator = FixnumMatchCalculator.new(444, match_payload)
|
13
|
-
match = calculator.match '4'
|
14
|
-
expect(match).to be_potential_match
|
15
|
-
expect(match).not_to be_exact_match
|
16
|
-
expect(match.potential_matches).to eq([444])
|
17
|
-
end
|
18
|
-
|
19
|
-
it "a multi-digit exact match scenario" do
|
20
|
-
calculator = FixnumMatchCalculator.new(5555, match_payload)
|
21
|
-
match = calculator.match '5555'
|
22
|
-
expect(match).to be_exact_match
|
23
|
-
end
|
24
|
-
|
25
|
-
it "a single-digit exact match scenario" do
|
26
|
-
calculator = FixnumMatchCalculator.new(1, match_payload)
|
27
|
-
match = calculator.match '1'
|
28
|
-
expect(match).to be_exact_match
|
29
|
-
end
|
30
|
-
|
31
|
-
it "the context name given to the calculator should be passed on the CalculatedMatch" do
|
32
|
-
match_payload = :icanhascheezburger
|
33
|
-
calculator = FixnumMatchCalculator.new(1337, match_payload)
|
34
|
-
expect(calculator.match('1337').match_payload).to be match_payload
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Adhearsion
|
6
|
-
class CallController
|
7
|
-
module MenuDSL
|
8
|
-
describe MatchCalculator do
|
9
|
-
describe ".build_with_pattern" do
|
10
|
-
it "should return an appropriate subclass instance based on the pattern's class" do
|
11
|
-
expect(MatchCalculator.build_with_pattern(1..2, :main)).to be_an_instance_of RangeMatchCalculator
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,165 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Adhearsion
|
6
|
-
class CallController
|
7
|
-
module MenuDSL
|
8
|
-
|
9
|
-
describe MenuBuilder do
|
10
|
-
subject { MenuDSL::MenuBuilder.new }
|
11
|
-
|
12
|
-
describe "#build" do
|
13
|
-
it "sets the context and instance_eval's the block" do
|
14
|
-
expect(subject).to receive(:foo).with(:bar)
|
15
|
-
subject.build do
|
16
|
-
foo :bar
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:foo) { :bar }
|
21
|
-
|
22
|
-
it "makes the block context available" do
|
23
|
-
doo = nil
|
24
|
-
subject.build do
|
25
|
-
doo = foo
|
26
|
-
end
|
27
|
-
expect(doo).to eq(:bar)
|
28
|
-
end
|
29
|
-
end#build
|
30
|
-
|
31
|
-
describe "#match" do
|
32
|
-
let(:match_block) { Proc.new() {} }
|
33
|
-
|
34
|
-
it "raises an exception if called without a CallController and no block" do
|
35
|
-
expect { subject.match 1 }.to raise_error(ArgumentError)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "raises an exception if given both a payload and a block" do
|
39
|
-
expect { subject.match(1, Object) {} }.to raise_error(ArgumentError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "raises an exception if given no patterns" do
|
43
|
-
expect { subject.match() {} }.to raise_error(ArgumentError, "You cannot call this method without patterns.")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "creates a pattern based on a payload" do
|
47
|
-
expect(MenuDSL::MatchCalculator).to receive(:build_with_pattern).with("1", Object)
|
48
|
-
subject.match "1", Object
|
49
|
-
end
|
50
|
-
|
51
|
-
it "creates a pattern based on a block" do
|
52
|
-
expect(MenuDSL::MatchCalculator).to receive(:build_with_pattern).with("1", nil, &match_block)
|
53
|
-
subject.match("1", &match_block)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "creates multiple patterns if multiple arguments are passed in" do
|
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
|
-
subject.match(1, 2, Object)
|
60
|
-
end
|
61
|
-
end#match
|
62
|
-
|
63
|
-
describe "#has_matchers?" do
|
64
|
-
context "with no matchers specified" do
|
65
|
-
describe '#has_matchers?' do
|
66
|
-
it { expect(subject.has_matchers?).to be false }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "with at least one matcher specified" do
|
71
|
-
before do
|
72
|
-
subject.match(1) {}
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#has_matchers?' do
|
76
|
-
it { expect(subject.has_matchers?).to be true }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "#weighted_match_calculators" do
|
82
|
-
let(:expected_pattern) { MenuDSL::MatchCalculator.build_with_pattern("1", Object) }
|
83
|
-
|
84
|
-
it "returns the generated patterns" do
|
85
|
-
expect(MenuDSL::MatchCalculator).to receive(:build_with_pattern).with("1", Object).at_least(:once).and_return(expected_pattern)
|
86
|
-
subject.match("1", Object)
|
87
|
-
expect(subject.weighted_match_calculators).to eq([expected_pattern])
|
88
|
-
end
|
89
|
-
end#weighted_match_calculators
|
90
|
-
|
91
|
-
describe "#invalid" do
|
92
|
-
let(:callback) { Proc.new() {} }
|
93
|
-
|
94
|
-
it "raises an error if not passed a block" do
|
95
|
-
expect { subject.invalid }.to raise_error(LocalJumpError)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "sets the invalid callback" do
|
99
|
-
subject.invalid(&callback)
|
100
|
-
expect(subject.menu_callbacks[:invalid]).to eq(callback)
|
101
|
-
end
|
102
|
-
end#invalid
|
103
|
-
|
104
|
-
describe "#timeout" do
|
105
|
-
let(:callback) { Proc.new() {} }
|
106
|
-
|
107
|
-
it "raises an error if not passed a block" do
|
108
|
-
expect { subject.timeout }.to raise_error(LocalJumpError)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "sets the timeout callback" do
|
112
|
-
subject.timeout(&callback)
|
113
|
-
expect(subject.menu_callbacks[:timeout]).to eq(callback)
|
114
|
-
end
|
115
|
-
end#timeout
|
116
|
-
|
117
|
-
describe "#failure" do
|
118
|
-
let(:callback) { Proc.new() {} }
|
119
|
-
|
120
|
-
it "raises an error if not passed a block" do
|
121
|
-
expect { subject.failure }.to raise_error(LocalJumpError)
|
122
|
-
end
|
123
|
-
|
124
|
-
it "sets the failure callback" do
|
125
|
-
subject.failure(&callback)
|
126
|
-
expect(subject.menu_callbacks[:failure]).to eq(callback)
|
127
|
-
end
|
128
|
-
end#failure
|
129
|
-
|
130
|
-
describe "#validator" do
|
131
|
-
let(:callback) { Proc.new() {} }
|
132
|
-
|
133
|
-
it "raises an error if not passed a block" do
|
134
|
-
expect { subject.validator }.to raise_error(LocalJumpError)
|
135
|
-
end
|
136
|
-
|
137
|
-
it "sets the invalid callback" do
|
138
|
-
subject.validator(&callback)
|
139
|
-
expect(subject.menu_callbacks[:validator]).to eq(callback)
|
140
|
-
end
|
141
|
-
end#invalid
|
142
|
-
|
143
|
-
describe "#execute_hook_for" do
|
144
|
-
it "executes the correct hook" do
|
145
|
-
bar = nil
|
146
|
-
subject.invalid do |baz|
|
147
|
-
bar = baz
|
148
|
-
end
|
149
|
-
subject.execute_hook_for(:invalid, "1")
|
150
|
-
expect(bar).to eq("1")
|
151
|
-
end
|
152
|
-
end#execute_hook_for
|
153
|
-
|
154
|
-
describe "#calculate_matches_for" do
|
155
|
-
it "returns a calculated match collection" do
|
156
|
-
subject.match("1", Object)
|
157
|
-
expect(subject.calculate_matches_for("1")).to be_a CalculatedMatchCollection
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
end# describe MenuBuilder
|
162
|
-
|
163
|
-
end# module MenuDSL
|
164
|
-
end
|
165
|
-
end
|
@@ -1,420 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Adhearsion
|
6
|
-
class CallController
|
7
|
-
module MenuDSL
|
8
|
-
describe Menu do
|
9
|
-
|
10
|
-
let(:options) { Hash.new }
|
11
|
-
subject { Menu.new(options) }
|
12
|
-
|
13
|
-
describe "#initialize" do
|
14
|
-
describe '#tries_count' do
|
15
|
-
subject { super().tries_count }
|
16
|
-
it { is_expected.to eq(0) }
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'when no timeout is set' do
|
20
|
-
it "should have the default timeout" do
|
21
|
-
expect(subject.timeout).to eq(5)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when a timeout is set' do
|
26
|
-
let(:options) {
|
27
|
-
{:timeout => 20}
|
28
|
-
}
|
29
|
-
|
30
|
-
it 'should have the passed timeout' do
|
31
|
-
expect(subject.timeout).to eq(20)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when no max number of tries is set' do
|
36
|
-
it "should have the default max number of tries" do
|
37
|
-
expect(subject.max_number_of_tries).to eq(1)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'when a max number of tries is set' do
|
42
|
-
let(:options) {
|
43
|
-
{:tries => 3}
|
44
|
-
}
|
45
|
-
|
46
|
-
it 'should have the passed max number of tries' do
|
47
|
-
expect(subject.max_number_of_tries).to eq(3)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'when no terminator is set' do
|
52
|
-
it "should have no terminator" do
|
53
|
-
expect(subject.terminator).to eq('')
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should not validate successfully' do
|
57
|
-
expect { subject.validate }.to raise_error(Menu::InvalidStructureError)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'when a terminator is set' do
|
62
|
-
let(:options) {
|
63
|
-
{:terminator => 3}
|
64
|
-
}
|
65
|
-
|
66
|
-
it 'should have the passed terminator' do
|
67
|
-
expect(subject.terminator).to eq('3')
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should validate(:basic) successfully' do
|
71
|
-
expect(subject.validate(:basic)).to be true
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'should not validate successfully' do
|
75
|
-
expect { subject.validate }.to raise_error(Menu::InvalidStructureError)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'when no limit is set' do
|
80
|
-
it "should have no limit" do
|
81
|
-
expect(subject.limit).to be nil
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should not validate successfully' do
|
85
|
-
expect { subject.validate }.to raise_error(Menu::InvalidStructureError)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'when a limit is set' do
|
90
|
-
let(:options) {
|
91
|
-
{:limit => 3}
|
92
|
-
}
|
93
|
-
|
94
|
-
it 'should have the passed limit' do
|
95
|
-
expect(subject.limit).to eq(3)
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should validate(:basic) successfully' do
|
99
|
-
expect(subject.validate(:basic)).to be true
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should not validate successfully' do
|
103
|
-
expect { subject.validate }.to raise_error(Menu::InvalidStructureError)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'when no interruptibility is set' do
|
108
|
-
it "should be interruptible" do
|
109
|
-
expect(subject.interruptible).to be true
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'when interruptible is set false' do
|
114
|
-
let(:options) {
|
115
|
-
{:interruptible => false}
|
116
|
-
}
|
117
|
-
|
118
|
-
it 'should be interruptible' do
|
119
|
-
expect(subject.interruptible).to be false
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context 'when renderer is not specified' do
|
124
|
-
it 'should have a nil renderer' do
|
125
|
-
expect(subject.renderer).to be nil
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'when renderer is specified' do
|
130
|
-
let(:options) {
|
131
|
-
{:renderer => :native}
|
132
|
-
}
|
133
|
-
|
134
|
-
it 'should have the specified renderer' do
|
135
|
-
expect(subject.renderer).to eq(:native)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'when matchers are specified' do
|
140
|
-
subject do
|
141
|
-
Menu.new do
|
142
|
-
match(1) { }
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'should validate successfully' do
|
147
|
-
expect(subject.validate).to be true
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'should not validate(:basic) successfully' do
|
151
|
-
expect { subject.validate :basic }.to raise_error(Menu::InvalidStructureError)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context 'menu builder setup' do
|
156
|
-
describe '#builder' do
|
157
|
-
subject { super().builder }
|
158
|
-
it { is_expected.to be_a MenuBuilder }
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should evaluate the block on the builder object" do
|
162
|
-
mock_menu_builder = MenuBuilder.new
|
163
|
-
expect(MenuBuilder).to receive(:new).and_return(mock_menu_builder)
|
164
|
-
expect(mock_menu_builder).to receive(:match).once.with(1)
|
165
|
-
Menu.new { match 1 }
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
end # describe #initialize
|
170
|
-
|
171
|
-
describe "#digit_buffer" do
|
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
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "#<<" do
|
184
|
-
it "should add a digit to the buffer" do
|
185
|
-
subject << 'a'
|
186
|
-
expect(subject.digit_buffer).to eq('a')
|
187
|
-
expect(subject.result).to eq('a')
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe "#digit_buffer_empty?" do
|
192
|
-
it "returns true if buffer is empty" do
|
193
|
-
expect(subject.digit_buffer_empty?).to eq(true)
|
194
|
-
end
|
195
|
-
|
196
|
-
it "returns false if buffer is not empty" do
|
197
|
-
subject << 1
|
198
|
-
expect(subject.digit_buffer_empty?).to eq(false)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
describe "#digit_buffer_string" do
|
203
|
-
it "returns the digit buffer as a string" do
|
204
|
-
subject << 1
|
205
|
-
expect(subject.digit_buffer_string).to eq("1")
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
describe "#should_continue?" do
|
210
|
-
it "returns true if the number of tries is less than the maximum" do
|
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)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
describe "#restart!" do
|
218
|
-
it "increments tries and clears the digit buffer" do
|
219
|
-
subject << 1
|
220
|
-
subject.restart!
|
221
|
-
expect(subject.tries_count).to eq(1)
|
222
|
-
expect(subject.digit_buffer_empty?).to eq(true)
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
describe "#execute_invalid_hook" do
|
227
|
-
it "calls the builder's execute_hook_for with :invalid" do
|
228
|
-
mock_menu_builder = MenuBuilder.new
|
229
|
-
expect(MenuBuilder).to receive(:new).and_return(mock_menu_builder)
|
230
|
-
expect(mock_menu_builder).to receive(:execute_hook_for).with(:invalid, "")
|
231
|
-
menu_instance = Menu.new
|
232
|
-
menu_instance.execute_invalid_hook
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
describe "#execute_timeout_hook" do
|
237
|
-
it "calls the builder's execute_hook_for with :timeout" do
|
238
|
-
mock_menu_builder = MenuBuilder.new
|
239
|
-
expect(MenuBuilder).to receive(:new).and_return(mock_menu_builder)
|
240
|
-
expect(mock_menu_builder).to receive(:execute_hook_for).with(:timeout, "")
|
241
|
-
menu_instance = Menu.new
|
242
|
-
menu_instance.execute_timeout_hook
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
describe "#execute_failure_hook" do
|
247
|
-
it "calls the builder's execute_hook_for with :failure" do
|
248
|
-
mock_menu_builder = MenuBuilder.new
|
249
|
-
expect(MenuBuilder).to receive(:new).and_return(mock_menu_builder)
|
250
|
-
expect(mock_menu_builder).to receive(:execute_hook_for).with(:failure, "")
|
251
|
-
menu_instance = Menu.new
|
252
|
-
menu_instance.execute_failure_hook
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
describe "#execute_validator_hook" do
|
257
|
-
it "calls the builder's execute_hook_for with :validator" do
|
258
|
-
mock_menu_builder = MenuBuilder.new
|
259
|
-
expect(MenuBuilder).to receive(:new).and_return(mock_menu_builder)
|
260
|
-
expect(mock_menu_builder).to receive(:execute_hook_for).with(:validator, "")
|
261
|
-
menu_instance = Menu.new
|
262
|
-
menu_instance.execute_validator_hook
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
describe "#continue" do
|
267
|
-
class MockControllerA; end
|
268
|
-
class MockControllerB; end
|
269
|
-
class MockControllerC; end
|
270
|
-
let(:options) { {} }
|
271
|
-
let(:menu_instance) {
|
272
|
-
Menu.new options do
|
273
|
-
match 1, MockControllerA
|
274
|
-
match 21, MockControllerA
|
275
|
-
match 23, MockControllerA
|
276
|
-
match 3, MockControllerB
|
277
|
-
match 3..5, MockControllerC
|
278
|
-
match 33, MockControllerA
|
279
|
-
match 6, MockControllerC
|
280
|
-
match 6..8, MockControllerA
|
281
|
-
end
|
282
|
-
}
|
283
|
-
|
284
|
-
it "returns a MenuGetAnotherDigitOrTimeout if the digit buffer is empty" do
|
285
|
-
expect(subject.continue).to be_a Menu::MenuGetAnotherDigitOrTimeout
|
286
|
-
expect(menu_instance.status).to be nil
|
287
|
-
end
|
288
|
-
|
289
|
-
it "asks for another digit if it has potential matches" do
|
290
|
-
menu_instance << 2
|
291
|
-
expect(menu_instance.continue).to be_a Menu::MenuGetAnotherDigitOrTimeout
|
292
|
-
expect(menu_instance.status).to eq(:potential)
|
293
|
-
end
|
294
|
-
|
295
|
-
it "returns a MenuResultInvalid if there are no matches" do
|
296
|
-
menu_instance << 9
|
297
|
-
expect(menu_instance.continue).to be_a Menu::MenuResultInvalid
|
298
|
-
expect(menu_instance.status).to eq(:invalid)
|
299
|
-
end
|
300
|
-
|
301
|
-
it "returns the first exact match when it has exact and potentials" do
|
302
|
-
menu_instance << 3
|
303
|
-
menu_result = menu_instance.continue
|
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)
|
308
|
-
end
|
309
|
-
|
310
|
-
it "returns a MenuResultFound if it has exact matches" do
|
311
|
-
menu_instance << 6
|
312
|
-
menu_result = menu_instance.continue
|
313
|
-
expect(menu_result).to be_a Menu::MenuResultFound
|
314
|
-
expect(menu_instance.status).to eq(:matched)
|
315
|
-
end
|
316
|
-
|
317
|
-
it "returns the first exact match when it has only exact matches" do
|
318
|
-
menu_instance << 6
|
319
|
-
menu_result = menu_instance.continue
|
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")
|
323
|
-
end
|
324
|
-
|
325
|
-
context "with no matchers" do
|
326
|
-
let(:menu_instance) { Menu.new options }
|
327
|
-
|
328
|
-
context "when a terminator digit is set" do
|
329
|
-
let(:options) { { :terminator => '#' } }
|
330
|
-
|
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
|
332
|
-
menu_instance << 2
|
333
|
-
menu_instance << 4
|
334
|
-
expect(menu_instance.continue).to be_a Menu::MenuGetAnotherDigitOrTimeout
|
335
|
-
expect(menu_instance.status).to eq(:potential)
|
336
|
-
menu_instance << '#'
|
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')
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
context "when a digit limit is set" do
|
345
|
-
let(:options) { { :limit => 3 } }
|
346
|
-
|
347
|
-
it "buffers until the limit is reached, then returns MenuLimitReached and sets the status to :limited" do
|
348
|
-
menu_instance << 2
|
349
|
-
menu_instance << 4
|
350
|
-
expect(menu_instance.continue).to be_a Menu::MenuGetAnotherDigitOrTimeout
|
351
|
-
expect(menu_instance.status).to eq(:potential)
|
352
|
-
menu_instance << 2
|
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')
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
context "when a validator is defined" do
|
361
|
-
let(:menu_instance) do
|
362
|
-
Menu.new options do
|
363
|
-
validator { |buffer| buffer == "242" }
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
it "buffers until the validator returns true, then returns MenuValidatorTerminated and sets the status to :validator_terminated" do
|
368
|
-
menu_instance << 2
|
369
|
-
menu_instance << 4
|
370
|
-
expect(menu_instance.continue).to be_a Menu::MenuGetAnotherDigitOrTimeout
|
371
|
-
expect(menu_instance.status).to eq(:potential)
|
372
|
-
menu_instance << 2
|
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')
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
context "when a digit limit and validator is defined" do
|
381
|
-
let(:menu_instance) do
|
382
|
-
Menu.new options.merge(:limit => 3) do
|
383
|
-
validator { |buffer| buffer == "242" }
|
384
|
-
end
|
385
|
-
end
|
386
|
-
|
387
|
-
it "applies the validator before checking the digit limit" do
|
388
|
-
menu_instance << 2
|
389
|
-
menu_instance << 4
|
390
|
-
menu_instance << 2
|
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')
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
end#continue
|
400
|
-
|
401
|
-
describe Menu::ClearableStringBuffer do
|
402
|
-
subject { Menu::ClearableStringBuffer.new }
|
403
|
-
|
404
|
-
it "adds a string to itself" do
|
405
|
-
subject << 'b'
|
406
|
-
subject << 'c'
|
407
|
-
expect(subject).to eq('bc')
|
408
|
-
end
|
409
|
-
|
410
|
-
it "clears itself" do
|
411
|
-
subject << 'a'
|
412
|
-
subject.clear!
|
413
|
-
expect(subject).to eq("")
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
end # describe Menu
|
418
|
-
end
|
419
|
-
end
|
420
|
-
end
|