adhearsion 1.2.6 → 2.0.0.alpha1
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.
- 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
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'adhearsion/voip/freeswitch/basic_connection_manager'
|
|
3
|
-
|
|
4
|
-
include Adhearsion::VoIP::FreeSwitch
|
|
5
|
-
|
|
6
|
-
describe "FreeSwitch BasicConnectionManager" do
|
|
7
|
-
attr_reader :manager, :io
|
|
8
|
-
before(:each) do
|
|
9
|
-
@io = StringIO.new
|
|
10
|
-
@manager = BasicConnectionManager.new io
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "<<() should add two newlines" do
|
|
14
|
-
manager << "foobar"
|
|
15
|
-
io.string.should == "foobar\n\n"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "FreeSwitch BasicConnectionManager's header parser" do
|
|
21
|
-
it "YAML-like headers are read properly" do
|
|
22
|
-
header = {
|
|
23
|
-
"Foo-Bar" => "bar",
|
|
24
|
-
"Qaz-Monkey-Charlie-Zebra" => "qwerty"
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
string_header = header.inject("") do |string, (key, value)|
|
|
28
|
-
string + "#{key}: #{value}\n"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
string_header << "\n"
|
|
32
|
-
|
|
33
|
-
manager = BasicConnectionManager.new StringIO.new(string_header)
|
|
34
|
-
manager.get_raw_header.should == string_header.strip
|
|
35
|
-
|
|
36
|
-
manager = BasicConnectionManager.new StringIO.new(string_header)
|
|
37
|
-
manager.get_header.should == header
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'adhearsion/voip/freeswitch/inbound_connection_manager'
|
|
3
|
-
include Adhearsion::VoIP::FreeSwitch
|
|
4
|
-
|
|
5
|
-
describe "A FreeSwitch InboundConnectionManager" do
|
|
6
|
-
|
|
7
|
-
it "authenticatating with the given password" do
|
|
8
|
-
manager = InboundConnectionManager.new io_mock
|
|
9
|
-
manager.login password
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "a hash is accepted when creating a new InboundConnectionManager" do
|
|
13
|
-
host, port = "myhost.mydomain", 31337
|
|
14
|
-
|
|
15
|
-
flexmock(TCPSocket).should_receive(:new).once.with(host, port).and_return io_mock
|
|
16
|
-
|
|
17
|
-
InboundConnectionManager.new :host => host, :port => port, :pass => password
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "an IO is accepted when creating a new InboundConnectionManager"
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
def io_mock
|
|
24
|
-
@io_mock ||=
|
|
25
|
-
begin
|
|
26
|
-
io_mock = StringIO.new
|
|
27
|
-
flexmock(io_mock) do |io|
|
|
28
|
-
io.should_receive(:write).with("auth #{password}\n\n")
|
|
29
|
-
io.should_receive(:gets).and_return "connection: kthnx\n",
|
|
30
|
-
"\n", "login: +OK\n", "\n"
|
|
31
|
-
end
|
|
32
|
-
io_mock
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def password
|
|
37
|
-
"supersecret"
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require File.dirname(__FILE__) + "/../dsl/dispatcher_spec_helper"
|
|
3
|
-
require 'adhearsion/voip/freeswitch/oes_server'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
describe "Adhearsion::VoIP::FreeSwitch::OesServer::OesDispatcher" do
|
|
7
|
-
include StandardDispatcherBehavior
|
|
8
|
-
before(:each) { @dispatcher_class = Adhearsion::VoIP::FreeSwitch::OesServer::OesDispatcher }
|
|
9
|
-
end
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
require 'adhearsion/voip/dsl/numerical_string'
|
|
4
|
-
require 'adhearsion/voip/constants'
|
|
5
|
-
|
|
6
|
-
describe "A NumericalString" do
|
|
7
|
-
# FIXME: This test is fundamentally broken in Ruby 1.9.
|
|
8
|
-
# See https://adhearsion.lighthouseapp.com/projects/5871/tickets/127-ruby-19-and-numericalstring-comparisons-in-case-statements
|
|
9
|
-
# The suggested workaround is to cast the object to a string:
|
|
10
|
-
# case numerical_string_object.to_s
|
|
11
|
-
# when "0987" then ...
|
|
12
|
-
# end
|
|
13
|
-
# it "should appear to be behave like a Fixnum in a case statement" do
|
|
14
|
-
# case numerical_string_for("123")
|
|
15
|
-
# when 123 then true
|
|
16
|
-
# else false
|
|
17
|
-
# end.should be true
|
|
18
|
-
#
|
|
19
|
-
# case numerical_string_for("0987")
|
|
20
|
-
# when 987 then true
|
|
21
|
-
# else false
|
|
22
|
-
# end.should be true
|
|
23
|
-
# end
|
|
24
|
-
|
|
25
|
-
it "should appear to behave like a String in a case statement" do
|
|
26
|
-
numerical_string_for("123").should === "123"
|
|
27
|
-
numerical_string_for("0987").should === "0987"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "when compared against a Range that contains the numeric equivalent, the NumericalString is seen as a member" do
|
|
31
|
-
(100..200).should === numerical_string_for("150")
|
|
32
|
-
(100..200).should === numerical_string_for("0150")
|
|
33
|
-
(100..200).should_not === numerical_string_for("1000000")
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "comparing against a regular expression works" do
|
|
37
|
-
%r|^\d+$|.should === numerical_string_for("027316287")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "checking if a string representation of a number starts with a leading zero" do
|
|
41
|
-
with_leading_zeros = %w(01 01234 01.23 01.2)
|
|
42
|
-
without_leading_zeros = %w(1 1.2 0 0.0)
|
|
43
|
-
|
|
44
|
-
with_leading_zeros.each do |number|
|
|
45
|
-
numerical_string.starts_with_leading_zero?(number).should_not be false
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
without_leading_zeros.each do |number|
|
|
49
|
-
numerical_string.starts_with_leading_zero?(number).should_not be true
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
private
|
|
54
|
-
def numerical_string
|
|
55
|
-
Adhearsion::VoIP::DSL::NumericalString
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def numerical_string_for(string)
|
|
59
|
-
numerical_string.new(string)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'adhearsion/voip/constants'
|
|
3
|
-
require 'adhearsion/voip/dsl/numerical_string'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
# Use cases...
|
|
7
|
-
# case extension
|
|
8
|
-
# when US_NUMBER
|
|
9
|
-
# when (100..200)
|
|
10
|
-
# when _('12Z')
|
|
11
|
-
# when 123
|
|
12
|
-
# when "123"
|
|
13
|
-
# end
|
|
14
|
-
|
|
15
|
-
def should_be_nil_or_false(arg)
|
|
16
|
-
[nil, false].include?(arg).should == true
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def should_not_be_nil_or_false(arg)
|
|
20
|
-
[nil, false].include?(arg).should == false
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe "A PhoneNumber" do
|
|
24
|
-
|
|
25
|
-
it "should have an ISN pattern-matching method" do
|
|
26
|
-
should_be_nil_or_false Adhearsion::VoIP::DSL::PhoneNumber.new("0115544332211").isn?
|
|
27
|
-
should_not_be_nil_or_false Adhearsion::VoIP::DSL::PhoneNumber.new("1*548").isn?
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "should have a US local number pattern-matching method" do
|
|
31
|
-
should_be_nil_or_false Adhearsion::VoIP::DSL::PhoneNumber.new("18887776665555").us_local_number?
|
|
32
|
-
should_be_nil_or_false Adhearsion::VoIP::DSL::PhoneNumber.new("18887776665555").us_national_number?
|
|
33
|
-
|
|
34
|
-
should_be_nil_or_false Adhearsion::VoIP::DSL::PhoneNumber.new("8887776665555").us_local_number?
|
|
35
|
-
should_be_nil_or_false Adhearsion::VoIP::DSL::PhoneNumber.new("8887776665555").us_national_number?
|
|
36
|
-
|
|
37
|
-
should_not_be_nil_or_false Adhearsion::VoIP::DSL::PhoneNumber.new("4445555").us_local_number?
|
|
38
|
-
should_be_nil_or_false Adhearsion::VoIP::DSL::PhoneNumber.new("4445555").us_national_number?
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "should convert from vanity numbers properly" do
|
|
42
|
-
Adhearsion::VoIP::DSL::PhoneNumber.from_vanity("1-800-FUDGEME").should == "18003834363"
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
data/spec/theatre/dsl_spec.rb
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
class Example
|
|
4
|
-
attr_reader :name, :yaml, :metadata, :file
|
|
5
|
-
|
|
6
|
-
def initialize(name)
|
|
7
|
-
@name = name.to_sym
|
|
8
|
-
@file = File.expand_path(File.dirname(__FILE__) + "/dsl_examples/#{name}.rb")
|
|
9
|
-
@yaml = file_contents[/=begin YAML\n(.+?)\n=end/m, 1]
|
|
10
|
-
@metadata = @yaml.nil? ? nil : YAML.load(@yaml)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def file_contents
|
|
14
|
-
File.read @file
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def register_namespaces_on(obj)
|
|
18
|
-
obj = obj.namespace_manager if obj.kind_of? Theatre::Theatre
|
|
19
|
-
namespaces = metadata["namespaces"]
|
|
20
|
-
if namespaces && namespaces.kind_of?(Array) && namespaces.any?
|
|
21
|
-
namespaces.each do |namespace|
|
|
22
|
-
obj.register_namespace_name namespace
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
obj
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe "CallbackDefinitionContainer" do
|
|
30
|
-
|
|
31
|
-
it "should successfully load the :simple_before_call example" do
|
|
32
|
-
example = Example.new(:simple_before_call)
|
|
33
|
-
theatre = Theatre::Theatre.new
|
|
34
|
-
example.register_namespaces_on theatre
|
|
35
|
-
|
|
36
|
-
flexmock(theatre.namespace_manager).should_receive(:register_callback_at_namespace).
|
|
37
|
-
with([:asterisk, :before_call], Proc).once
|
|
38
|
-
|
|
39
|
-
loader = Theatre::CallbackDefinitionLoader.new(theatre)
|
|
40
|
-
loader.load_events_file example.file
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "should let you override the recorder method name" do
|
|
44
|
-
theatre = Theatre::Theatre.new
|
|
45
|
-
theatre.namespace_manager.register_namespace_name "/foo/bar/qaz"
|
|
46
|
-
flexmock(theatre.namespace_manager).should_receive(:register_callback_at_namespace).
|
|
47
|
-
with([:foo, :bar, :qaz], Proc).once
|
|
48
|
-
|
|
49
|
-
loader = Theatre::CallbackDefinitionLoader.new(theatre, :roflcopter)
|
|
50
|
-
loader.roflcopter.foo.bar.qaz.each {}
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# High level specs to test the entire library.
|
|
56
|
-
|
|
57
|
-
describe "Misuses of the Theatre" do
|
|
58
|
-
|
|
59
|
-
it "should not allow callbacks to be registered for namespaces which have not been registered" do
|
|
60
|
-
theatre = Theatre::Theatre.new
|
|
61
|
-
example = Example.new(:simple_before_call)
|
|
62
|
-
|
|
63
|
-
loader = Theatre::CallbackDefinitionLoader.new(theatre)
|
|
64
|
-
lambda do
|
|
65
|
-
loader.events.foo.each {}
|
|
66
|
-
end.should raise_error(Theatre::NamespaceNotFound)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
end
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
GUID_REGEXP = /^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/i
|
|
4
|
-
|
|
5
|
-
module InvocationTestHelper
|
|
6
|
-
def new_invocation(payload=@payload)
|
|
7
|
-
Theatre::Invocation.new(@namespace, @block, @payload)
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe "The lifecycle of an Invocation" do
|
|
12
|
-
|
|
13
|
-
include InvocationTestHelper
|
|
14
|
-
|
|
15
|
-
before :all do
|
|
16
|
-
@block = lambda {}
|
|
17
|
-
@payload = 123
|
|
18
|
-
@namespace = "/some/namespace"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "should have an initial state of :new" do
|
|
22
|
-
new_invocation.current_state.should eql(:new)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "should not have a @queued_time until state becomes :queued" do
|
|
26
|
-
invocation = new_invocation
|
|
27
|
-
invocation.queued_time.should eql(nil)
|
|
28
|
-
invocation.queued
|
|
29
|
-
invocation.queued_time.should be_instance_of(Time)
|
|
30
|
-
invocation.current_state.should eql(:queued)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should have a valid guid when instantiated" do
|
|
34
|
-
new_invocation.unique_id.should =~ GUID_REGEXP
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "should execute the callback when moving to the 'start' state" do
|
|
38
|
-
flexmock(@block).should_receive(:call).once
|
|
39
|
-
invocation = new_invocation
|
|
40
|
-
invocation.queued
|
|
41
|
-
invocation.start
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe "Using Invocations that've been ran through the Theatre" do
|
|
47
|
-
|
|
48
|
-
it "should pass the payload to the callback" do
|
|
49
|
-
destined_payload = [:i_feel_so_pretty, :OH, :SO, :PRETTY!]
|
|
50
|
-
expecting_callback = lambda do |payload|
|
|
51
|
-
payload.should equal(destined_payload)
|
|
52
|
-
end
|
|
53
|
-
invocation = Theatre::Invocation.new("/namespace/whatever", expecting_callback, destined_payload)
|
|
54
|
-
invocation.queued
|
|
55
|
-
invocation.start
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "should have a status of :error if an exception was raised and set the #error property" do
|
|
59
|
-
invocation = Theatre::Invocation.new("/namespace/whatever", lambda { raise ArgumentError, "this error is intentional" })
|
|
60
|
-
invocation.queued
|
|
61
|
-
invocation.start
|
|
62
|
-
invocation.current_state.should == :error
|
|
63
|
-
invocation.should be_error
|
|
64
|
-
invocation.error.should be_instance_of(ArgumentError)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "should trigger an exception event if an exception was raised" do
|
|
68
|
-
invocation = Theatre::Invocation.new("/namespace/whatever", lambda { raise ArgumentError, "this error is intentional" })
|
|
69
|
-
flexmock(Adhearsion::Events).should_receive(:trigger).once.with('/exception', FlexMock.any)
|
|
70
|
-
invocation.queued
|
|
71
|
-
invocation.start
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should NOT trigger an exception if the exception occurs in an exception namespace" do
|
|
75
|
-
invocation = Theatre::Invocation.new("/exception", lambda { raise ArgumentError, "this error is intentional" })
|
|
76
|
-
flexmock(Adhearsion::Events).should_receive(:trigger).never
|
|
77
|
-
invocation.queued
|
|
78
|
-
invocation.start
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "should do the right thing with exceptions triggered with the wrong namespace" do
|
|
82
|
-
invocation = Theatre::Invocation.new(['exception'], lambda { raise ArgumentError, "this error is intentional" })
|
|
83
|
-
flexmock(Adhearsion::Events).should_receive(:trigger).never
|
|
84
|
-
invocation.queued
|
|
85
|
-
invocation.start
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it "should have a status of :success if no expection was raised" do
|
|
89
|
-
callback = lambda { "No errors raised here!" }
|
|
90
|
-
invocation = Theatre::Invocation.new("/namespace/whatever", callback)
|
|
91
|
-
invocation.queued
|
|
92
|
-
invocation.start
|
|
93
|
-
invocation.current_state.should equal(:success)
|
|
94
|
-
invocation.should be_success
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "should set the #returned_value property to the returned value callback when a payload was given" do
|
|
98
|
-
doubler = lambda { |num| num * 2 }
|
|
99
|
-
invocation = Theatre::Invocation.new('/foo/bar', doubler, 5)
|
|
100
|
-
invocation.queued
|
|
101
|
-
invocation.start
|
|
102
|
-
invocation.returned_value.should equal(10)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "should set the #returned_value property to the returned value callback when a payload was NOT given" do
|
|
106
|
-
doubler = lambda { :ohai }
|
|
107
|
-
invocation = Theatre::Invocation.new('/foo/bar', doubler)
|
|
108
|
-
invocation.queued
|
|
109
|
-
invocation.start
|
|
110
|
-
invocation.returned_value.should equal(:ohai)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it "should set the #finished_time property when a success was encountered" do
|
|
114
|
-
block = lambda {}
|
|
115
|
-
invocation = Theatre::Invocation.new('/foo/bar', block)
|
|
116
|
-
invocation.queued
|
|
117
|
-
|
|
118
|
-
now = Time.now
|
|
119
|
-
flexmock(Time).should_receive(:now).twice.and_return now
|
|
120
|
-
|
|
121
|
-
invocation.start
|
|
122
|
-
invocation.should be_success
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
it "should set the #finished_time property when a failure was encountered" do
|
|
126
|
-
invocation = Theatre::Invocation.new('/foo/bar', lambda { raise LocalJumpError })
|
|
127
|
-
invocation.queued
|
|
128
|
-
|
|
129
|
-
invocation.start
|
|
130
|
-
invocation.should be_error
|
|
131
|
-
invocation.finished_time.should be_kind_of(Time)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it "should set the #started_time property after starting" do
|
|
135
|
-
invocation = Theatre::Invocation.new('/foo/bar', lambda { sleep 0.01 } )
|
|
136
|
-
invocation.queued
|
|
137
|
-
invocation.started_time.should be_nil
|
|
138
|
-
invocation.start
|
|
139
|
-
invocation.started_time.should be_kind_of(Time)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
it "should properly calculate #execution_duration" do
|
|
143
|
-
time_ago_difference = 60 * 5 # Five minutes
|
|
144
|
-
time_now = Time.now
|
|
145
|
-
time_ago = time_now - time_ago_difference
|
|
146
|
-
|
|
147
|
-
invocation = Theatre::Invocation.new('/foo/bar', lambda {} )
|
|
148
|
-
invocation.queued
|
|
149
|
-
invocation.start
|
|
150
|
-
|
|
151
|
-
invocation.send(:instance_variable_set, :@started_time, time_ago)
|
|
152
|
-
invocation.send(:instance_variable_set, :@finished_time, time_now)
|
|
153
|
-
|
|
154
|
-
invocation.execution_duration.should be_within(0.01).of(time_ago_difference.to_f)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "should return the set value of returned_value when one has been set to a non-nil value" do
|
|
158
|
-
return_nil = lambda { 123 }
|
|
159
|
-
invocation = Theatre::Invocation.new("/namespace/whatever", return_nil)
|
|
160
|
-
invocation.queued
|
|
161
|
-
invocation.start
|
|
162
|
-
invocation.returned_value.should eql(123)
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
it "should return nil for returned_value when it has been set to nil" do
|
|
166
|
-
return_nil = lambda { nil }
|
|
167
|
-
invocation = Theatre::Invocation.new("/namespace/whatever", return_nil)
|
|
168
|
-
invocation.queued
|
|
169
|
-
invocation.start
|
|
170
|
-
invocation.returned_value.should eql(nil)
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
it "waiting on an Invocation should execute properly" do
|
|
174
|
-
wait_on_invocation = lambda { 123 }
|
|
175
|
-
invocation = Theatre::Invocation.new("/namespace/whatever", wait_on_invocation)
|
|
176
|
-
invocation.queued
|
|
177
|
-
invocation.start
|
|
178
|
-
invocation.wait.should eql(123)
|
|
179
|
-
invocation.success?.should eql(true)
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
end
|