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
@@ -1,292 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'adhearsion/component_manager/component_tester'
|
3
|
-
|
4
|
-
module ComponentManagerTestHelper
|
5
|
-
|
6
|
-
def mock_component_config(component_name, yaml)
|
7
|
-
yaml = YAML.load(yaml) if yaml.kind_of?(String)
|
8
|
-
flexmock(@component_manager.lazy_config_loader).should_receive(component_name).and_return yaml
|
9
|
-
end
|
10
|
-
|
11
|
-
def run_component_code(code)
|
12
|
-
@component_manager.load_code(code)
|
13
|
-
end
|
14
|
-
|
15
|
-
def new_object_with_scope(scope)
|
16
|
-
@component_manager.extend_object_with(Object.new, scope)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "Adhearsion's component system" do
|
21
|
-
|
22
|
-
include ComponentManagerTestHelper
|
23
|
-
|
24
|
-
before :each do
|
25
|
-
@component_manager = Adhearsion::Components::ComponentManager.new "/filesystem/access/should/be/mocked/out"
|
26
|
-
Object.send :remove_const, :COMPONENTS if Object.const_defined?(:COMPONENTS)
|
27
|
-
Object.send :const_set, :COMPONENTS, @component_manager.lazy_config_loader
|
28
|
-
end
|
29
|
-
|
30
|
-
it "constants should be available in the main namespace" do
|
31
|
-
constant_name = "FOO_#{rand(10000000000)}"
|
32
|
-
begin
|
33
|
-
run_component_code <<-RUBY
|
34
|
-
#{constant_name} = 123
|
35
|
-
RUBY
|
36
|
-
Module.const_get(constant_name).should be 123
|
37
|
-
ensure
|
38
|
-
Object.send(:remove_const, constant_name) rescue nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it "defined constants should be available within the methods_for block" do
|
43
|
-
constant_name = "I_HAVE_#{rand(100000000000000)}_GUMMY_BEARS"
|
44
|
-
code = <<-RUBY
|
45
|
-
#{constant_name} = :its_true!
|
46
|
-
methods_for :dialplan do
|
47
|
-
throw #{constant_name}
|
48
|
-
end
|
49
|
-
RUBY
|
50
|
-
the_following_code {
|
51
|
-
run_component_code code
|
52
|
-
}.should throw_symbol :its_true!
|
53
|
-
end
|
54
|
-
|
55
|
-
it "initialization block should be called after the methods_for() blocks"
|
56
|
-
|
57
|
-
it "defined methods should be recognized once defined" do
|
58
|
-
run_component_code <<-RUBY
|
59
|
-
methods_for :events do
|
60
|
-
def foo
|
61
|
-
:inside_foo!
|
62
|
-
end
|
63
|
-
end
|
64
|
-
RUBY
|
65
|
-
container_object = new_object_with_scope :events
|
66
|
-
container_object.foo.should be :inside_foo!
|
67
|
-
end
|
68
|
-
|
69
|
-
it "a method defined in one scope should not be available in another" do
|
70
|
-
code = <<-RUBY
|
71
|
-
methods_for :events do
|
72
|
-
def in_events
|
73
|
-
in_dialplan
|
74
|
-
end
|
75
|
-
end
|
76
|
-
methods_for :dialplan do
|
77
|
-
def in_dialplan
|
78
|
-
in_events
|
79
|
-
end
|
80
|
-
end
|
81
|
-
RUBY
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
it "methods defined in separate blocks should be available if they share a scope" do
|
86
|
-
run_component_code <<-RUBY
|
87
|
-
methods_for :dialplan do
|
88
|
-
def get_symbol
|
89
|
-
:i_am_the_best_symbol_in_the_world
|
90
|
-
end
|
91
|
-
end
|
92
|
-
methods_for :dialplan do
|
93
|
-
def throw_best_symbol_in_the_world
|
94
|
-
throw get_symbol
|
95
|
-
end
|
96
|
-
end
|
97
|
-
RUBY
|
98
|
-
obj = new_object_with_scope :dialplan
|
99
|
-
the_following_code {
|
100
|
-
obj.throw_best_symbol_in_the_world
|
101
|
-
}.should throw_symbol :i_am_the_best_symbol_in_the_world
|
102
|
-
end
|
103
|
-
|
104
|
-
it "privately defined methods should remain private" do
|
105
|
-
return_value = "hear! hear! i'm private, indeed!"
|
106
|
-
run_component_code <<-RUBY
|
107
|
-
methods_for :generators do
|
108
|
-
def i_am_public
|
109
|
-
i_am_private.reverse
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
|
114
|
-
def i_am_private
|
115
|
-
"#{return_value}"
|
116
|
-
end
|
117
|
-
end
|
118
|
-
RUBY
|
119
|
-
object = new_object_with_scope(:generators)
|
120
|
-
object.i_am_public.should == return_value.reverse
|
121
|
-
the_following_code {
|
122
|
-
object.i_am_private
|
123
|
-
}.should raise_error NoMethodError
|
124
|
-
end
|
125
|
-
|
126
|
-
it "load_components should load code with the proper filenames" do
|
127
|
-
components_dir_path = "/path/to/somewhere/components"
|
128
|
-
component_names = %w[fooo barr qazz]
|
129
|
-
component_paths = component_names.map { |name| "#{components_dir_path}/#{name}" }
|
130
|
-
|
131
|
-
flexmock(Dir).should_receive(:glob).once.with(components_dir_path + "/*").
|
132
|
-
and_return(component_paths + ["disabled"])
|
133
|
-
flexstub(File).should_receive(:exists?).and_return true
|
134
|
-
flexstub(File).should_receive(:directory?).and_return true
|
135
|
-
|
136
|
-
manager = Adhearsion::Components::ComponentManager.new(components_dir_path)
|
137
|
-
component_paths.each do |path|
|
138
|
-
flexmock(manager).should_receive(:load_file).once.with "#{path}/lib/#{File.basename(path)}.rb"
|
139
|
-
end
|
140
|
-
|
141
|
-
manager.load_components
|
142
|
-
end
|
143
|
-
|
144
|
-
it "the :global scope" do
|
145
|
-
run_component_code <<-RUBY
|
146
|
-
methods_for :global do
|
147
|
-
def i_should_be_globally_available
|
148
|
-
:found!
|
149
|
-
end
|
150
|
-
end
|
151
|
-
RUBY
|
152
|
-
@component_manager.globalize_global_scope!
|
153
|
-
i_should_be_globally_available.should be :found!
|
154
|
-
end
|
155
|
-
|
156
|
-
it "methods defined in outside of any scope should not be globally available" do
|
157
|
-
run_component_code <<-RUBY
|
158
|
-
def i_should_not_be_globally_available
|
159
|
-
:found!
|
160
|
-
end
|
161
|
-
RUBY
|
162
|
-
the_following_code {
|
163
|
-
i_should_not_be_globally_available
|
164
|
-
}.should raise_error NameError
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should have access to the COMPONENTS constant" do
|
168
|
-
component_name = "am_not_for_kokoa"
|
169
|
-
mock_component_config(component_name, <<-YAML)
|
170
|
-
host: localhost
|
171
|
-
port: 7007
|
172
|
-
array:
|
173
|
-
- 1
|
174
|
-
- 2
|
175
|
-
- 3
|
176
|
-
YAML
|
177
|
-
run_component_code <<-RUBY
|
178
|
-
methods_for(:dialplan) do
|
179
|
-
def host
|
180
|
-
COMPONENTS.#{component_name}["host"]
|
181
|
-
end
|
182
|
-
def port
|
183
|
-
COMPONENTS.#{component_name}["port"]
|
184
|
-
end
|
185
|
-
def array
|
186
|
-
COMPONENTS.#{component_name}["array"]
|
187
|
-
end
|
188
|
-
end
|
189
|
-
RUBY
|
190
|
-
obj = new_object_with_scope :dialplan
|
191
|
-
obj.host.should =="localhost"
|
192
|
-
obj.port.should ==7007
|
193
|
-
obj.array.should ==[1,2,3]
|
194
|
-
end
|
195
|
-
|
196
|
-
it "the delegate method should properly delegate arguments and a block to a specified object" do
|
197
|
-
component_name = "writing_this_at_peets_coffee"
|
198
|
-
mock_component_config(component_name, "{jay: phillips}")
|
199
|
-
run_component_code <<-RUBY
|
200
|
-
|
201
|
-
initialization do
|
202
|
-
obj = Object.new
|
203
|
-
def obj.foo
|
204
|
-
:foo
|
205
|
-
end
|
206
|
-
def obj.bar
|
207
|
-
:bar
|
208
|
-
end
|
209
|
-
COMPONENTS.#{component_name}[:foobar] = obj
|
210
|
-
end
|
211
|
-
|
212
|
-
methods_for :dialplan do
|
213
|
-
delegate :#{component_name}, :to => :COMPONENTS
|
214
|
-
end
|
215
|
-
RUBY
|
216
|
-
obj = new_object_with_scope :dialplan
|
217
|
-
obj.send(component_name)[:foobar].foo.should be :foo
|
218
|
-
end
|
219
|
-
|
220
|
-
it "an initialized component should not have an 'initialize' private method since it's confusing"
|
221
|
-
|
222
|
-
it "should find components in a project properly"
|
223
|
-
it "should run the initialization block" do
|
224
|
-
code = <<-RUBY
|
225
|
-
initialization do
|
226
|
-
throw :got_here!
|
227
|
-
end
|
228
|
-
RUBY
|
229
|
-
the_following_code {
|
230
|
-
run_component_code code
|
231
|
-
}.should throw_symbol :got_here!
|
232
|
-
|
233
|
-
end
|
234
|
-
|
235
|
-
it "should alias the initialization method to initialisation" do
|
236
|
-
code = <<-RUBY
|
237
|
-
initialisation do
|
238
|
-
throw :BRITISH!
|
239
|
-
end
|
240
|
-
RUBY
|
241
|
-
the_following_code {
|
242
|
-
run_component_code code
|
243
|
-
}.should throw_symbol :BRITISH!
|
244
|
-
end
|
245
|
-
|
246
|
-
it "should properly expose any defined constants" do
|
247
|
-
container = run_component_code <<-RUBY
|
248
|
-
TEST_ONE = 1
|
249
|
-
TEST_TWO = 2
|
250
|
-
TEST_THREE = 3
|
251
|
-
RUBY
|
252
|
-
container.constants.sort.map{|s| s.to_sym}.should == [:TEST_ONE, :TEST_THREE, :TEST_TWO]
|
253
|
-
container.constants.map do |constant|
|
254
|
-
container.const_get(constant)
|
255
|
-
end.sort.should ==[1,2,3]
|
256
|
-
end
|
257
|
-
|
258
|
-
end
|
259
|
-
|
260
|
-
describe "ComponentTester" do
|
261
|
-
it "should allow the scope-resolution operator to access a component's constants" do
|
262
|
-
component_name = "my_awesomeness"
|
263
|
-
flexmock(File).should_receive(:read).once.with(/#{component_name}\.rb$/).and_return "AWESOME = :YES!"
|
264
|
-
tester = ComponentTester.new(component_name, "/path/shouldnt/matter")
|
265
|
-
tester::AWESOME.should be :YES!
|
266
|
-
end
|
267
|
-
|
268
|
-
it "should return an executable helper method properly" do
|
269
|
-
component_name = "one_two_three"
|
270
|
-
flexmock(File).should_receive(:read).once.with(/#{component_name}\.rb$/).and_return "def hair() :long end"
|
271
|
-
tester = ComponentTester.new(component_name, "/path/shouldnt/matter")
|
272
|
-
tester.helper_method(:hair).call.should be :long
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should load the configuration for the given helper properly" do
|
276
|
-
component_name = "i_like_configurations"
|
277
|
-
config = {:german => {1 => :eins, 2 => :zwei, 3 => :drei}}
|
278
|
-
flexmock(File).should_receive(:read).once.with(/#{component_name}\.rb$/).and_return ""
|
279
|
-
component_manager = flexmock "ComponentManager"
|
280
|
-
component_manager.should_receive(:configuration_for_component_named).once.with(component_name).and_return config
|
281
|
-
flexmock(Adhearsion::Components::ComponentManager).should_receive(:new).once.and_return component_manager
|
282
|
-
ComponentTester.new(component_name, "/path/shouldnt/matter").config[:german][1].should be :eins
|
283
|
-
end
|
284
|
-
|
285
|
-
it "should execute the initialize block when calling ComponentTester#initialize!()" do
|
286
|
-
component_name = "morrissey"
|
287
|
-
flexmock(File).should_receive(:read).once.with(/#{component_name}\.rb$/).and_return "initialization { $YES_I_WAS_CALLED = TRUE }"
|
288
|
-
ComponentTester.new(component_name, "/path/shouldnt/matter").initialize!
|
289
|
-
$YES_I_WAS_CALLED.should == true
|
290
|
-
end
|
291
|
-
|
292
|
-
end
|
data/spec/adhearsion/drb_spec.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module DRbTestHelper
|
4
|
-
|
5
|
-
def new_drb_rpc_object
|
6
|
-
Object.new.tap do |obj|
|
7
|
-
@component_manager.extend_object_with(obj, :rpc)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def add_rpc_methods(code)
|
12
|
-
@component_manager.load_code "methods_for(:rpc) do; #{code}; end"
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "Invoking an interface method via DRb" do
|
18
|
-
include DRbTestHelper
|
19
|
-
|
20
|
-
it "should raise an exception if the method is not found" do
|
21
|
-
the_following_code do
|
22
|
-
new_drb_rpc_object.this_method_doesnt_exist
|
23
|
-
end.should raise_error NoMethodError
|
24
|
-
end
|
25
|
-
|
26
|
-
before(:all) { require 'drb' }
|
27
|
-
|
28
|
-
before :each do
|
29
|
-
@component_manager = Adhearsion::Components::ComponentManager.new("/path/doesnt/matter")
|
30
|
-
@door = DRb.start_service "druby://127.0.0.1:#{37832 + rand(1500)}", new_drb_rpc_object
|
31
|
-
end
|
32
|
-
|
33
|
-
after :each do
|
34
|
-
@door.stop_service
|
35
|
-
@door.thread.kill
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should return normal Ruby data structures properly over DRb" do
|
39
|
-
add_rpc_methods <<-RUBY
|
40
|
-
def bar
|
41
|
-
[3,2,1]
|
42
|
-
end
|
43
|
-
RUBY
|
44
|
-
client = DRbObject.new nil, DRb.uri
|
45
|
-
client.bar.should == [3, 2, 1]
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should raise an exception for a non-existent interface" do
|
49
|
-
client = DRbObject.new nil, DRb.uri
|
50
|
-
the_following_code do
|
51
|
-
client.interface.bad_interface.should be [3, 2, 1]
|
52
|
-
end.should raise_error NoMethodError
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should raise an exception for a non-existent method" do
|
56
|
-
client = DRbObject.new nil, DRb.uri
|
57
|
-
the_following_code do
|
58
|
-
client.interface.interface.foobar.equal [3, 2, 1]
|
59
|
-
end.should raise_error NoMethodError
|
60
|
-
end
|
61
|
-
|
62
|
-
after do
|
63
|
-
DRb.stop_service
|
64
|
-
end
|
65
|
-
end
|
@@ -1,168 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module EventSocketTestHelper
|
4
|
-
def mock_handler_object
|
5
|
-
flexmock.tap do |handler|
|
6
|
-
flexstub(handler).should_receive(:connected)
|
7
|
-
flexstub(handler).should_receive(:receive_data)
|
8
|
-
flexstub(handler).should_receive(:disconnected)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "a new EventSocket" do
|
14
|
-
|
15
|
-
include EventSocketTestHelper
|
16
|
-
|
17
|
-
it "instantiating a new EventSocket should not instantiate a TCPSocket yet" do
|
18
|
-
flexmock(TCPSocket).should_receive(:new).never
|
19
|
-
EventSocket.new("localhost", 1234, mock_handler_object)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "instantiating a new EventSocket with both a block and a handler object" do
|
23
|
-
the_following_code {
|
24
|
-
EventSocket.new("localhost", 1234, mock_handler_object) {}
|
25
|
-
}.should raise_error ArgumentError
|
26
|
-
end
|
27
|
-
|
28
|
-
it "instantiating a new EventSocket with neither a block nor handler object" do
|
29
|
-
the_following_code {
|
30
|
-
EventSocket.new("localhost", 1234)
|
31
|
-
}.should raise_error ArgumentError
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should have an initial state of :new" do
|
35
|
-
EventSocket.new("localhost", 1234, mock_handler_object).state.should be :new
|
36
|
-
end
|
37
|
-
|
38
|
-
it "the handler created when instantiating the EventSocket with a block" do
|
39
|
-
event_socket = EventSocket.new("foo", 123) do |handler|
|
40
|
-
handler.receive_data { throw :inside_receive_data }
|
41
|
-
handler.disconnected { throw :inside_disconnected}
|
42
|
-
handler.connected { throw :inside_connected }
|
43
|
-
end
|
44
|
-
handler = event_socket.send(:instance_variable_get, :@handler)
|
45
|
-
the_following_code {
|
46
|
-
handler.send :receive_data, ''
|
47
|
-
}.should throw_symbol :inside_receive_data
|
48
|
-
|
49
|
-
%w[disconnected connected].each do |callback|
|
50
|
-
the_following_code {
|
51
|
-
handler.send callback
|
52
|
-
}.should throw_symbol "inside_#{callback}".to_sym
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'the handler created when instantiating the EventSocket with a block in which "def" is used to define callbacks' do
|
57
|
-
event_socket = EventSocket.new("foo", 123) do |handler|
|
58
|
-
def handler.receive_data
|
59
|
-
throw :inside_receive_data
|
60
|
-
end
|
61
|
-
def handler.disconnected
|
62
|
-
throw :inside_disconnected
|
63
|
-
end
|
64
|
-
def handler.connected
|
65
|
-
throw :inside_connected
|
66
|
-
end
|
67
|
-
end
|
68
|
-
handler = event_socket.send(:instance_variable_get, :@handler)
|
69
|
-
%w[receive_data disconnected connected].each do |callback|
|
70
|
-
the_following_code {
|
71
|
-
handler.send callback
|
72
|
-
}.should throw_symbol "inside_#{callback}".to_sym
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "connecting an EventSocket" do
|
79
|
-
|
80
|
-
include EventSocketTestHelper
|
81
|
-
|
82
|
-
before :each do
|
83
|
-
flexmock(Mutex).new_instances.should_receive(:synchronize).zero_or_more_times.and_yield
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should instantiate a new TCPSocket with the correct host and port" do
|
87
|
-
host, port = "google.com", 80
|
88
|
-
mock_socket = flexmock "TCPSocket"
|
89
|
-
flexmock(TCPSocket).should_receive(:new).once.with(host, port)
|
90
|
-
EventSocket.new(host, port, mock_handler_object).connect!
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should have a state of :connected if TCPSocket instantiates without error" do
|
94
|
-
host, port = "google.com", 80
|
95
|
-
mock_socket = flexmock "TCPSocket"
|
96
|
-
flexmock(TCPSocket).should_receive(:new).once.with(host, port)
|
97
|
-
event_socket = EventSocket.new(host, port, mock_handler_object)
|
98
|
-
event_socket.connect!
|
99
|
-
# Avoid race condition in JRuby where state may return nil
|
100
|
-
sleep(0.1)
|
101
|
-
event_socket.state.should be :connected
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should have a state of :failed after ECONNREFUSED is raised" do
|
105
|
-
host, port = "google.com", 80
|
106
|
-
flexmock(TCPSocket).should_receive(:new).once.with(host, port).and_raise(Errno::ECONNREFUSED)
|
107
|
-
event_socket = EventSocket.new(host, port, mock_handler_object)
|
108
|
-
|
109
|
-
the_following_code {
|
110
|
-
event_socket.connect!
|
111
|
-
}.should raise_error Errno::ECONNREFUSED
|
112
|
-
|
113
|
-
event_socket.state.should be :failed
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should instantiate a new Thread which calls EventSocket#reader_loop" do
|
117
|
-
flexmock(TCPSocket).should_receive(:new).once
|
118
|
-
flexmock(Thread).should_receive(:new).and_yield
|
119
|
-
the_following_code {
|
120
|
-
event_socket = EventSocket.new("foo", 123, mock_handler_object)
|
121
|
-
flexmock(event_socket).should_receive(:reader_loop).once.and_throw :in_thread_loop
|
122
|
-
event_socket.connect!
|
123
|
-
}.should throw_symbol :in_thread_loop
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "the reader_loop method" do
|
129
|
-
|
130
|
-
include EventSocketTestHelper
|
131
|
-
|
132
|
-
it "should call readpartial() on the TCPSocket and pass that to the receive_data method of handler" do
|
133
|
-
mock_handler = flexmock "mock handler object"
|
134
|
-
mock_socket = flexmock "TCPSocket"
|
135
|
-
data = "Jay Phillips " * 25
|
136
|
-
|
137
|
-
mock_handler.should_receive(:connected).and_return
|
138
|
-
mock_handler.should_receive(:disconnected).and_return
|
139
|
-
mock_handler.should_receive(:receive_data).once.with(data).and_throw :done_testing
|
140
|
-
|
141
|
-
mock_socket.should_receive(:readpartial).once.with(EventSocket::MAX_CHUNK_SIZE).and_return data
|
142
|
-
|
143
|
-
flexmock(TCPSocket).should_receive(:new).once.and_return mock_socket
|
144
|
-
flexmock(Thread).should_receive(:new).and_yield
|
145
|
-
|
146
|
-
the_following_code {
|
147
|
-
EventSocket.new("foo", 123, mock_handler).connect!
|
148
|
-
}.should throw_symbol :done_testing
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should set the state to :connection_dropped when an EOFError is raised by readpartial" do
|
152
|
-
mock_socket = flexmock "TCPSocket"
|
153
|
-
mock_socket.should_receive(:readpartial).once.and_raise EOFError
|
154
|
-
flexmock(TCPSocket).should_receive(:new).once.and_return mock_socket
|
155
|
-
|
156
|
-
flexmock(Thread).should_receive(:new).and_yield
|
157
|
-
|
158
|
-
event_socket = EventSocket.new("foo", 123, mock_handler_object)
|
159
|
-
|
160
|
-
event_socket.connect!
|
161
|
-
event_socket.state.should be :connection_dropped
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
describe "the writer_loop method" do
|
167
|
-
|
168
|
-
end
|