adhearsion 1.2.6 → 2.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -10
- data/CHANGELOG.md +273 -0
- data/Gemfile +1 -1
- data/Guardfile +17 -0
- data/README.markdown +61 -9
- data/Rakefile +16 -48
- data/adhearsion.gemspec +21 -7
- data/bin/ahn +3 -1
- data/cucumber.yml +4 -0
- data/features/app_generator.feature +42 -0
- data/features/cli.feature +108 -0
- data/features/step_definitions/app_generator_steps.rb +6 -0
- data/features/step_definitions/cli_steps.rb +74 -0
- data/features/support/aruba_helper.rb +22 -0
- data/features/support/env.rb +37 -0
- data/features/support/utils.rb +8 -0
- data/lib/adhearsion.rb +85 -41
- data/lib/adhearsion/call.rb +176 -0
- data/lib/adhearsion/call_controller.rb +134 -0
- data/lib/adhearsion/call_controller/dial.rb +70 -0
- data/lib/adhearsion/call_controller/input.rb +173 -0
- data/lib/adhearsion/call_controller/menu.rb +124 -0
- data/lib/adhearsion/call_controller/output.rb +267 -0
- data/lib/adhearsion/call_controller/record.rb +42 -0
- data/lib/adhearsion/call_controller/utility.rb +60 -0
- data/lib/adhearsion/calls.rb +81 -0
- data/lib/adhearsion/cli.rb +1 -3
- data/lib/adhearsion/cli_commands.rb +142 -0
- data/lib/adhearsion/configuration.rb +149 -0
- data/lib/adhearsion/console.rb +19 -8
- data/lib/adhearsion/dialplan_controller.rb +9 -0
- data/lib/adhearsion/events.rb +84 -0
- data/lib/adhearsion/foundation/all.rb +0 -7
- data/lib/adhearsion/foundation/custom_daemonizer.rb +4 -6
- data/lib/adhearsion/foundation/exception_handler.rb +9 -0
- data/lib/adhearsion/foundation/object.rb +26 -8
- data/lib/adhearsion/foundation/synchronized_hash.rb +3 -6
- data/lib/adhearsion/foundation/thread_safety.rb +17 -1
- data/lib/adhearsion/generators/app/app_generator.rb +4 -13
- data/lib/adhearsion/generators/app/templates/Gemfile +10 -5
- data/lib/adhearsion/generators/app/templates/Procfile +1 -0
- data/lib/adhearsion/generators/app/templates/README.md +28 -0
- data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +41 -0
- data/lib/adhearsion/generators/app/templates/{components/simon_game → lib}/simon_game.rb +6 -18
- data/lib/adhearsion/generators/app/templates/script/ahn +2 -2
- data/lib/adhearsion/initializer.rb +151 -293
- data/lib/adhearsion/initializer/logging.rb +33 -0
- data/lib/adhearsion/logging.rb +65 -69
- data/lib/adhearsion/menu_dsl.rb +15 -0
- data/lib/adhearsion/menu_dsl/calculated_match.rb +39 -0
- data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +41 -0
- data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +18 -0
- data/lib/adhearsion/menu_dsl/match_calculator.rb +36 -0
- data/lib/adhearsion/{voip/menu_state_machine/menu_class.rb → menu_dsl/menu.rb} +38 -40
- data/lib/adhearsion/menu_dsl/menu_builder.rb +69 -0
- data/lib/adhearsion/menu_dsl/range_match_calculator.rb +55 -0
- data/lib/adhearsion/menu_dsl/string_match_calculator.rb +21 -0
- data/lib/adhearsion/outbound_call.rb +64 -0
- data/lib/adhearsion/plugin.rb +319 -0
- data/lib/adhearsion/plugin/collection.rb +19 -0
- data/lib/adhearsion/plugin/initializer.rb +37 -0
- data/lib/adhearsion/plugin/methods_container.rb +6 -0
- data/lib/adhearsion/process.rb +94 -0
- data/lib/adhearsion/punchblock_plugin.rb +29 -0
- data/lib/adhearsion/punchblock_plugin/initializer.rb +137 -0
- data/lib/adhearsion/router.rb +30 -0
- data/lib/adhearsion/router/route.rb +42 -0
- data/lib/adhearsion/script_ahn_loader.rb +2 -2
- data/lib/adhearsion/tasks.rb +14 -9
- data/lib/adhearsion/tasks/configuration.rb +26 -0
- data/lib/adhearsion/tasks/plugins.rb +17 -0
- data/lib/adhearsion/version.rb +8 -14
- data/spec/adhearsion/call_controller/dial_spec.rb +138 -0
- data/spec/adhearsion/call_controller/input_spec.rb +278 -0
- data/spec/adhearsion/call_controller/menu_spec.rb +120 -0
- data/spec/adhearsion/call_controller/output_spec.rb +466 -0
- data/spec/adhearsion/call_controller/record_spec.rb +125 -0
- data/spec/adhearsion/call_controller_spec.rb +395 -0
- data/spec/adhearsion/call_spec.rb +438 -0
- data/spec/adhearsion/calls_spec.rb +47 -0
- data/spec/adhearsion/configuration_spec.rb +308 -0
- data/spec/adhearsion/dialplan_controller_spec.rb +26 -0
- data/spec/adhearsion/events_spec.rb +112 -0
- data/spec/adhearsion/initializer/logging_spec.rb +58 -0
- data/spec/adhearsion/initializer_spec.rb +209 -122
- data/spec/adhearsion/logging_spec.rb +58 -47
- data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +56 -0
- data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +57 -0
- data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +33 -0
- data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +13 -0
- data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +118 -0
- data/spec/adhearsion/menu_dsl/menu_spec.rb +210 -0
- data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +28 -0
- data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +36 -0
- data/spec/adhearsion/menu_dsl_spec.rb +12 -0
- data/spec/adhearsion/outbound_call_spec.rb +174 -0
- data/spec/adhearsion/plugin_spec.rb +489 -0
- data/spec/adhearsion/process_spec.rb +34 -0
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +294 -0
- data/spec/adhearsion/router/route_spec.rb +99 -0
- data/spec/adhearsion/router_spec.rb +106 -0
- data/spec/adhearsion_spec.rb +46 -0
- data/spec/spec_helper.rb +14 -14
- data/spec/support/call_controller_test_helpers.rb +48 -0
- data/spec/support/initializer_stubs.rb +8 -13
- data/spec/support/punchblock_mocks.rb +6 -0
- metadata +255 -253
- data/CHANGELOG +0 -174
- data/bin/ahnctl +0 -68
- data/bin/jahn +0 -43
- data/examples/asterisk_manager_interface/standalone.rb +0 -51
- data/lib/adhearsion/commands.rb +0 -302
- data/lib/adhearsion/component_manager.rb +0 -278
- data/lib/adhearsion/component_manager/component_tester.rb +0 -54
- data/lib/adhearsion/component_manager/spec_framework.rb +0 -18
- data/lib/adhearsion/events_support.rb +0 -65
- data/lib/adhearsion/foundation/blank_slate.rb +0 -3
- data/lib/adhearsion/foundation/event_socket.rb +0 -205
- data/lib/adhearsion/foundation/future_resource.rb +0 -36
- data/lib/adhearsion/foundation/metaprogramming.rb +0 -17
- data/lib/adhearsion/foundation/numeric.rb +0 -13
- data/lib/adhearsion/foundation/pseudo_guid.rb +0 -10
- data/lib/adhearsion/foundation/relationship_properties.rb +0 -42
- data/lib/adhearsion/foundation/string.rb +0 -26
- data/lib/adhearsion/generators/app/templates/.ahnrc +0 -34
- data/lib/adhearsion/generators/app/templates/README +0 -8
- data/lib/adhearsion/generators/app/templates/components/ami_remote/ami_remote.rb +0 -15
- data/lib/adhearsion/generators/app/templates/components/disabled/HOW_TO_ENABLE +0 -7
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/README.markdown +0 -47
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.rb +0 -34
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.yml +0 -12
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/README.markdown +0 -3
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +0 -11
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
- data/lib/adhearsion/generators/app/templates/config/startup.rb +0 -81
- data/lib/adhearsion/generators/app/templates/dialplan.rb +0 -3
- data/lib/adhearsion/generators/app/templates/events.rb +0 -33
- data/lib/adhearsion/host_definitions.rb +0 -67
- data/lib/adhearsion/initializer/asterisk.rb +0 -86
- data/lib/adhearsion/initializer/configuration.rb +0 -324
- data/lib/adhearsion/initializer/database.rb +0 -60
- data/lib/adhearsion/initializer/drb.rb +0 -31
- data/lib/adhearsion/initializer/freeswitch.rb +0 -22
- data/lib/adhearsion/initializer/ldap.rb +0 -57
- data/lib/adhearsion/initializer/rails.rb +0 -41
- data/lib/adhearsion/initializer/xmpp.rb +0 -42
- data/lib/adhearsion/tasks/components.rb +0 -32
- data/lib/adhearsion/tasks/database.rb +0 -5
- data/lib/adhearsion/tasks/deprecations.rb +0 -59
- data/lib/adhearsion/tasks/generating.rb +0 -20
- data/lib/adhearsion/tasks/lint.rb +0 -4
- data/lib/adhearsion/voip/asterisk.rb +0 -4
- data/lib/adhearsion/voip/asterisk/agi_server.rb +0 -121
- data/lib/adhearsion/voip/asterisk/commands.rb +0 -1966
- data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +0 -140
- data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +0 -102
- data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +0 -250
- data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +0 -240
- data/lib/adhearsion/voip/asterisk/config_manager.rb +0 -64
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -697
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +0 -1681
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +0 -341
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +0 -78
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +0 -87
- data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +0 -80
- data/lib/adhearsion/voip/call.rb +0 -521
- data/lib/adhearsion/voip/call_routing.rb +0 -64
- data/lib/adhearsion/voip/commands.rb +0 -17
- data/lib/adhearsion/voip/constants.rb +0 -39
- data/lib/adhearsion/voip/conveniences.rb +0 -18
- data/lib/adhearsion/voip/dial_plan.rb +0 -252
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +0 -151
- data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +0 -37
- data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +0 -27
- data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +0 -124
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +0 -69
- data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +0 -16
- data/lib/adhearsion/voip/dsl/numerical_string.rb +0 -128
- data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +0 -48
- data/lib/adhearsion/voip/freeswitch/event_handler.rb +0 -58
- data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +0 -129
- data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +0 -38
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +0 -195
- data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +0 -80
- data/lib/adhearsion/voip/menu_state_machine/matchers.rb +0 -123
- data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +0 -57
- data/lib/adhearsion/xmpp/connection.rb +0 -61
- data/lib/theatre.rb +0 -147
- data/lib/theatre/README.markdown +0 -64
- data/lib/theatre/callback_definition_loader.rb +0 -86
- data/lib/theatre/guid.rb +0 -23
- data/lib/theatre/invocation.rb +0 -131
- data/lib/theatre/namespace_manager.rb +0 -153
- data/lib/theatre/version.rb +0 -2
- data/spec/adhearsion/cli_spec.rb +0 -306
- data/spec/adhearsion/component_manager_spec.rb +0 -292
- data/spec/adhearsion/constants_spec.rb +0 -8
- data/spec/adhearsion/drb_spec.rb +0 -65
- data/spec/adhearsion/fixtures/dialplan.rb +0 -3
- data/spec/adhearsion/foundation/event_socket_spec.rb +0 -168
- data/spec/adhearsion/host_definitions_spec.rb +0 -79
- data/spec/adhearsion/initializer/configuration_spec.rb +0 -291
- data/spec/adhearsion/initializer/loading_spec.rb +0 -154
- data/spec/adhearsion/initializer/paths_spec.rb +0 -74
- data/spec/adhearsion/relationship_properties_spec.rb +0 -54
- data/spec/adhearsion/voip/asterisk/agi_server_spec.rb +0 -473
- data/spec/adhearsion/voip/asterisk/ami/ami_spec.rb +0 -550
- data/spec/adhearsion/voip/asterisk/ami/lexer/ami_fixtures.yml +0 -30
- data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story +0 -291
- data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story.rb +0 -241
- data/spec/adhearsion/voip/asterisk/ami/lexer/story_helper.rb +0 -124
- data/spec/adhearsion/voip/asterisk/commands_spec.rb +0 -3241
- data/spec/adhearsion/voip/asterisk/config_file_generators/agents_spec.rb +0 -251
- data/spec/adhearsion/voip/asterisk/config_file_generators/queues_spec.rb +0 -323
- data/spec/adhearsion/voip/asterisk/config_file_generators/voicemail_spec.rb +0 -306
- data/spec/adhearsion/voip/asterisk/config_manager_spec.rb +0 -127
- data/spec/adhearsion/voip/asterisk/menu_command/calculated_match_spec.rb +0 -109
- data/spec/adhearsion/voip/asterisk/menu_command/matchers_spec.rb +0 -97
- data/spec/adhearsion/voip/call_routing_spec.rb +0 -125
- data/spec/adhearsion/voip/dialplan_manager_spec.rb +0 -468
- data/spec/adhearsion/voip/dsl/dialing_dsl_spec.rb +0 -270
- data/spec/adhearsion/voip/dsl/dispatcher_spec.rb +0 -82
- data/spec/adhearsion/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/adhearsion/voip/dsl/parser_spec.rb +0 -69
- data/spec/adhearsion/voip/freeswitch/basic_connection_manager_spec.rb +0 -39
- data/spec/adhearsion/voip/freeswitch/inbound_connection_manager_spec.rb +0 -39
- data/spec/adhearsion/voip/freeswitch/oes_server_spec.rb +0 -9
- data/spec/adhearsion/voip/numerical_string_spec.rb +0 -61
- data/spec/adhearsion/voip/phone_number_spec.rb +0 -45
- data/spec/support/the_following_code.rb +0 -3
- data/spec/theatre/dsl_examples/simple_before_call.rb +0 -7
- data/spec/theatre/dsl_spec.rb +0 -69
- data/spec/theatre/invocation_spec.rb +0 -182
- data/spec/theatre/namespace_spec.rb +0 -125
- data/spec/theatre/spec_helper_spec.rb +0 -28
- data/spec/theatre/theatre_class_spec.rb +0 -148
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Adhearsion
|
4
|
+
module MenuDSL
|
5
|
+
describe CalculatedMatchCollection do
|
6
|
+
def mock_with_potential_matches(potential_matches)
|
7
|
+
CalculatedMatch.new :potential_matches => potential_matches
|
8
|
+
end
|
9
|
+
|
10
|
+
def mock_with_exact_matches(exact_matches)
|
11
|
+
CalculatedMatch.new :exact_matches => exact_matches
|
12
|
+
end
|
13
|
+
|
14
|
+
def mock_with_potential_and_exact_matches(potential_matches, exact_matches)
|
15
|
+
CalculatedMatch.new :potential_matches => potential_matches,
|
16
|
+
:exact_matches => exact_matches
|
17
|
+
end
|
18
|
+
|
19
|
+
it "the <<() method should collect the potential matches into the actual_potential_matches Array" do
|
20
|
+
mock_matches_array_1 = [:foo, :bar, :qaz],
|
21
|
+
mock_matches_array_2 = [10, 20, 30]
|
22
|
+
mock_matches_1 = mock_with_potential_matches mock_matches_array_1
|
23
|
+
mock_matches_2 = mock_with_potential_matches mock_matches_array_2
|
24
|
+
|
25
|
+
subject << mock_matches_1
|
26
|
+
subject.actual_potential_matches.should == mock_matches_array_1
|
27
|
+
|
28
|
+
subject << mock_matches_2
|
29
|
+
subject.actual_potential_matches.should == mock_matches_array_1 + mock_matches_array_2
|
30
|
+
end
|
31
|
+
|
32
|
+
it "the <<() method should collect the exact matches into the actual_exact_matches Array" do
|
33
|
+
mock_matches_array_1 = [:blam, :blargh],
|
34
|
+
mock_matches_array_2 = [5,4,3,2,1]
|
35
|
+
mock_matches_1 = mock_with_exact_matches mock_matches_array_1
|
36
|
+
mock_matches_2 = mock_with_exact_matches mock_matches_array_2
|
37
|
+
|
38
|
+
subject << mock_matches_1
|
39
|
+
subject.actual_exact_matches.should == mock_matches_array_1
|
40
|
+
|
41
|
+
subject << mock_matches_2
|
42
|
+
subject.actual_exact_matches.should == mock_matches_array_1 + mock_matches_array_2
|
43
|
+
end
|
44
|
+
|
45
|
+
it "if any exact matches exist, the exact_match?() method should return true" do
|
46
|
+
subject << mock_with_exact_matches([1,2,3])
|
47
|
+
subject.exact_match?.should be true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "if any potential matches exist, the potential_match?() method should return true" do
|
51
|
+
subject << mock_with_potential_matches([1,2,3])
|
52
|
+
subject.potential_match?.should be true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Adhearsion
|
4
|
+
module MenuDSL
|
5
|
+
describe CalculatedMatch do
|
6
|
+
it "should make accessible the context name" do
|
7
|
+
CalculatedMatch.new(:match_payload => :foobar).match_payload.should be :foobar
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should make accessible the original pattern" do
|
11
|
+
CalculatedMatch.new(:pattern => :something).pattern.should be :something
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should make accessible the matched query" do
|
15
|
+
CalculatedMatch.new(:query => 123).query.should be 123
|
16
|
+
end
|
17
|
+
|
18
|
+
it "#type_of_match should return :exact, :potential, or nil" do
|
19
|
+
CalculatedMatch.new(:potential_matches => [1]).type_of_match.should be :potential
|
20
|
+
CalculatedMatch.new(:exact_matches => [3,3]).type_of_match.should be :exact
|
21
|
+
CalculatedMatch.new(:exact_matches => [8,3], :potential_matches => [0,9]).type_of_match.should be :exact
|
22
|
+
end
|
23
|
+
|
24
|
+
it "#exact_match? should return true if the match was exact" do
|
25
|
+
CalculatedMatch.new(:exact_matches => [0,3,5]).exact_match?.should be true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "#potential_match? should return true if the match was exact" do
|
29
|
+
CalculatedMatch.new(:potential_matches => [88,99,77]).potential_match?.should be true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "#failed_match? should return false if the match was exact" do
|
33
|
+
CalculatedMatch.new(:potential_matches => [88,99,77]).failed_match?.should be false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "#exact_matches should return an array of exact matches" do
|
37
|
+
CalculatedMatch.new(:exact_matches => [0,3,5]).exact_matches.should == [0,3,5]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#potential_matches should return an array of potential matches" do
|
41
|
+
CalculatedMatch.new(:potential_matches => [88,99,77]).potential_matches.should == [88,99,77]
|
42
|
+
end
|
43
|
+
|
44
|
+
it "::failed_match! should return a match that *really* failed" do
|
45
|
+
failure = CalculatedMatch.failed_match! 10..20, 30, :match_payload_does_not_matter
|
46
|
+
failure.exact_match?.should_not be true
|
47
|
+
failure.potential_match?.should_not be true
|
48
|
+
failure.failed_match?.should be true
|
49
|
+
failure.type_of_match.should be nil
|
50
|
+
|
51
|
+
failure.match_payload.should be :match_payload_does_not_matter
|
52
|
+
failure.pattern.should == (10..20)
|
53
|
+
failure.query.should == 30
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Adhearsion
|
4
|
+
module MenuDSL
|
5
|
+
describe FixnumMatchCalculator do
|
6
|
+
let(:match_payload) { :main }
|
7
|
+
|
8
|
+
it "a potential match scenario" do
|
9
|
+
calculator = FixnumMatchCalculator.new(444, match_payload)
|
10
|
+
match = calculator.match 4
|
11
|
+
match.potential_match?.should be true
|
12
|
+
match.exact_match?.should_not be true
|
13
|
+
match.potential_matches.should == [444]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "a multi-digit exact match scenario" do
|
17
|
+
calculator = FixnumMatchCalculator.new(5555, match_payload)
|
18
|
+
calculator.match(5555).exact_match?.should be true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "a single-digit exact match scenario" do
|
22
|
+
calculator = FixnumMatchCalculator.new(1, match_payload)
|
23
|
+
calculator.match(1).exact_match?.should be true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "the context name given to the calculator should be passed on the CalculatedMatch" do
|
27
|
+
match_payload = :icanhascheezburger
|
28
|
+
calculator = FixnumMatchCalculator.new(1337, match_payload)
|
29
|
+
calculator.match(1337).match_payload.should be match_payload
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Adhearsion
|
4
|
+
module MenuDSL
|
5
|
+
describe MatchCalculator do
|
6
|
+
describe ".build_with_pattern" do
|
7
|
+
it "should return an appropriate subclass instance based on the pattern's class" do
|
8
|
+
MatchCalculator.build_with_pattern(1..2, :main).should be_an_instance_of RangeMatchCalculator
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Adhearsion
|
4
|
+
module MenuDSL
|
5
|
+
|
6
|
+
describe MenuBuilder do
|
7
|
+
subject{ MenuDSL::MenuBuilder.new }
|
8
|
+
|
9
|
+
describe "#build" do
|
10
|
+
it "sets the context and instance_eval's the block" do
|
11
|
+
flexmock(subject).should_receive(:foo).with(:bar)
|
12
|
+
subject.build do
|
13
|
+
foo :bar
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end#build
|
17
|
+
|
18
|
+
describe "#match" do
|
19
|
+
let(:match_block) { Proc.new() {} }
|
20
|
+
it "raises an exception if called without a CallController and no block" do
|
21
|
+
expect { subject.match 1 }.to raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "raises an exception if given both a payload and a block" do
|
25
|
+
expect { subject.match(1, Object) {} }.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "raises an exception if given no patterns" do
|
29
|
+
expect { subject.match() {} }.to raise_error(ArgumentError, "You cannot call this method without patterns.")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "creates a pattern based on a payload" do
|
33
|
+
flexmock(MenuDSL::MatchCalculator).should_receive(:build_with_pattern).with("1", Object)
|
34
|
+
subject.match "1", Object
|
35
|
+
end
|
36
|
+
|
37
|
+
it "creates a pattern based on a block" do
|
38
|
+
flexmock(MenuDSL::MatchCalculator).should_receive(:build_with_pattern).with("1", nil, match_block)
|
39
|
+
subject.match("1", &match_block)
|
40
|
+
end
|
41
|
+
it "creates multiple patterns if multiple arguments are passed in" do
|
42
|
+
flexmock(MenuDSL::MatchCalculator).should_receive(:build_with_pattern).with(1, Object)
|
43
|
+
flexmock(MenuDSL::MatchCalculator).should_receive(:build_with_pattern).with(2, Object)
|
44
|
+
subject.match(1, 2, Object)
|
45
|
+
end
|
46
|
+
end#match
|
47
|
+
|
48
|
+
describe "#weighted_match_calculators" do
|
49
|
+
let(:expected_pattern) { MenuDSL::MatchCalculator.build_with_pattern("1", Object) }
|
50
|
+
|
51
|
+
it "returns the generated patterns" do
|
52
|
+
flexmock(MenuDSL::MatchCalculator).should_receive(:build_with_pattern).with("1", Object).and_return(expected_pattern)
|
53
|
+
subject.match("1", Object)
|
54
|
+
subject.weighted_match_calculators.should == [expected_pattern]
|
55
|
+
end
|
56
|
+
end#weighted_match_calculators
|
57
|
+
|
58
|
+
describe "#invalid" do
|
59
|
+
let(:callback) { Proc.new() {} }
|
60
|
+
|
61
|
+
it "raises an error if not passed a block" do
|
62
|
+
expect { subject.invalid }.to raise_error(LocalJumpError)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "sets the invalid callback" do
|
66
|
+
subject.invalid(&callback)
|
67
|
+
subject.menu_callbacks[:invalid].should == callback
|
68
|
+
end
|
69
|
+
end#invalid
|
70
|
+
|
71
|
+
describe "#timeout" do
|
72
|
+
let(:callback) { Proc.new() {} }
|
73
|
+
|
74
|
+
it "raises an error if not passed a block" do
|
75
|
+
expect { subject.timeout }.to raise_error(LocalJumpError)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "sets the timeout callback" do
|
79
|
+
subject.timeout(&callback)
|
80
|
+
subject.menu_callbacks[:timeout].should == callback
|
81
|
+
end
|
82
|
+
end#timeout
|
83
|
+
|
84
|
+
describe "#failure" do
|
85
|
+
let(:callback) { Proc.new() {} }
|
86
|
+
|
87
|
+
it "raises an error if not passed a block" do
|
88
|
+
expect { subject.failure }.to raise_error(LocalJumpError)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "sets the failure callback" do
|
92
|
+
subject.failure(&callback)
|
93
|
+
subject.menu_callbacks[:failure].should == callback
|
94
|
+
end
|
95
|
+
end#failure
|
96
|
+
|
97
|
+
describe "#execute_hook_for" do
|
98
|
+
it "executes the correct hook" do
|
99
|
+
bar = nil
|
100
|
+
subject.invalid do |baz|
|
101
|
+
bar = baz
|
102
|
+
end
|
103
|
+
subject.execute_hook_for(:invalid, "1")
|
104
|
+
bar.should == "1"
|
105
|
+
end
|
106
|
+
end#execute_hook_for
|
107
|
+
|
108
|
+
describe "#calculate_matches_for" do
|
109
|
+
it "returns a calculated match collection" do
|
110
|
+
subject.match("1", Object)
|
111
|
+
subject.calculate_matches_for("1").should be_a CalculatedMatchCollection
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end# describe MenuBuilder
|
116
|
+
|
117
|
+
end# module MenuDSL
|
118
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Adhearsion
|
4
|
+
module MenuDSL
|
5
|
+
describe Menu do
|
6
|
+
|
7
|
+
let(:options) { Hash.new }
|
8
|
+
subject { Menu.new(options) {} }
|
9
|
+
|
10
|
+
describe "#initialize" do
|
11
|
+
|
12
|
+
its(:tries_count) { should == 0 }
|
13
|
+
|
14
|
+
|
15
|
+
context 'when no timeout is set' do
|
16
|
+
it "should have the default timeout" do
|
17
|
+
subject.timeout.should == 5
|
18
|
+
end
|
19
|
+
end
|
20
|
+
context 'when a timeout is set' do
|
21
|
+
let(:options) {
|
22
|
+
{:timeout => 20}
|
23
|
+
}
|
24
|
+
it 'should have the passed timeout' do
|
25
|
+
subject.timeout.should == 20
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when no max number of tries is set' do
|
30
|
+
it "should have the default max number of tries" do
|
31
|
+
subject.max_number_of_tries.should == 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context 'when a max number of tries is set' do
|
35
|
+
let(:options) {
|
36
|
+
{:tries => 3}
|
37
|
+
}
|
38
|
+
it 'should have the passed max number of tries' do
|
39
|
+
subject.max_number_of_tries.should == 3
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'menu builder setup' do
|
44
|
+
its(:builder) { should be_a MenuBuilder }
|
45
|
+
|
46
|
+
it "should evaluate the block on the builder object" do
|
47
|
+
mock_menu_builder = flexmock(MenuBuilder.new)
|
48
|
+
flexmock(MenuBuilder).should_receive(:new).and_return(mock_menu_builder)
|
49
|
+
mock_menu_builder.should_receive(:match).once.with(1)
|
50
|
+
Menu.new {match 1}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end # describe #initialize
|
55
|
+
|
56
|
+
describe "#digit_buffer" do
|
57
|
+
its(:digit_buffer) { should be_a Menu::ClearableStringBuffer }
|
58
|
+
its(:digit_buffer) { should == "" }
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#<<" do
|
62
|
+
it "should add a digit to the buffer" do
|
63
|
+
subject << 'a'
|
64
|
+
subject.digit_buffer.should == 'a'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#digit_buffer_empty?" do
|
69
|
+
it "returns true if buffer is empty" do
|
70
|
+
subject.digit_buffer_empty?.should == true
|
71
|
+
end
|
72
|
+
it "returns false if buffer is not empty" do
|
73
|
+
subject << 1
|
74
|
+
subject.digit_buffer_empty?.should == false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#digit_buffer_string" do
|
79
|
+
it "returns the digit buffer as a string" do
|
80
|
+
subject << 1
|
81
|
+
subject.digit_buffer_string.should == "1"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#should_continue?" do
|
86
|
+
it "returns true if the number of tries is less than the maximum" do
|
87
|
+
subject.max_number_of_tries.should == 1
|
88
|
+
subject.tries_count.should == 0
|
89
|
+
subject.should_continue?.should == true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#restart!" do
|
94
|
+
it "increments tries and clears the digit buffer" do
|
95
|
+
subject << 1
|
96
|
+
subject.restart!
|
97
|
+
subject.tries_count.should == 1
|
98
|
+
subject.digit_buffer_empty?.should == true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#execute_invalid_hook" do
|
103
|
+
it "calls the builder's execute_hook_for with :invalid" do
|
104
|
+
mock_menu_builder = flexmock(MenuBuilder.new)
|
105
|
+
flexmock(MenuBuilder).should_receive(:new).and_return(mock_menu_builder)
|
106
|
+
mock_menu_builder.should_receive(:execute_hook_for).with(:invalid, "")
|
107
|
+
menu_instance = Menu.new() {}
|
108
|
+
menu_instance.execute_invalid_hook
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#execute_timeout_hook" do
|
113
|
+
it "calls the builder's execute_hook_for with :timeout" do
|
114
|
+
mock_menu_builder = flexmock(MenuBuilder.new)
|
115
|
+
flexmock(MenuBuilder).should_receive(:new).and_return(mock_menu_builder)
|
116
|
+
mock_menu_builder.should_receive(:execute_hook_for).with(:timeout, "")
|
117
|
+
menu_instance = Menu.new() {}
|
118
|
+
menu_instance.execute_timeout_hook
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "#execute_failure_hook" do
|
123
|
+
it "calls the builder's execute_hook_for with :failure" do
|
124
|
+
mock_menu_builder = flexmock(MenuBuilder.new)
|
125
|
+
flexmock(MenuBuilder).should_receive(:new).and_return(mock_menu_builder)
|
126
|
+
mock_menu_builder.should_receive(:execute_hook_for).with(:failure, "")
|
127
|
+
menu_instance = Menu.new() {}
|
128
|
+
menu_instance.execute_failure_hook
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#continue" do
|
133
|
+
class MockControllerA; end
|
134
|
+
class MockControllerB; end
|
135
|
+
class MockControllerC; end
|
136
|
+
let(:menu_instance) {
|
137
|
+
Menu.new do
|
138
|
+
match 1, MockControllerA
|
139
|
+
match 21, MockControllerA
|
140
|
+
match 23, MockControllerA
|
141
|
+
match 3, MockControllerB
|
142
|
+
match 3..5, MockControllerC
|
143
|
+
match 33, MockControllerA
|
144
|
+
match 6, MockControllerC
|
145
|
+
match 6..8, MockControllerA
|
146
|
+
end
|
147
|
+
}
|
148
|
+
it "returns a MenuGetAnotherDigitOrTimeout if the digit buffer is empty" do
|
149
|
+
subject.continue.should be_a Menu::MenuGetAnotherDigitOrTimeout
|
150
|
+
end
|
151
|
+
|
152
|
+
it "asks for another digit if it has potential matches" do
|
153
|
+
menu_instance << 2
|
154
|
+
menu_instance.continue.should be_a Menu::MenuGetAnotherDigitOrTimeout
|
155
|
+
end
|
156
|
+
|
157
|
+
it "returns a MenuResultInvalid if there are no matches" do
|
158
|
+
menu_instance << 9
|
159
|
+
menu_instance.continue.should be_a Menu::MenuResultInvalid
|
160
|
+
end
|
161
|
+
|
162
|
+
it "returns a MenuGetAnotherDigitOrFinish if it has exact and potential matches" do
|
163
|
+
menu_instance << 3
|
164
|
+
menu_result = menu_instance.continue
|
165
|
+
menu_result.should be_a Menu::MenuGetAnotherDigitOrFinish
|
166
|
+
end
|
167
|
+
|
168
|
+
it "returns the first exact match when it has exact and potentials" do
|
169
|
+
menu_instance << 3
|
170
|
+
menu_result = menu_instance.continue
|
171
|
+
menu_result.should be_a Menu::MenuGetAnotherDigitOrFinish
|
172
|
+
menu_result.match_object.should == MockControllerB
|
173
|
+
menu_result.new_extension.should == "3"
|
174
|
+
end
|
175
|
+
|
176
|
+
it "returns a MenuResultFound if it has exact matches" do
|
177
|
+
menu_instance << 6
|
178
|
+
menu_result = menu_instance.continue
|
179
|
+
menu_result.should be_a Menu::MenuResultFound
|
180
|
+
end
|
181
|
+
|
182
|
+
it "returns the first exact match when it has only exact matches" do
|
183
|
+
menu_instance << 6
|
184
|
+
menu_result = menu_instance.continue
|
185
|
+
menu_result.should be_a Menu::MenuResultFound
|
186
|
+
menu_result.match_object.match_payload.should == MockControllerC
|
187
|
+
menu_result.match_object.pattern.to_s.should == "6"
|
188
|
+
end
|
189
|
+
|
190
|
+
end#continue
|
191
|
+
|
192
|
+
describe Menu::ClearableStringBuffer do
|
193
|
+
subject { Menu::ClearableStringBuffer.new }
|
194
|
+
|
195
|
+
it "adds a string to itself" do
|
196
|
+
subject << 'b'
|
197
|
+
subject << 'c'
|
198
|
+
subject.should == 'bc'
|
199
|
+
end
|
200
|
+
|
201
|
+
it "clears itself" do
|
202
|
+
subject << 'a'
|
203
|
+
subject.clear!
|
204
|
+
subject.should == ""
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
end # describe Menu
|
209
|
+
end
|
210
|
+
end
|