sevenscale-adhearsion 0.7.1003 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. data/CHANGELOG +8 -2
  2. data/EVENTS +11 -0
  3. data/Rakefile +92 -26
  4. data/adhearsion.gemspec +131 -23
  5. data/app_generators/ahn/ahn_generator.rb +21 -7
  6. data/app_generators/ahn/templates/.ahnrc +10 -4
  7. data/app_generators/ahn/templates/Rakefile +7 -2
  8. data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
  9. data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
  10. data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
  11. data/app_generators/ahn/templates/components/disabled/stomp_gateway/config.yml +12 -0
  12. data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
  13. data/app_generators/ahn/templates/components/simon_game/{lib/simon_game.rb → simon_game.rb} +14 -19
  14. data/app_generators/ahn/templates/config/startup.rb +3 -6
  15. data/app_generators/ahn/templates/dialplan.rb +2 -3
  16. data/app_generators/ahn/templates/events.rb +32 -6
  17. data/bin/jahn +10 -0
  18. data/examples/asterisk_manager_interface/standalone.rb +51 -0
  19. data/lib/adhearsion/cli.rb +140 -23
  20. data/lib/adhearsion/component_manager/component_tester.rb +55 -0
  21. data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
  22. data/lib/adhearsion/component_manager.rb +169 -238
  23. data/lib/adhearsion/events_support.rb +59 -237
  24. data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
  25. data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
  26. data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
  27. data/lib/adhearsion/foundation/event_socket.rb +203 -0
  28. data/lib/adhearsion/foundation/future_resource.rb +36 -0
  29. data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
  30. data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
  31. data/lib/adhearsion/foundation/numeric.rb +13 -0
  32. data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
  33. data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
  34. data/lib/adhearsion/foundation/string.rb +26 -0
  35. data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
  36. data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
  37. data/lib/adhearsion/host_definitions.rb +5 -1
  38. data/lib/adhearsion/initializer/asterisk.rb +33 -11
  39. data/lib/adhearsion/initializer/configuration.rb +58 -6
  40. data/lib/adhearsion/initializer/database.rb +3 -46
  41. data/lib/adhearsion/initializer/drb.rb +9 -3
  42. data/lib/adhearsion/initializer/freeswitch.rb +3 -3
  43. data/lib/adhearsion/initializer/rails.rb +1 -1
  44. data/lib/adhearsion/initializer.rb +213 -87
  45. data/lib/adhearsion/tasks/deprecations.rb +59 -0
  46. data/lib/adhearsion/tasks.rb +2 -1
  47. data/lib/adhearsion/version.rb +3 -3
  48. data/lib/adhearsion/voip/asterisk/agi_server.rb +6 -6
  49. data/lib/adhearsion/voip/asterisk/commands.rb +100 -2
  50. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
  51. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
  52. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
  53. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
  54. data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
  55. data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
  56. data/lib/adhearsion/voip/asterisk.rb +1 -8
  57. data/lib/adhearsion/voip/call.rb +5 -1
  58. data/lib/adhearsion/voip/dial_plan.rb +74 -61
  59. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
  60. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
  61. data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
  62. data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
  63. data/lib/adhearsion.rb +16 -11
  64. data/lib/theatre/README.markdown +64 -0
  65. data/lib/theatre/callback_definition_loader.rb +84 -0
  66. data/lib/theatre/guid.rb +23 -0
  67. data/lib/theatre/invocation.rb +121 -0
  68. data/lib/theatre/namespace_manager.rb +153 -0
  69. data/lib/theatre/version.rb +2 -0
  70. data/lib/theatre.rb +151 -0
  71. metadata +60 -147
  72. data/Manifest.txt +0 -151
  73. data/README.txt +0 -5
  74. data/ahn_generators/component/USAGE +0 -5
  75. data/ahn_generators/component/component_generator.rb +0 -57
  76. data/ahn_generators/component/templates/configuration.rb +0 -0
  77. data/ahn_generators/component/templates/lib/lib.rb.erb +0 -3
  78. data/ahn_generators/component/templates/test/test.rb.erb +0 -12
  79. data/ahn_generators/component/templates/test/test_helper.rb +0 -14
  80. data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
  81. data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +0 -14
  82. data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +0 -31
  83. data/lib/adhearsion/core_extensions/array.rb +0 -0
  84. data/lib/adhearsion/core_extensions/guid.rb +0 -5
  85. data/lib/adhearsion/core_extensions/hash.rb +0 -0
  86. data/lib/adhearsion/core_extensions/numeric.rb +0 -4
  87. data/lib/adhearsion/core_extensions/proc.rb +0 -0
  88. data/lib/adhearsion/core_extensions/pseudo_uuid.rb +0 -11
  89. data/lib/adhearsion/core_extensions/publishable.rb +0 -73
  90. data/lib/adhearsion/core_extensions/string.rb +0 -26
  91. data/lib/adhearsion/core_extensions/thread.rb +0 -13
  92. data/lib/adhearsion/core_extensions/time.rb +0 -0
  93. data/lib/adhearsion/distributed/gateways/dbus_gateway.rb +0 -0
  94. data/lib/adhearsion/distributed/gateways/osa_gateway.rb +0 -0
  95. data/lib/adhearsion/distributed/gateways/rest_gateway.rb +0 -9
  96. data/lib/adhearsion/distributed/gateways/soap_gateway.rb +0 -9
  97. data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +0 -9
  98. data/lib/adhearsion/distributed/peer_finder.rb +0 -0
  99. data/lib/adhearsion/distributed/remote_cli.rb +0 -0
  100. data/lib/adhearsion/hooks.rb +0 -57
  101. data/lib/adhearsion/initializer/paths.rb +0 -55
  102. data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
  103. data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
  104. data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
  105. data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
  106. data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
  107. data/spec/fixtures/dialplan.rb +0 -3
  108. data/spec/initializer/test_configuration.rb +0 -267
  109. data/spec/initializer/test_loading.rb +0 -162
  110. data/spec/initializer/test_paths.rb +0 -43
  111. data/spec/sample.rb +0 -9
  112. data/spec/silence.rb +0 -10
  113. data/spec/test_ahn_command.rb +0 -149
  114. data/spec/test_code_quality.rb +0 -87
  115. data/spec/test_component_manager.rb +0 -97
  116. data/spec/test_constants.rb +0 -8
  117. data/spec/test_drb.rb +0 -104
  118. data/spec/test_events.rb +0 -136
  119. data/spec/test_helper.rb +0 -106
  120. data/spec/test_hooks.rb +0 -15
  121. data/spec/test_host_definitions.rb +0 -79
  122. data/spec/test_initialization.rb +0 -124
  123. data/spec/test_logging.rb +0 -80
  124. data/spec/test_relationship_properties.rb +0 -54
  125. data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
  126. data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
  127. data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
  128. data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
  129. data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
  130. data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
  131. data/spec/voip/asterisk/mock_ami_server.rb +0 -176
  132. data/spec/voip/asterisk/test_agi_server.rb +0 -453
  133. data/spec/voip/asterisk/test_ami.rb +0 -227
  134. data/spec/voip/asterisk/test_commands.rb +0 -2006
  135. data/spec/voip/asterisk/test_config_manager.rb +0 -129
  136. data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
  137. data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
  138. data/spec/voip/dsl/test_dispatcher.rb +0 -82
  139. data/spec/voip/dsl/test_parser.rb +0 -87
  140. data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
  141. data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
  142. data/spec/voip/freeswitch/test_oes_server.rb +0 -9
  143. data/spec/voip/test_call_routing.rb +0 -127
  144. data/spec/voip/test_dialplan_manager.rb +0 -442
  145. data/spec/voip/test_numerical_string.rb +0 -48
  146. data/spec/voip/test_phone_number.rb +0 -36
  147. data/test/test_ahn_generator.rb +0 -59
  148. data/test/test_component_generator.rb +0 -52
  149. data/test/test_generator_helper.rb +0 -20
