adhearsion 1.0.1 → 1.0.2
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 +10 -0
- data/CHANGELOG +8 -0
- data/README.markdown +33 -0
- data/Rakefile +28 -68
- data/adhearsion.gemspec +19 -133
- data/app_generators/ahn/templates/Gemfile +0 -4
- data/app_generators/ahn/templates/components/disabled/restful_rpc/spec/restful_rpc_spec.rb +4 -16
- data/lib/adhearsion/cli.rb +17 -0
- data/lib/adhearsion/component_manager/component_tester.rb +1 -3
- data/lib/adhearsion/component_manager/spec_framework.rb +4 -10
- data/lib/adhearsion/foundation/object.rb +10 -0
- data/lib/adhearsion/version.rb +1 -1
- data/spec/ahn_command_spec.rb +284 -0
- data/spec/component_manager_spec.rb +292 -0
- data/spec/constants_spec.rb +8 -0
- data/spec/drb_spec.rb +65 -0
- data/spec/fixtures/dialplan.rb +3 -0
- data/spec/foundation/event_socket_spec.rb +168 -0
- data/spec/host_definitions_spec.rb +79 -0
- data/spec/initialization_spec.rb +163 -0
- data/spec/initializer/configuration_spec.rb +270 -0
- data/spec/initializer/loading_spec.rb +149 -0
- data/spec/initializer/paths_spec.rb +74 -0
- data/spec/logging_spec.rb +86 -0
- data/spec/relationship_properties_spec.rb +54 -0
- data/spec/silence.rb +10 -0
- data/spec/spec_helper.rb +101 -0
- data/spec/voip/asterisk/agi_server_spec.rb +473 -0
- data/spec/voip/asterisk/ami/ami_spec.rb +549 -0
- data/spec/voip/asterisk/ami/lexer/ami_fixtures.yml +30 -0
- data/spec/voip/asterisk/ami/lexer/lexer_story +291 -0
- data/spec/voip/asterisk/ami/lexer/lexer_story.rb +241 -0
- data/spec/voip/asterisk/ami/lexer/story_helper.rb +124 -0
- data/spec/voip/asterisk/ami/old_tests.rb +204 -0
- data/spec/voip/asterisk/ami/super_manager/super_manager_story +25 -0
- data/spec/voip/asterisk/ami/super_manager/super_manager_story.rb +15 -0
- data/spec/voip/asterisk/ami/super_manager/super_manager_story_helper.rb +5 -0
- data/spec/voip/asterisk/commands_spec.rb +2179 -0
- data/spec/voip/asterisk/config_file_generators/agents_spec.rb +251 -0
- data/spec/voip/asterisk/config_file_generators/queues_spec.rb +323 -0
- data/spec/voip/asterisk/config_file_generators/voicemail_spec.rb +306 -0
- data/spec/voip/asterisk/config_manager_spec.rb +127 -0
- data/spec/voip/asterisk/menu_command/calculated_match_spec.rb +109 -0
- data/spec/voip/asterisk/menu_command/matchers_spec.rb +97 -0
- data/spec/voip/call_routing_spec.rb +125 -0
- data/spec/voip/dialplan_manager_spec.rb +468 -0
- data/spec/voip/dsl/dialing_dsl_spec.rb +270 -0
- data/spec/voip/dsl/dispatcher_spec.rb +82 -0
- data/spec/voip/dsl/dispatcher_spec_helper.rb +45 -0
- data/spec/voip/dsl/parser_spec.rb +69 -0
- data/spec/voip/freeswitch/basic_connection_manager_spec.rb +39 -0
- data/spec/voip/freeswitch/inbound_connection_manager_spec.rb +39 -0
- data/spec/voip/freeswitch/oes_server_spec.rb +9 -0
- data/spec/voip/numerical_string_spec.rb +61 -0
- data/spec/voip/phone_number_spec.rb +45 -0
- data/theatre-spec/dsl_examples/dynamic_stomp.rb +7 -0
- data/theatre-spec/dsl_examples/simple_before_call.rb +7 -0
- data/theatre-spec/dsl_spec.rb +43 -0
- data/theatre-spec/invocation_spec.rb +167 -0
- data/theatre-spec/namespace_spec.rb +125 -0
- data/theatre-spec/spec_helper.rb +37 -0
- data/theatre-spec/spec_helper_spec.rb +28 -0
- data/theatre-spec/theatre_class_spec.rb +150 -0
- metadata +171 -34
@@ -0,0 +1,270 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ConfigurationTestHelper
|
4
|
+
def default_config(&block)
|
5
|
+
Adhearsion::Configuration.new do |config|
|
6
|
+
config.enable_asterisk
|
7
|
+
yield config if block_given?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Configuration defaults" do
|
13
|
+
include ConfigurationTestHelper
|
14
|
+
attr_reader :config
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
@config = default_config
|
18
|
+
end
|
19
|
+
|
20
|
+
it "incoming calls are answered by default" do
|
21
|
+
config.automatically_answer_incoming_calls.should be true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "calls are ended when hung up" do
|
25
|
+
config.end_call_on_hangup.should be true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "if an error occurs, a call is hungup" do
|
29
|
+
config.end_call_on_error.should be true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "asterisk is enabled by default" do
|
33
|
+
config.asterisk_enabled?.should be true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "default asterisk configuration is available" do
|
37
|
+
config.asterisk.kind_of?(Adhearsion::Configuration::AsteriskConfiguration).should be true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "database access is NOT enabled by default" do
|
41
|
+
config.database_enabled?.should be false
|
42
|
+
end
|
43
|
+
|
44
|
+
it "ldap access is NOT enabled by default" do
|
45
|
+
config.ldap_enabled?.should be false
|
46
|
+
end
|
47
|
+
|
48
|
+
it "freeswith is NOT enabled by default" do
|
49
|
+
config.freeswitch_enabled?.should be false
|
50
|
+
end
|
51
|
+
|
52
|
+
it "AMI is NOT enabled by default" do
|
53
|
+
config.asterisk.ami_enabled?.should be false
|
54
|
+
end
|
55
|
+
|
56
|
+
it "Drb is NOT enabled by default" do
|
57
|
+
config.drb_enabled?.should be false
|
58
|
+
end
|
59
|
+
|
60
|
+
it "XMPP is NOT enabled by default" do
|
61
|
+
config.xmpp_enabled?.should be false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "Asterisk AGI configuration defaults" do
|
66
|
+
attr_reader :config
|
67
|
+
|
68
|
+
before(:each) do
|
69
|
+
@config = Adhearsion::Configuration::AsteriskConfiguration.new
|
70
|
+
end
|
71
|
+
|
72
|
+
it "asterisk configuration sets default listening port" do
|
73
|
+
config.listening_port.should be Adhearsion::Configuration::AsteriskConfiguration.default_listening_port
|
74
|
+
end
|
75
|
+
|
76
|
+
it "asterisk configuration sets default listening host" do
|
77
|
+
config.listening_host.should == Adhearsion::Configuration::AsteriskConfiguration.default_listening_host
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'Logging configuration' do
|
82
|
+
|
83
|
+
attr_reader :config
|
84
|
+
before :each do
|
85
|
+
@config = Adhearsion::Configuration.new
|
86
|
+
end
|
87
|
+
|
88
|
+
after :each do
|
89
|
+
Adhearsion::Logging.logging_level = :fatal
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'the logging level should translate from symbols into Log4r constants' do
|
93
|
+
Adhearsion::Logging.logging_level.should_not be Log4r::WARN
|
94
|
+
config.logging :level => :warn
|
95
|
+
Adhearsion::Logging.logging_level.should be Log4r::WARN
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "AMI configuration defaults" do
|
101
|
+
attr_reader :config
|
102
|
+
|
103
|
+
before(:each) do
|
104
|
+
@config = Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration.new
|
105
|
+
end
|
106
|
+
|
107
|
+
it "ami configuration sets default port" do
|
108
|
+
config.port.should be Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration.default_port
|
109
|
+
end
|
110
|
+
|
111
|
+
it "ami allows you to configure a username and a password, both of which default to nil" do
|
112
|
+
config.username.should be nil
|
113
|
+
config.password.should be nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "Rails configuration defaults" do
|
118
|
+
it "should require the path to the Rails app in the constructor" do
|
119
|
+
config = Adhearsion::Configuration::RailsConfiguration.new :path => "path here doesn't matter right now", :env => :development
|
120
|
+
config.rails_root.should_not be nil
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should expand_path() the first constructor parameter" do
|
124
|
+
rails_root = "gui"
|
125
|
+
flexmock(File).should_receive(:expand_path).once.with(rails_root)
|
126
|
+
config = Adhearsion::Configuration::RailsConfiguration.new :path => rails_root, :env => :development
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "Database configuration defaults" do
|
131
|
+
|
132
|
+
before(:each) do
|
133
|
+
Adhearsion.send(:remove_const, :AHN_CONFIG) if Adhearsion.const_defined?(:AHN_CONFIG)
|
134
|
+
Adhearsion::Configuration.configure {}
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should store the constructor's argument in connection_options()" do
|
138
|
+
sample_options = { :adapter => "sqlite3", :dbfile => "foo.sqlite3" }
|
139
|
+
config = Adhearsion::Configuration::DatabaseConfiguration.new(sample_options)
|
140
|
+
config.connection_options.should be sample_options
|
141
|
+
end
|
142
|
+
it "should remove the :orm key from the connection options" do
|
143
|
+
sample_options = { :orm => :active_record, :adapter => "mysql", :host => "::1",
|
144
|
+
:user => "a", :pass => "b", :database => "ahn" }
|
145
|
+
config = Adhearsion::Configuration::DatabaseConfiguration.new(sample_options.clone)
|
146
|
+
config.orm.should be sample_options.delete(:orm)
|
147
|
+
config.connection_options.should == sample_options
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "Freeswitch configuration defaults" do
|
152
|
+
attr_reader :config
|
153
|
+
|
154
|
+
before(:each) do
|
155
|
+
@config = Adhearsion::Configuration::FreeswitchConfiguration.new
|
156
|
+
end
|
157
|
+
|
158
|
+
it "freeswitch configuration sets default listening port" do
|
159
|
+
config.listening_port.should be Adhearsion::Configuration::FreeswitchConfiguration.default_listening_port
|
160
|
+
end
|
161
|
+
|
162
|
+
it "freeswitch configuration sets default listening host" do
|
163
|
+
config.listening_host.should == Adhearsion::Configuration::FreeswitchConfiguration.default_listening_host
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "XMPP configuration defaults" do
|
168
|
+
attr_reader :config
|
169
|
+
|
170
|
+
it "xmpp configuration sets default port when server is set, but no port" do
|
171
|
+
config = Adhearsion::Configuration::XMPPConfiguration.new :jid => "test@example.com", :password => "somepassword", :server => "example.com"
|
172
|
+
config.port.should be Adhearsion::Configuration::XMPPConfiguration.default_port
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should raise when port is specified, but no server" do
|
176
|
+
begin
|
177
|
+
config = Adhearsion::Configuration::XMPPConfiguration.new :jid => "test@example.com", :password => "somepassword", :port => "5223"
|
178
|
+
rescue ArgumentError => e
|
179
|
+
e.message.should == "Must supply a :server argument as well as :port to the XMPP initializer!"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "Configuration scenarios" do
|
185
|
+
include ConfigurationTestHelper
|
186
|
+
|
187
|
+
it "enabling AMI using all its defaults" do
|
188
|
+
config = enable_ami
|
189
|
+
|
190
|
+
config.asterisk.ami_enabled?.should be true
|
191
|
+
config.asterisk.ami.should be_a_kind_of Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration
|
192
|
+
end
|
193
|
+
|
194
|
+
it "enabling AMI with custom configuration overrides the defaults" do
|
195
|
+
overridden_port = 911
|
196
|
+
config = enable_ami :port => overridden_port
|
197
|
+
config.asterisk.ami.port.should be overridden_port
|
198
|
+
end
|
199
|
+
|
200
|
+
it "enabling Drb without any configuration" do
|
201
|
+
config = enable_drb
|
202
|
+
config.drb.should_not be nil
|
203
|
+
config.drb.should be_a_kind_of Adhearsion::Configuration::DrbConfiguration
|
204
|
+
end
|
205
|
+
|
206
|
+
it "enabling Drb with a port specified sets the port" do
|
207
|
+
target_port = 911
|
208
|
+
config = enable_drb :port => target_port
|
209
|
+
config.drb.port.should == target_port
|
210
|
+
end
|
211
|
+
|
212
|
+
private
|
213
|
+
def enable_ami(*overrides)
|
214
|
+
default_config do |config|
|
215
|
+
config.asterisk.enable_ami(*overrides)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def enable_drb(*overrides)
|
220
|
+
default_config do |config|
|
221
|
+
config.enable_drb *overrides
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "AHN_CONFIG" do
|
227
|
+
before(:each) do
|
228
|
+
Adhearsion.send(:remove_const, :AHN_CONFIG) if Adhearsion.const_defined?(:AHN_CONFIG)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "Running configure sets configuration to Adhearsion::AHN_CONFIG" do
|
232
|
+
Adhearsion.const_defined?(:AHN_CONFIG).should be false
|
233
|
+
Adhearsion::Configuration.configure do |config|
|
234
|
+
# Nothing needs to happen here
|
235
|
+
end
|
236
|
+
|
237
|
+
Adhearsion.const_defined?(:AHN_CONFIG).should be true
|
238
|
+
Adhearsion::AHN_CONFIG.should be_a_kind_of(Adhearsion::Configuration)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "DRb configuration" do
|
243
|
+
it "should not add any ACL rules when :raw_acl is passed in" do
|
244
|
+
config = Adhearsion::Configuration::DrbConfiguration.new :raw_acl => :this_is_an_acl
|
245
|
+
config.acl.should be :this_is_an_acl
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should, by default, allow only localhost connections" do
|
249
|
+
config = Adhearsion::Configuration::DrbConfiguration.new
|
250
|
+
config.acl.should == %w[allow 127.0.0.1]
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should add ACL 'deny' rules before 'allow' rules" do
|
254
|
+
config = Adhearsion::Configuration::DrbConfiguration.new :allow => %w[1.1.1.1 2.2.2.2],
|
255
|
+
:deny => %w[9.9.9.9]
|
256
|
+
config.acl.should == %w[deny 9.9.9.9 allow 1.1.1.1 allow 2.2.2.2]
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should allow both an Array and a String to be passed as an allow/deny ACL rule" do
|
260
|
+
config = Adhearsion::Configuration::DrbConfiguration.new :allow => "1.1.1.1", :deny => "9.9.9.9"
|
261
|
+
config.acl.should == %w[deny 9.9.9.9 allow 1.1.1.1]
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should have a default host and port" do
|
265
|
+
config = Adhearsion::Configuration::DrbConfiguration.new
|
266
|
+
config.host.should_not be nil
|
267
|
+
config.port.should_not be nil
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'adhearsion/initializer/database'
|
3
|
+
require 'adhearsion/initializer/asterisk'
|
4
|
+
require 'adhearsion/initializer/rails'
|
5
|
+
require 'adhearsion/initializer/xmpp'
|
6
|
+
require 'active_record'
|
7
|
+
|
8
|
+
module DatabaseInitializationTestHelper
|
9
|
+
|
10
|
+
def start_database_initializer
|
11
|
+
start_database_initializer_with_options :adapter => "sqlite3", :dbfile => "foobar.sqlite3"
|
12
|
+
end
|
13
|
+
|
14
|
+
def start_database_initializer_with_options(options)
|
15
|
+
Adhearsion::Configuration.configure { |config| config.enable_database(options) }
|
16
|
+
Adhearsion::Initializer::DatabaseInitializer.start
|
17
|
+
end
|
18
|
+
|
19
|
+
def tempfile_with_contents(contents)
|
20
|
+
Tempfile.new("bogus_model").tap do |file|
|
21
|
+
file.puts contents
|
22
|
+
file.flush
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def sample_user_model
|
27
|
+
<<-CODE
|
28
|
+
class User < ActiveRecord::Base
|
29
|
+
validates_uniqueness_of :name
|
30
|
+
end
|
31
|
+
CODE
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module AsteriskInitializerTestHelper
|
36
|
+
def initialize_asterisk_with_defaults
|
37
|
+
initialize_asterisk_with_options Hash.new
|
38
|
+
end
|
39
|
+
def initialize_asterisk_with_options(options)
|
40
|
+
flexmock(Adhearsion::Initializer::AsteriskInitializer).should_receive(:join_server_thread_after_initialized)
|
41
|
+
Adhearsion::Configuration.configure { |config| config.enable_asterisk(options) }
|
42
|
+
Adhearsion::Initializer::AsteriskInitializer.start
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module RailsInitializerTestHelper
|
47
|
+
|
48
|
+
def initialize_rails_with_options(options)
|
49
|
+
rails_options = flexmock "Rails options mock", options
|
50
|
+
flexstub(Adhearsion::AHN_CONFIG).should_receive(:rails).once.and_return(rails_options)
|
51
|
+
Adhearsion::Initializer::RailsInitializer.start
|
52
|
+
end
|
53
|
+
|
54
|
+
def stub_file_checking_methods!
|
55
|
+
flexstub(File).should_receive(:directory?).and_return true
|
56
|
+
flexstub(File).should_receive(:exists?).and_return true
|
57
|
+
end
|
58
|
+
|
59
|
+
def stub_before_call_hook!
|
60
|
+
flexstub(Adhearsion::Events.framework_theatre).should_receive(:register_namespace_name).with([:asterisk, :before_call]).and_return
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "The database initializer" do
|
66
|
+
|
67
|
+
include DatabaseInitializationTestHelper
|
68
|
+
|
69
|
+
after :each do
|
70
|
+
Adhearsion.send(:remove_const, :AHN_CONFIG) if Adhearsion.const_defined? :AHN_CONFIG
|
71
|
+
end
|
72
|
+
|
73
|
+
it "starts a connection through ActiveRecord" do
|
74
|
+
connection_options = { :adapter => "sqlite3",
|
75
|
+
:dbfile => "foo.sqlite3" }
|
76
|
+
flexmock(Adhearsion::Initializer::DatabaseInitializer).should_receive(:require_models).once
|
77
|
+
flexmock(ActiveRecord::Base).should_receive(:establish_connection).with(connection_options)
|
78
|
+
|
79
|
+
start_database_initializer_with_options connection_options
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should make any required models available in the main namespace" do
|
83
|
+
bogus_model = tempfile_with_contents sample_user_model
|
84
|
+
flexmock(Adhearsion::Configuration).new_instances.should_receive(:files_from_setting).once.
|
85
|
+
with("paths", "models").and_return [bogus_model.path]
|
86
|
+
start_database_initializer
|
87
|
+
User.superclass.should be ActiveRecord::Base
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "The Asterisk initializer" do
|
93
|
+
|
94
|
+
include AsteriskInitializerTestHelper
|
95
|
+
|
96
|
+
it "starts the AGI server" do
|
97
|
+
initialize_asterisk_with_defaults
|
98
|
+
flexmock(Adhearsion::VoIP::Asterisk::AGI::Server).new_instances.should_receive(:start).once
|
99
|
+
end
|
100
|
+
|
101
|
+
it "starts the AGI server with any overridden settings" do
|
102
|
+
overrides = {:host => "127.0.0.1", :port => 7788}
|
103
|
+
config_overrides = {:listening_host => overrides[:host], :listening_port => overrides[:port]}
|
104
|
+
initialize_asterisk_with_options config_overrides
|
105
|
+
flexmock(Adhearsion::VoIP::Asterisk::AGI::Server).new_instances.should_receive(:start).once.with(overrides)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "The Rails initializer" do
|
111
|
+
|
112
|
+
include RailsInitializerTestHelper
|
113
|
+
|
114
|
+
it "should load the config/environment.rb file within the rails_root path" do
|
115
|
+
rails_root = "/path/to/rails/app"
|
116
|
+
environment_rb = rails_root + '/config/environment.rb'
|
117
|
+
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).once.with environment_rb
|
118
|
+
stub_file_checking_methods!
|
119
|
+
stub_before_call_hook!
|
120
|
+
initialize_rails_with_options :rails_root => rails_root, :environment => :development
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should raise an exception if the database is initialized at the same time" do
|
124
|
+
flexstub(Adhearsion::AHN_CONFIG).should_receive(:database_enabled?).and_return true
|
125
|
+
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).and_return
|
126
|
+
stub_file_checking_methods!
|
127
|
+
stub_before_call_hook!
|
128
|
+
the_following_code {
|
129
|
+
initialize_rails_with_options :rails_root => '/tmp', :environment => :development
|
130
|
+
}.should raise_error
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should set the RAILS_ENV to be the argument passed in" do
|
134
|
+
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).once.and_return
|
135
|
+
stub_file_checking_methods!
|
136
|
+
stub_before_call_hook!
|
137
|
+
initialize_rails_with_options :rails_root => '/tmp', :environment => :development
|
138
|
+
raise Test::Unit::AssertionFailed, 'ENV["RAILS_ENV"] should have been set but was not.' unless ENV['RAILS_ENV'] == "development"
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should create a BeforeCall hook (presumably to verify the active connections)' do
|
142
|
+
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :require
|
143
|
+
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :load_rails
|
144
|
+
stub_file_checking_methods!
|
145
|
+
flexmock(Adhearsion::Events).should_receive(:register_callback).once.with([:asterisk, :before_call], Proc)
|
146
|
+
initialize_rails_with_options :rails_root => '/path/somewhere', :environment => :development
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PathsTestHelper
|
4
|
+
def mock_ahnrc_with(raw_yaml)
|
5
|
+
Adhearsion::AHN_CONFIG.ahnrc = raw_yaml
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "Files from config" do
|
10
|
+
|
11
|
+
include PathsTestHelper
|
12
|
+
|
13
|
+
it "the old way of doing paths should not still be around" do
|
14
|
+
should_not respond_to(:all_helpers)
|
15
|
+
should_not respond_to(:helper_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should work when only one filename is present" do
|
19
|
+
mock_ahnrc_with "paths:\n init: foobar.rb"
|
20
|
+
flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_glob).once.with("foobar.rb").and_return "foobar.rb"
|
21
|
+
Adhearsion::AHN_CONFIG.files_from_setting("paths", "init").should ==["foobar.rb"]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should only expand a glob if the filename contains *"
|
25
|
+
|
26
|
+
it "should work when an Array of filenames is present" do
|
27
|
+
files = %w[jay.rb thomas.rb phillips.rb]
|
28
|
+
flexstub(Dir).should_receive(:glob).with(*files).and_return(*files)
|
29
|
+
yaml = <<-YML
|
30
|
+
paths:
|
31
|
+
init:
|
32
|
+
#{
|
33
|
+
files.map { |f| " - #{f}" }.join("\n")
|
34
|
+
}
|
35
|
+
YML
|
36
|
+
Adhearsion::AHN_CONFIG.ahnrc = yaml
|
37
|
+
|
38
|
+
flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_glob).once.with("jay.rb").and_return "jay.rb"
|
39
|
+
flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_glob).once.with("thomas.rb").and_return "thomas.rb"
|
40
|
+
flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_glob).once.with("phillips.rb").and_return "phillips.rb"
|
41
|
+
|
42
|
+
Adhearsion::AHN_CONFIG.files_from_setting("paths", "init").should == files
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should work when one glob filename is present" do
|
46
|
+
files = %w[foo.rb bar.rb qaz.rb]
|
47
|
+
flexmock(Dir).should_receive(:glob).once.with(/\*.rb$/).and_return files
|
48
|
+
yaml = <<-YML
|
49
|
+
paths:
|
50
|
+
init:
|
51
|
+
-*.rb
|
52
|
+
YML
|
53
|
+
Adhearsion::AHN_CONFIG.ahnrc = yaml
|
54
|
+
Adhearsion::AHN_CONFIG.files_from_setting("paths", "init").should == %w[foo.rb bar.rb qaz.rb]
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should work when an Array of globs are present" do
|
58
|
+
files = %w[aaa.rb aba.rb aca.rb]
|
59
|
+
flexstub(Dir).should_receive(:glob).with(*files).and_return(*files)
|
60
|
+
yaml = <<-YML
|
61
|
+
paths:
|
62
|
+
init:
|
63
|
+
#{
|
64
|
+
files.map { |filename| " - #{filename}" }.join("\n") + "\n"
|
65
|
+
}
|
66
|
+
YML
|
67
|
+
Adhearsion::AHN_CONFIG.ahnrc = yaml
|
68
|
+
files.each do |file|
|
69
|
+
flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_glob).once.with(file).and_return file
|
70
|
+
end
|
71
|
+
Adhearsion::AHN_CONFIG.files_from_setting("paths", "init").should == files
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|