@@ -1,87 +0,0 @@
1
- # #!/usr/bin/env spec
2
- #
3
- # # TODO: Forget regexps. Use Rubinius.
4
- # # This spec is somewhat unique. It essentially reads the code
5
- # # and ensures the best practices are followed.
6
- #
7
- # # TODO: Create a be_a_proper_method_definition assertion
8
- # # TODO: Create a syntax checking spec
9
- # # TODO: Report code that has spaces between the dot when defining the method on an object
10
- #
11
- # module CodeQualityHelper
12
- # # TODO: Allow strings with a Hash in them before it
13
- #
14
- # BadMethodRegexp = /def\s+([$@]?[a-zA-Z_][\w_]*\s*\.\s*)?[a-zA-Z_][\w_]*[=!?]?[^(^\Z]/
15
- # @root = File.dirname(__FILE__) + "/.."
16
- #
17
- # def ruby_files
18
- # @ruby_files ||= Dir[@root + "/**/*.rb"].map { |f| File.expand_path f }
19
- # end
20
- #
21
- # end
22
- #
23
- # describe "My 'bad method definition' finding regular expression" do
24
- #
25
- # # ATTENTION: If this spec ever blows up for a method definition it shouldn't,
26
- # # please add the definition that caused it to explode here as an assertion.
27
- # # It would also be nice to fix the regular expression too :)
28
- #
29
- # include CodeQualityHelper
30
- #
31
- # it "should NOT match method definitions with no arguments" do
32
- # "def foo".should !~ CodeQualityHelper::BadMethodRegexp
33
- # " def monkey ".should !~ CodeQualityHelper::BadMethodRegexp
34
- # ' unless "#{bar}".empty? then def @zebra.spock '.should !~ CodeQualityHelper::BadMethodRegexp
35
- # end
36
- #
37
- # it "should NOT match method definitions with arguments and parenthesis" do
38
- # "def foo(bar)".should !~ CodeQualityHelper::BadMethodRegexp
39
- # "\tdef $MONKEY . foo( bar, qaz = blam!) ".should !~ CodeQualityHelper::BadMethodRegexp
40
- # "if(this) then def $MONKEY . foo( qaz = blam!, *args, &b) ".should !~ CodeQualityHelper::BadMethodRegexp
41
- # " @something.each do |x| def something".should !~ CodeQualityHelper::BadMethodRegexp
42
- # end
43
- #
44
- # it "should match method definitions with a space between the name and parenthesis" do
45
- # "def foo (bar)".should =~ CodeQualityHelper::BadMethodRegexp
46
- # "def \t m \t (*args)".should =~ CodeQualityHelper::BadMethodRegexp
47
- # end
48
- #
49
- # it "should match method definitions with no parenthesis around its arguments" do
50
- # "def foo bar".should =~ CodeQualityHelper::BadMethodRegexp
51
- # "\tif $x then def foo bar # Commentacular".should =~ CodeQualityHelper::BadMethodRegexp
52
- # end
53
- # end
54
- #
55
- # describe "All method definitions" do
56
- #
57
- # include CodeQualityHelper
58
- #
59
- # before:all do
60
- # @root = File.dirname(__FILE__) + "/.."
61
- # end
62
- #
63
- # it "should have parenthesis around their arguments" do
64
- # ruby_files.each do |file|
65
- # puts file
66
- # File.read(file).grep(CodeQualityHelper::BadMethodRegexp).should be_empty
67
- # end
68
- # end
69
- # end
70
- #
71
- # # describe "The syntax of all Ruby source files" do
72
- # #
73
- # # include CodeQualityHelper
74
- # #
75
- # # before:all do
76
- # # @root = File.dirname(__FILE__) + "/.."
77
- # # end
78
- # #
79
- # # it "should be valid" do
80
- # # incorrect = ruby_files.map { |f| File.expand_path f }.select do |file|
81
- # # `ruby -c #{file}`
82
- # # not $?.success?
83
- # # end
84
- # #
85
- # # incorrect.should be_empty
86
- # # end
87
- # # end
@@ -1,97 +0,0 @@
1
- require File.dirname(__FILE__) + "/test_helper"
2
-
3
- context "Adding call context to components" do
4
- include CallContextComponentTestHelpers
5
-
6
- attr_reader :sample_component
7
-
8
- setup do
9
- @sample_component = new_componenet_class_named(sample_component_name)
10
- end
11
-
12
- test "Component name is added to list of components that will have call contexts injected into them" do
13
- components_with_call_context.should.be.empty
14
- the_following_code {
15
- sample_component.add_call_context
16
- }.should.not.raise
17
-
18
- components_with_call_context.should.not.be.empty
19
- Adhearsion::ComponentManager.components_with_call_context[sample_component_name].component_class.should.equal sample_component
20
- end
21
-
22
- private
23
- def components_with_call_context
24
- Adhearsion::ComponentManager.components_with_call_context.keys
25
- end
26
-
27
- def sample_component_name
28
- 'SampleComponent'
29
- end
30
- end
31
-
32
- context "Referencing a component class in a dial plan context" do
33
- include CallContextComponentTestHelpers
34
-
35
- test "the class constant should be available in the scope of a call context" do
36
- sample_component_class = new_componenet_class_named('SampleComponent2')
37
- sample_component_class.add_call_context
38
-
39
- loader = load_dial_plan(<<-DIAL_PLAN)
40
- some_context {
41
- SampleComponent2
42
- }
43
- DIAL_PLAN
44
-
45
- flexmock(Adhearsion::DialPlan::Loader).should_receive(:load_dial_plan).and_return(loader)
46
- tested_call = Adhearsion::Call.new(nil, :context => :some_context)
47
- mock_config = flexmock 'a Configuration which communicates automatically_answer_incoming_calls properly',
48
- :automatically_answer_incoming_calls => false
49
- flexmock(Adhearsion::Configuration).should_receive(:new).once.and_return mock_config
50
- Adhearsion::Configuration.configure
51
-
52
- the_following_code {
53
- handle(tested_call)
54
- }.should.not.raise
55
- end
56
-
57
- test "the call context is injected into any instances of the component class" do
58
- sample_component_class = new_componenet_class_named('SampleComponent3')
59
- sample_component_class.add_call_context :as => :call_context_variable_name
60
-
61
- loader = load_dial_plan(<<-DIAL_PLAN)
62
- some_context {
63
- new_sample_component3.call_context_variable_name
64
- }
65
- DIAL_PLAN
66
-
67
- flexmock(Adhearsion::DialPlan::Loader).should_receive(:load_dial_plan).and_return(loader)
68
- sample_call = Adhearsion::Call.new(nil, :context => :some_context)
69
- mock_config = flexmock 'a Configuration which communicates automatically_answer_incoming_calls properly',
70
- :automatically_answer_incoming_calls => false
71
- flexmock(Adhearsion::Configuration).should_receive(:new).once.and_return mock_config
72
- Adhearsion::Configuration.configure
73
-
74
- the_following_code {
75
- handle(sample_call)
76
- }.should.not.raise
77
- end
78
-
79
- private
80
- def load_dial_plan(dial_plan_as_string)
81
- Adhearsion::DialPlan::Loader.load(dial_plan_as_string)
82
- end
83
-
84
- def handle(call)
85
- Adhearsion::DialPlan::Manager.handle(call)
86
- end
87
- end
88
-
89
- BEGIN {
90
- module CallContextComponentTestHelpers
91
- def new_componenet_class_named(component_name)
92
- component_namespace = Adhearsion::Components::ComponentModule.new('passed in component does not matter here')
93
- Adhearsion::Components::Component.prepare_component_class(component_namespace, component_name)
94
- component_namespace.const_get(component_name)
95
- end
96
- end
97
- }
@@ -1,8 +0,0 @@
1
- require File.dirname(__FILE__) + "/test_helper"
2
-
3
- context "The Adhearsion module" do
4
- # This test is of questionable benefit
5
- test "should have a VERSION constant" do
6
- assert(Adhearsion.const_defined?(:VERSION), "VERSION constant should be defined")
7
- end
8
- end
data/spec/test_drb.rb DELETED
@@ -1,104 +0,0 @@
1
- require File.dirname(__FILE__) + "/test_helper"
2
-
3
- # The way I envisoned publishing this DRb:
4
- #
5
- # publish :globally do/end
6
- # publish :with => :drb do/end
7
-
8
- context "Publishing an interface" do
9
- test "should be allowed with a class method" do
10
- Class.new.class_eval do
11
- include Adhearsion::Publishable
12
- publish :through => :interface do
13
- def self.bar
14
- [1, 2, 3]
15
- end
16
- end
17
- end
18
- Adhearsion::DrbDoor.instance.interface.bar.should.equal [1, 2, 3]
19
- end
20
-
21
- test "should be allowed with an alternate interface" do
22
- Class.new.class_eval do
23
- include Adhearsion::Publishable
24
- publish :through => :api do
25
- def self.bar
26
- [2, 3, 4]
27
- end
28
- end
29
- end
30
- Adhearsion::DrbDoor.instance.api.bar.should.equal [2, 3, 4]
31
- end
32
-
33
- test "should be allowed with a metaclass block" do
34
- Class.new.class_eval do
35
- include Adhearsion::Publishable
36
- publish :through => :interface do
37
- class << self
38
- def bar
39
- [3, 2, 1]
40
- end
41
- end
42
- end
43
- end
44
- Adhearsion::DrbDoor.instance.interface.bar.should.equal [3, 2, 1]
45
- end
46
-
47
- test "should be allowed from within the metaclass block" do
48
- # Class.new.class_eval do
49
- # include Publishable
50
- # class << self
51
- # publish :through => :interface do
52
- # def baz
53
- # [4, 5, 6]
54
- # end
55
- # end
56
- # end
57
- # end
58
- # Adhearsion::DrbDoor.instance.interface.baz.should.equal [4, 5, 6]
59
- end
60
- end
61
-
62
- context "Invoking an interface" do
63
- test "should raise an exception if the method is not found" do
64
- the_following_code do
65
- Adhearsion::DrbDoor.instance.interface.foobar.should.equal [1, 2, 3]
66
- end.should.raise NoMethodError
67
- end
68
-
69
- test "should raise an exception if the interface is not found" do
70
- the_following_code do
71
- Adhearsion::DrbDoor.instance.bad_interface.bar.should.equal [1, 2, 3]
72
- end.should.raise NoMethodError
73
- end
74
- end
75
-
76
- context "Invoking an interface method via DRb" do
77
- require 'drb'
78
- before do
79
- @door = DRb.start_service "druby://127.0.0.1:9050", Adhearsion::DrbDoor.instance
80
- end
81
-
82
- test "should return the proper result" do
83
- client = DRbObject.new nil, DRb.uri
84
- client.interface.bar.should.equal [3, 2, 1]
85
- end
86
-
87
- test "should raise an exception for a non-existent interface" do
88
- client = DRbObject.new nil, DRb.uri
89
- the_following_code do
90
- client.interface.bad_interface.should.equal [3, 2, 1]
91
- end.should.raise NoMethodError
92
- end
93
-
94
- test "should raise an exception for a non-existent method" do
95
- client = DRbObject.new nil, DRb.uri
96
- the_following_code do
97
- client.interface.interface.foobar.equal [3, 2, 1]
98
- end.should.raise NoMethodError
99
- end
100
-
101
- after do
102
- DRb.stop_service
103
- end
104
- end
data/spec/test_events.rb DELETED
@@ -1,136 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
2
-
3
- context 'Definitions within an events.rb file' do
4
-
5
- include EventsSubsystemTestHelper
6
-
7
- before :each do
8
- Adhearsion::Events.reinitialize_framework_events_container!
9
- end
10
-
11
- test 'calling each() on a registrar defines a RegisteredEventCallback' do
12
-
13
- mock_file_access_with_text %{ events.framework.before_call.each { |event| event } }
14
-
15
- framework_events_container.register_namespace_path(:framework).register_callback_name(:before_call)
16
- callbacks = framework_events_container.callbacks_at_path :framework, :before_call
17
- load_events_file_from_mocked_filesystem
18
-
19
- callbacks.size.should.equal 1
20
- callbacks.first.should.be.kind_of Adhearsion::Events::RegisteredEventCallback
21
- end
22
-
23
- test 'the each() method does not exist on the object returned by events()' do
24
- the_following_code {
25
- load_code_from_mocked_filesystem %{ events.each {} }
26
- }.should.raise NoMethodError
27
- end
28
-
29
- test 'addressing a non-existent path raises an Exception' do
30
- [%{ events.monkeys! }, %{events.framework.icanhascheezburger}, %{events.framework}].each do |bad_code|
31
- the_following_code {
32
- load_code_from_mocked_filesystem bad_code
33
- }.should.raise Adhearsion::Events::UndefinedEventNamespace
34
- end
35
- end
36
-
37
- end
38
-
39
-
40
- # Hierarchy tests?
41
-
42
- context 'Executing synchronous events defined within an events.rb file' do
43
-
44
- before :each do
45
- Adhearsion::Events.reinitialize_framework_events_container!
46
- end
47
-
48
- test 'an exception in a callback should be passed to ahn_log.events.error' do
49
- flexmock(ahn_log.events).should_receive(:error).once.with(/lolrus/)
50
- Adhearsion::Events.register_namespace_path(:ceiling_cat).register_callback_name(:watches_you)
51
- Adhearsion::Events.framework_events_container.events.ceiling_cat.watches_you.each { |prophecy| raise prophecy }
52
- the_following_code {
53
- Adhearsion::Events.framework_events_container.events.ceiling_cat.watches_you << "I has a lolrus!"
54
- }.should.not.raise RuntimeError
55
- end
56
-
57
- test 'events should execute the callbacks in the order in which they were defined' do
58
- order_keeper = []
59
- Adhearsion::Events.register_namespace_path(:foo, :bar).register_callback_name(:before_explosion)
60
- Adhearsion::Events.framework_events_container.events.foo.bar.before_explosion.each { |event| order_keeper << 1 }
61
- Adhearsion::Events.framework_events_container.events.foo.bar.before_explosion.each { |event| order_keeper << 2 }
62
-
63
- [:one, :two, :three].each do |number|
64
- Adhearsion::Events.framework_events_container.events.foo.bar.before_explosion << number
65
- end
66
- order_keeper.should == [1,2] * 3
67
- end
68
- end
69
-
70
- context 'Executing asynchronous events defined within an events.rb file' do
71
-
72
- end
73
-
74
- context "Defining new namespaces and events within an EventsDefinitionContainer's object graph" do
75
-
76
- attr_reader :container
77
- before :each do
78
- @container = Adhearsion::Events::EventsDefinitionContainer.new
79
- end
80
-
81
- test 'initializes a RootNamespace' do
82
- container.root.should.be.kind_of Adhearsion::Events::RootEventNamespace
83
- end
84
-
85
- test 'allows the registration of new namespaces' do
86
- container.register_namespace_path(:framework).register_callback_name(:after_call)
87
- container.callbacks_at_path(:framework, :after_call).empty?.should == true
88
- end
89
-
90
- test 'the callback is executed with the proper message' do
91
- container.register_namespace_path(:reporters).register_callback_name(:report)
92
- message_from_block = :has_not_executed_yet
93
- container.events.reporters.report(:foobar).each { |event| message_from_block = event }
94
- container.events.reporters.report << :got_here
95
- message_from_block.should.equal :got_here
96
- end
97
-
98
- end
99
-
100
- context 'NamespaceDefinitionCapturer' do
101
-
102
- attr_reader :namespace
103
- before :each do
104
- @namespace = flexmock 'a mock AbstractNamespace'
105
- end
106
-
107
- test 'captures any method and returns a NamespaceDefinitionCapturer' do
108
- nested_namespace = Adhearsion::Events::RegisteredEventNamespace.new(namespace)
109
- namespace.should_receive(:[]).once.with(:foobarz).and_return nested_namespace
110
- Adhearsion::Events::NamespaceDefinitionCapturer.new(namespace).foobarz.should.
111
- be.kind_of(Adhearsion::Events::NamespaceDefinitionCapturer)
112
- end
113
-
114
- end
115
-
116
- BEGIN {
117
- module EventsSubsystemTestHelper
118
- def mock_file_access_with_text(text)
119
- flexmock(File).should_receive(:read).once.and_return text
120
- end
121
-
122
- def framework_events_container
123
- Adhearsion::Events.framework_events_container
124
- end
125
-
126
- def load_code_from_mocked_filesystem(code)
127
- mock_file_access_with_text code
128
- load_events_file_from_mocked_filesystem
129
- end
130
-
131
- def load_events_file_from_mocked_filesystem
132
- Adhearsion::Events.load_definitions_from_file "events.rb"
133
- end
134
-
135
- end
136
- }
data/spec/test_helper.rb DELETED
@@ -1,106 +0,0 @@
1
- Dir.chdir File.join(File.dirname(__FILE__), '..')
2
-
3
- require 'rubygems'
4
-
5
- def require_or_report_dependency(require_name, gem_name)
6
- begin
7
- require require_name
8
- rescue LoadError
9
- report_dependency!(gem_name)
10
- end
11
- end
12
-
13
- def report_dependency!(name)
14
- 2.times { puts }
15
- puts "You need #{name} to run these tests: gem install #{name}"
16
- 2.times { puts }
17
- exit!
18
- end
19
-
20
- require_or_report_dependency('test/spec', 'test-spec')
21
- require_or_report_dependency('flexmock/test_unit', 'flexmock')
22
- require_or_report_dependency('active_support', 'activesupport')
23
- # require_or_report_dependency('ruby-debug', 'ruby-debug')
24
- require_or_report_dependency('rubigen', 'rubigen')
25
-
26
- require 'pp'
27
- require 'stringio'
28
-
29
- $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
30
- $: << File.expand_path('lib')
31
- $: << File.dirname(__FILE__)
32
-
33
- require 'adhearsion'
34
-
35
- class Test::Unit::TestCase
36
-
37
- alias_method :the_following_code, :lambda
38
- def self.test(*args, &block)
39
- if block_given?
40
- specify(args, &block)
41
- else
42
- disabled_test(*args)
43
- end
44
- end
45
-
46
- def self.disabled_test(*args, &block)
47
- xspecify(*args, &block)
48
- end
49
-
50
- end
51
-
52
- module InitializerStubs
53
-
54
- DEFAULT_AHNRC_DATA_STRUCTURE = YAML.load_file(
55
- File.dirname(__FILE__) + "/../app_generators/ahn/templates/.ahnrc"
56
- ) unless defined? DEFAULT_AHNRC_DATA_STRUCTURE
57
-
58
- UNWANTED_BEHAVIOR = {
59
- Adhearsion::Initializer => [:initialize_log_file, :switch_to_root_directory, :daemonize!],
60
- Adhearsion::Initializer.metaclass => { :get_rules_from => DEFAULT_AHNRC_DATA_STRUCTURE },
61
- Adhearsion::Hooks::AfterInitialized.metaclass => [:create_hook, :trigger_hooks]
62
- } unless defined? UNWANTED_BEHAVIOR
63
-
64
- def stub_behavior_for_initializer_with_no_path_changing_behavior
65
- stub_unwanted_behavior
66
- yield if block_given?
67
- ensure
68
- unstub_directory_changing_behavior
69
- end
70
-
71
- def with_new_initializer_with_no_path_changing_behavior(&block)
72
- stub_behavior_for_initializer_with_no_path_changing_behavior do
73
- block.call Adhearsion::Initializer.start('path does not matter')
74
- end
75
- end
76
-
77
- def stub_unwanted_behavior
78
- UNWANTED_BEHAVIOR.each do |stub_victim_class, undesired_methods|
79
- undesired_methods.each do |undesired_method_name_or_key_value_pair|
80
- undesired_method_name, method_implementation = case undesired_method_name_or_key_value_pair
81
- when Array
82
- [undesired_method_name_or_key_value_pair.first, lambda { undesired_method_name_or_key_value_pair.last } ]
83
- else
84
- [undesired_method_name_or_key_value_pair, lambda{ |*args| }]
85
- end
86
- stub_victim_class.send(:alias_method, "pre_stubbed_#{undesired_method_name}", undesired_method_name)
87
- stub_victim_class.send(:define_method, undesired_method_name, &method_implementation)
88
- end
89
- end
90
- end
91
-
92
- def unstub_directory_changing_behavior
93
- UNWANTED_BEHAVIOR.each do |stub_victim_class, undesired_methods|
94
- undesired_methods.each do |undesired_method_name|
95
- undesired_method_name = undesired_method_name.first if undesired_method_name.kind_of? Array
96
- stub_victim_class.send(:alias_method, undesired_method_name, "pre_stubbed_#{undesired_method_name}")
97
- end
98
- end
99
- end
100
- end
101
-
102
- Adhearsion::Initializer.ahn_root = File.dirname(__FILE__) + '/fixtures'
103
- require 'spec/silence' unless ENV['SHOW_DISABLED']
104
-
105
- require 'adhearsion/voip/asterisk'
106
- require 'adhearsion/component_manager'
data/spec/test_hooks.rb DELETED
@@ -1,15 +0,0 @@
1
- require File.dirname(__FILE__) + "/test_helper.rb"
2
-
3
- context "A HookWithArguments" do
4
- test "should pass the arguments to trigger_hooks() along to each registered block" do
5
- hook_manager = Adhearsion::Hooks::HookWithArguments.new
6
- hook_manager.create_hook do |foo, bar|
7
- foo.should.equal :foo
8
- bar.should.equal :bar
9
- throw :inside_hook
10
- end
11
- the_following_code {
12
- hook_manager.trigger_hooks(:foo, :bar)
13
- }.should.throw :inside_hook
14
- end
15
- end
@@ -1,79 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
- require 'adhearsion/host_definitions'
3
-
4
- context 'HostDefinition' do
5
-
6
- after :each do
7
- Adhearsion::HostDefinition.clear_definitions!
8
- end
9
-
10
- test 'when loading from a YAML array, it should pass each nested Hash to the constructor' do
11
- hosts = [
12
- {:host => "hostname1", :username => "user", :password => "password"},
13
- {:host => "hostname2", :username => "user", :password => "password"},
14
- {:host => "hostname3", :username => "user", :password => "password"}
15
- ]
16
- flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(hosts[0])
17
- flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(hosts[1])
18
- flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(hosts[2])
19
- Adhearsion::HostDefinition.import_from_yaml hosts.to_yaml
20
- end
21
-
22
- test 'should set the @name property to a new UUID when no name is given' do
23
- definition = {:host => "hostname", :username => "user", :password => "pass"}
24
- Adhearsion::HostDefinition.new(definition).name.should =~ /^[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}$/i
25
- end
26
-
27
- test 'when loading from YAML keys, it should pass each nested Hash to the constructor with the key as :name' do
28
- definitions = { :pbx1 => {},
29
- :pbx2 => {},
30
- :pbx3 => {} }
31
- definitions.each_pair do |key,value|
32
- flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(value.merge(:name => key))
33
- end
34
- Adhearsion::HostDefinition.import_from_data_structure(definitions)
35
- end
36
-
37
- test 'should have an Array class variable named definitions' do
38
- Adhearsion::HostDefinition.definitions.should.be.kind_of Array
39
- end
40
-
41
- test 'should add each HostDefinition to a class variable named @@definitions when instantiated' do
42
- Adhearsion::HostDefinition.definitions.size.should.equal 0
43
- Adhearsion::HostDefinition.new :name => "foobar", :host => "hostname", :username => "user", :password => "password"
44
- Adhearsion::HostDefinition.definitions.size.should.equal 1
45
- Adhearsion::HostDefinition.clear_definitions!
46
- Adhearsion::HostDefinition.definitions.size.should.equal 0
47
- end
48
-
49
- test 'should raise a HostDefinitionException when a password and a key are given' do
50
- the_following_code {
51
- Adhearsion::HostDefinition.new(:username => "user", :host => "foobar", :key => "doesntmatter", :password => "pass")
52
- }.should.raise Adhearsion::HostDefinition::HostDefinitionException
53
- end
54
-
55
- test 'should raise a HostDefinitionException when no password or key is given' do
56
- the_following_code {
57
- Adhearsion::HostDefinition.new(:username => "user", :host => "foobar")
58
- }.should.raise Adhearsion::HostDefinition::HostDefinitionException
59
- end
60
-
61
- test 'should raise a HostDefinitionException when no username is given' do
62
- the_following_code {
63
- Adhearsion::HostDefinition.new(:host => "host", :password => "password")
64
- }.should.raise Adhearsion::HostDefinition::HostDefinitionException
65
- end
66
-
67
- test 'should raise a HostDefinitionException when no "host" key is given' do
68
- the_following_code {
69
- Adhearsion::HostDefinition.new(:username => "foobar", :password => "password")
70
- }.should.raise Adhearsion::HostDefinition::HostDefinitionException
71
- end
72
-
73
- test 'should raise a HostDefinitionException when an unrecognized key is given' do
74
- the_following_code {
75
- Adhearsion::HostDefinition.new(:username => "foobar", :password => "password", :host => "blah", :thiskeyisnotrecognized => nil)
76
- }.should.raise Adhearsion::HostDefinition::HostDefinitionException
77
- end
78
-
79
- end