adhearsion 2.5.4 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/CHANGELOG.md +15 -0
- data/README.markdown +2 -1
- data/Rakefile +1 -6
- data/adhearsion.gemspec +4 -3
- data/features/cli_daemon.feature +2 -4
- data/features/cli_restart.feature +14 -5
- data/features/cli_start.feature +0 -2
- data/features/cli_stop.feature +15 -6
- data/lib/adhearsion.rb +21 -23
- data/lib/adhearsion/call.rb +49 -5
- data/lib/adhearsion/call_controller.rb +29 -11
- data/lib/adhearsion/call_controller/dial.rb +21 -9
- data/lib/adhearsion/call_controller/menu_dsl.rb +12 -12
- data/lib/adhearsion/call_controller/menu_dsl/array_match_calculator.rb +1 -1
- data/lib/adhearsion/call_controller/menu_dsl/fixnum_match_calculator.rb +1 -0
- data/lib/adhearsion/call_controller/menu_dsl/string_match_calculator.rb +1 -1
- data/lib/adhearsion/call_controller/output.rb +36 -7
- data/lib/adhearsion/call_controller/output/abstract_player.rb +4 -0
- data/lib/adhearsion/call_controller/record.rb +1 -0
- data/lib/adhearsion/cli_commands/ahn_command.rb +7 -4
- data/lib/adhearsion/cli_commands/plugin_command.rb +2 -0
- data/lib/adhearsion/generators.rb +2 -4
- data/lib/adhearsion/generators/app/templates/simon_game_spec.rb +20 -20
- data/lib/adhearsion/initializer.rb +2 -2
- data/lib/adhearsion/plugin.rb +6 -6
- data/lib/adhearsion/punchblock_plugin.rb +3 -4
- data/lib/adhearsion/punchblock_plugin/initializer.rb +2 -1
- data/lib/adhearsion/router.rb +7 -7
- data/lib/adhearsion/router/route.rb +10 -4
- data/lib/adhearsion/rspec.rb +2 -0
- data/lib/adhearsion/version.rb +1 -1
- data/spec/adhearsion/call_controller/dial_spec.rb +589 -557
- data/spec/adhearsion/call_controller/input_spec.rb +91 -91
- data/spec/adhearsion/call_controller/menu_dsl/array_match_calculator_spec.rb +29 -29
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_collection_spec.rb +6 -6
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_spec.rb +19 -19
- data/spec/adhearsion/call_controller/menu_dsl/fixnum_match_calculator_spec.rb +6 -6
- data/spec/adhearsion/call_controller/menu_dsl/match_calculator_spec.rb +1 -1
- data/spec/adhearsion/call_controller/menu_dsl/menu_builder_spec.rb +21 -17
- data/spec/adhearsion/call_controller/menu_dsl/menu_spec.rb +96 -83
- data/spec/adhearsion/call_controller/menu_dsl/range_match_calculator_spec.rb +5 -5
- data/spec/adhearsion/call_controller/menu_dsl/string_match_calculator_spec.rb +9 -9
- data/spec/adhearsion/call_controller/output/async_player_spec.rb +14 -4
- data/spec/adhearsion/call_controller/output/formatter_spec.rb +14 -14
- data/spec/adhearsion/call_controller/output/player_spec.rb +15 -5
- data/spec/adhearsion/call_controller/output_spec.rb +126 -78
- data/spec/adhearsion/call_controller/record_spec.rb +38 -26
- data/spec/adhearsion/call_controller/utility_spec.rb +11 -11
- data/spec/adhearsion/call_controller_spec.rb +176 -136
- data/spec/adhearsion/call_spec.rb +443 -218
- data/spec/adhearsion/calls_spec.rb +33 -33
- data/spec/adhearsion/configuration_spec.rb +61 -61
- data/spec/adhearsion/console_spec.rb +29 -29
- data/spec/adhearsion/events_spec.rb +14 -14
- data/spec/adhearsion/generators_spec.rb +1 -1
- data/spec/adhearsion/initializer_spec.rb +42 -42
- data/spec/adhearsion/logging_spec.rb +33 -33
- data/spec/adhearsion/outbound_call_spec.rb +69 -55
- data/spec/adhearsion/plugin_spec.rb +53 -44
- data/spec/adhearsion/process_spec.rb +21 -21
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +68 -52
- data/spec/adhearsion/punchblock_plugin_spec.rb +6 -6
- data/spec/adhearsion/router/evented_route_spec.rb +2 -2
- data/spec/adhearsion/router/openended_route_spec.rb +9 -9
- data/spec/adhearsion/router/route_spec.rb +61 -31
- data/spec/adhearsion/router/unaccepting_route_spec.rb +13 -13
- data/spec/adhearsion/router_spec.rb +47 -33
- data/spec/adhearsion/statistics/dump_spec.rb +6 -6
- data/spec/adhearsion/statistics_spec.rb +9 -9
- data/spec/adhearsion_spec.rb +23 -20
- data/spec/spec_helper.rb +3 -6
- data/spec/support/call_controller_test_helpers.rb +7 -7
- data/spec/support/initializer_stubs.rb +1 -1
- data/spec/support/punchblock_mocks.rb +1 -1
- metadata +22 -10
- data/features/support/utils.rb +0 -9
@@ -13,7 +13,7 @@ module Adhearsion
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should have a GirlFriday::Queue to handle events" do
|
16
|
-
Events.queue.
|
16
|
+
expect(Events.queue).to be_a GirlFriday::WorkQueue
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should allow adding events to the queue and handle them appropriately" do
|
@@ -21,7 +21,7 @@ module Adhearsion
|
|
21
21
|
o = nil
|
22
22
|
latch = CountDownLatch.new 1
|
23
23
|
|
24
|
-
Events.instance.
|
24
|
+
expect(Events.instance).to receive(:handle_message) do |message|
|
25
25
|
t = message.type
|
26
26
|
o = message.object
|
27
27
|
latch.countdown!
|
@@ -29,16 +29,16 @@ module Adhearsion
|
|
29
29
|
|
30
30
|
Events.trigger :event, :foo
|
31
31
|
|
32
|
-
latch.wait(2).
|
33
|
-
t.
|
34
|
-
o.
|
32
|
+
expect(latch.wait(2)).to be_truthy
|
33
|
+
expect(t).to eq(:event)
|
34
|
+
expect(o).to eq(:foo)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should allow executing events immediately" do
|
38
38
|
t = nil
|
39
39
|
o = nil
|
40
40
|
|
41
|
-
Events.instance.
|
41
|
+
expect(Events.instance).to receive(:handle_message) do |message|
|
42
42
|
sleep 0.25
|
43
43
|
t = message.type
|
44
44
|
o = message.object
|
@@ -46,8 +46,8 @@ module Adhearsion
|
|
46
46
|
|
47
47
|
Events.trigger_immediately :event, :foo
|
48
48
|
|
49
|
-
t.
|
50
|
-
o.
|
49
|
+
expect(t).to eq(:event)
|
50
|
+
expect(o).to eq(:foo)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should handle events using registered guarded handlers" do
|
@@ -59,13 +59,13 @@ module Adhearsion
|
|
59
59
|
|
60
60
|
Events.trigger_immediately :event, EventClass.new
|
61
61
|
|
62
|
-
result.
|
62
|
+
expect(result).to eq(:foo)
|
63
63
|
|
64
64
|
Events.clear_handlers :event, EventClass
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should handle exceptions in event processing by raising the exception as an event" do
|
68
|
-
Events.instance.
|
68
|
+
expect(Events.instance).to receive(:trigger).with(:exception, kind_of(ExceptionClass)).once
|
69
69
|
|
70
70
|
Events.register_handler :event, EventClass do |event|
|
71
71
|
raise ExceptionClass
|
@@ -88,7 +88,7 @@ module Adhearsion
|
|
88
88
|
|
89
89
|
Events.trigger_immediately :event, EventClass.new
|
90
90
|
|
91
|
-
result.
|
91
|
+
expect(result).to eq(:bar)
|
92
92
|
|
93
93
|
Events.clear_handlers :event, EventClass
|
94
94
|
end
|
@@ -97,8 +97,8 @@ module Adhearsion
|
|
97
97
|
Events.register_handler :event_type_1 do |event|
|
98
98
|
end
|
99
99
|
|
100
|
-
Events.
|
101
|
-
Events.
|
100
|
+
expect(Events).to respond_to(:event_type_1)
|
101
|
+
expect(Events).not_to respond_to(:event_type_2)
|
102
102
|
end
|
103
103
|
|
104
104
|
describe '#draw' do
|
@@ -112,7 +112,7 @@ module Adhearsion
|
|
112
112
|
|
113
113
|
Events.trigger_immediately :event
|
114
114
|
|
115
|
-
result.
|
115
|
+
expect(result).to eq(:foo)
|
116
116
|
|
117
117
|
Events.clear_handlers :event
|
118
118
|
end
|
@@ -12,7 +12,7 @@ module Adhearsion
|
|
12
12
|
DummyGenerator = Class.new
|
13
13
|
|
14
14
|
Generators.add_generator generator_key, DummyGenerator
|
15
|
-
Generators.mappings[generator_key].
|
15
|
+
expect(Generators.mappings[generator_key]).to eq(DummyGenerator)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -12,8 +12,8 @@ describe Adhearsion::Initializer do
|
|
12
12
|
describe "#start" do
|
13
13
|
before do
|
14
14
|
::Logging.reset
|
15
|
-
Adhearsion::Logging.
|
16
|
-
::Logging::Appenders.
|
15
|
+
expect(Adhearsion::Logging).to receive(:start).once.and_return('')
|
16
|
+
allow(::Logging::Appenders).to receive_messages(:file => nil)
|
17
17
|
Adhearsion.config = nil
|
18
18
|
end
|
19
19
|
|
@@ -34,7 +34,7 @@ describe Adhearsion::Initializer do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should start the stats aggregator" do
|
37
|
-
Adhearsion.
|
37
|
+
expect(Adhearsion).to receive(:statistics).at_least(:once)
|
38
38
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
39
39
|
Adhearsion::Initializer.start
|
40
40
|
end
|
@@ -42,33 +42,33 @@ describe Adhearsion::Initializer do
|
|
42
42
|
|
43
43
|
it "should create a pid file in the app's path when given 'true' as the pid_file hash key argument" do
|
44
44
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
45
|
-
File.
|
45
|
+
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
46
46
|
ahn = Adhearsion::Initializer.start :pid_file => true
|
47
|
-
ahn.pid_file[0, path.length].
|
47
|
+
expect(ahn.pid_file[0, path.length]).to eq(path)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should NOT create a pid file in the app's path when given 'false' as the pid_file hash key argument" do
|
52
52
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
53
53
|
ahn = Adhearsion::Initializer.start :pid_file => false
|
54
|
-
ahn.pid_file.
|
54
|
+
expect(ahn.pid_file).to be nil
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should create a pid file in the app's path by default when daemonizing" do
|
59
59
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
60
|
-
Adhearsion::CustomDaemonizer.
|
61
|
-
File.
|
60
|
+
expect(Adhearsion::CustomDaemonizer).to receive(:daemonize).and_yield '123'
|
61
|
+
expect(File).to receive(:open).once.with(File.join(path, 'adhearsion.pid'), 'w')
|
62
62
|
ahn = Adhearsion::Initializer.start :mode => :daemon
|
63
|
-
ahn.pid_file[0, path.size].
|
63
|
+
expect(ahn.pid_file[0, path.size]).to eq(path)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should NOT create a pid file in the app's path when daemonizing and :pid_file is given as false" do
|
68
68
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
69
|
-
Adhearsion::CustomDaemonizer.
|
69
|
+
expect(Adhearsion::CustomDaemonizer).to receive(:daemonize).and_yield '123'
|
70
70
|
ahn = Adhearsion::Initializer.start :mode => :daemon, :pid_file => false
|
71
|
-
ahn.pid_file.
|
71
|
+
expect(ahn.pid_file).to be nil
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -76,63 +76,63 @@ describe Adhearsion::Initializer do
|
|
76
76
|
random_file = "/tmp/AHN_TEST_#{rand 100000}.pid"
|
77
77
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
78
78
|
ahn = Adhearsion::Initializer.start :pid_file => random_file
|
79
|
-
ahn.pid_file.
|
80
|
-
File.exists?(random_file).
|
79
|
+
expect(ahn.pid_file).to eq(random_file)
|
80
|
+
expect(File.exists?(random_file)).to be true
|
81
81
|
File.delete random_file
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should resolve the log file path to daemonize" do
|
86
86
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
87
|
-
File.
|
87
|
+
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
88
88
|
ahn = Adhearsion::Initializer.start :pid_file => true
|
89
|
-
ahn.resolve_log_file_path.
|
89
|
+
expect(ahn.resolve_log_file_path).to eq(path + Adhearsion.config.platform.logging.outputters[0])
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should resolve the log file path to daemonize when outputters is an Array" do
|
94
94
|
Adhearsion.config.platform.logging.outputters = ["log/my_application.log", "log/adhearsion.log"]
|
95
95
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
96
|
-
File.
|
96
|
+
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
97
97
|
ahn = Adhearsion::Initializer.start :pid_file => true
|
98
|
-
ahn.resolve_log_file_path.
|
98
|
+
expect(ahn.resolve_log_file_path).to eq(path + Adhearsion.config.platform.logging.outputters[0])
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should return a valid appenders array" do
|
103
103
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
104
|
-
File.
|
104
|
+
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
105
105
|
ahn = Adhearsion::Initializer.start :pid_file => true
|
106
106
|
appenders = ahn.init_get_logging_appenders
|
107
|
-
appenders.
|
108
|
-
appenders[1].
|
107
|
+
expect(appenders.size).to eq(2)
|
108
|
+
expect(appenders[1]).to be_instance_of Logging::Appenders::Stdout
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should initialize properly the log paths" do
|
113
113
|
ahn = stub_behavior_for_initializer_with_no_path_changing_behavior do
|
114
|
-
File.
|
114
|
+
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
115
115
|
Adhearsion::Initializer.start :pid_file => true
|
116
116
|
end
|
117
|
-
Dir.
|
117
|
+
expect(Dir).to receive(:mkdir).with("log/")
|
118
118
|
ahn.initialize_log_paths
|
119
119
|
end
|
120
120
|
|
121
121
|
it "should initialize properly the log paths when outputters is an array" do
|
122
122
|
Adhearsion.config.platform.logging.outputters = ["log/my_application.log", "log/test/adhearsion.log"]
|
123
123
|
ahn = stub_behavior_for_initializer_with_no_path_changing_behavior do
|
124
|
-
File.
|
124
|
+
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
125
125
|
Adhearsion::Initializer.start :pid_file => true
|
126
126
|
end
|
127
|
-
Dir.
|
128
|
-
Dir.
|
127
|
+
expect(Dir).to receive(:mkdir).with("log/").twice
|
128
|
+
expect(Dir).to receive(:mkdir).with("log/test/").once
|
129
129
|
ahn.initialize_log_paths
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should set the adhearsion proc name" do
|
133
133
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
134
|
-
File.
|
135
|
-
Adhearsion::LinuxProcName.
|
134
|
+
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
135
|
+
expect(Adhearsion::LinuxProcName).to receive(:set_proc_name).with(Adhearsion.config.platform.process_name)
|
136
136
|
Adhearsion::Initializer.start :pid_file => true
|
137
137
|
end
|
138
138
|
end
|
@@ -141,14 +141,14 @@ describe Adhearsion::Initializer do
|
|
141
141
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
142
142
|
Adhearsion::Initializer.start :pid_file => true
|
143
143
|
end
|
144
|
-
$0.
|
144
|
+
expect($0).to eq(Adhearsion.config.platform.process_name)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
describe "Initializing logger" do
|
149
149
|
before do
|
150
150
|
::Logging.reset
|
151
|
-
::Logging::Appenders.
|
151
|
+
expect(::Logging::Appenders).to receive(:file).and_return(nil)
|
152
152
|
Adhearsion.config = nil
|
153
153
|
end
|
154
154
|
|
@@ -161,8 +161,8 @@ describe Adhearsion::Initializer do
|
|
161
161
|
|
162
162
|
it "should start logging with valid parameters" do
|
163
163
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
164
|
-
File.
|
165
|
-
Adhearsion::Logging.
|
164
|
+
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
165
|
+
expect(Adhearsion::Logging).to receive(:start).once.with(kind_of(Array), :info, nil).and_return('')
|
166
166
|
Adhearsion::Initializer.start :pid_file => true
|
167
167
|
end
|
168
168
|
end
|
@@ -174,24 +174,24 @@ describe Adhearsion::Initializer do
|
|
174
174
|
end
|
175
175
|
|
176
176
|
it "should load the contents of lib directory" do
|
177
|
-
Dir.
|
177
|
+
expect(Dir).to receive(:chdir).with(File.join(path, "lib")).and_return []
|
178
178
|
Adhearsion::Initializer.new.load_lib_folder
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should return false if folder does not exist" do
|
182
182
|
Adhearsion.config.platform.lib = "my_random_lib_directory"
|
183
|
-
Adhearsion::Initializer.new.load_lib_folder.
|
183
|
+
expect(Adhearsion::Initializer.new.load_lib_folder).to eq(false)
|
184
184
|
end
|
185
185
|
|
186
186
|
it "should return false and not load any file if config folder is set to nil" do
|
187
187
|
Adhearsion.config.platform.lib = nil
|
188
|
-
Adhearsion::Initializer.new.load_lib_folder.
|
188
|
+
expect(Adhearsion::Initializer.new.load_lib_folder).to eq(false)
|
189
189
|
end
|
190
190
|
|
191
191
|
it "should load the contents of the preconfigured directory" do
|
192
192
|
Adhearsion.config.platform.lib = "foo"
|
193
|
-
File.
|
194
|
-
Dir.
|
193
|
+
allow(File).to receive_messages directory?: true
|
194
|
+
expect(Dir).to receive(:chdir).with(File.join(path, "foo")).and_return []
|
195
195
|
Adhearsion::Initializer.new.load_lib_folder
|
196
196
|
end
|
197
197
|
end
|
@@ -202,8 +202,8 @@ describe "Updating RAILS_ENV variable" do
|
|
202
202
|
|
203
203
|
before do
|
204
204
|
::Logging.reset
|
205
|
-
Adhearsion::Logging.
|
206
|
-
::Logging::Appenders.
|
205
|
+
expect(Adhearsion::Logging).to receive(:start).once.and_return('')
|
206
|
+
expect(::Logging::Appenders).to receive(:file).and_return(nil)
|
207
207
|
Adhearsion.config = nil
|
208
208
|
end
|
209
209
|
|
@@ -226,7 +226,7 @@ describe "Updating RAILS_ENV variable" do
|
|
226
226
|
ahn = Adhearsion::Initializer.start
|
227
227
|
end
|
228
228
|
ahn.update_rails_env_var
|
229
|
-
ENV['RAILS_ENV'].
|
229
|
+
expect(ENV['RAILS_ENV']).to eq(env.to_s)
|
230
230
|
end
|
231
231
|
end
|
232
232
|
end
|
@@ -244,7 +244,7 @@ describe "Updating RAILS_ENV variable" do
|
|
244
244
|
ahn = Adhearsion::Initializer.start
|
245
245
|
end
|
246
246
|
ahn.update_rails_env_var
|
247
|
-
ENV['RAILS_ENV'].
|
247
|
+
expect(ENV['RAILS_ENV']).to eq("test")
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
@@ -255,7 +255,7 @@ describe "Updating RAILS_ENV variable" do
|
|
255
255
|
ahn = Adhearsion::Initializer.start
|
256
256
|
end
|
257
257
|
ahn.update_rails_env_var
|
258
|
-
ENV['RAILS_ENV'].
|
258
|
+
expect(ENV['RAILS_ENV']).to eq("test")
|
259
259
|
end
|
260
260
|
end
|
261
261
|
end
|
@@ -271,7 +271,7 @@ describe "Updating RAILS_ENV variable" do
|
|
271
271
|
ahn = Adhearsion::Initializer.start
|
272
272
|
end
|
273
273
|
ahn.update_rails_env_var
|
274
|
-
ENV['RAILS_ENV'].
|
274
|
+
expect(ENV['RAILS_ENV']).to eq("production")
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
@@ -20,73 +20,73 @@ describe Adhearsion::Logging do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should be added to any Object' do
|
23
|
-
Foo.
|
23
|
+
expect(Foo).to respond_to(:logger)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should be added to any Object instance' do
|
27
|
-
Foo.new.
|
27
|
+
expect(Foo.new).to respond_to :logger
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should create the predefined set of log levels' do
|
31
|
-
::Logging::LEVELS.keys.
|
31
|
+
expect(::Logging::LEVELS.keys).to eq(Adhearsion::Logging::LOG_LEVELS.map(&:downcase))
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should log to the Object logger when given arguments" do
|
35
35
|
message = "o hai. ur home erly."
|
36
36
|
foo = Foo.new
|
37
|
-
::Logging.logger[Foo].
|
37
|
+
expect(::Logging.logger[Foo]).to receive(:info).once.with(message)
|
38
38
|
foo.logger.info message
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should log to the Object logger when given arguments (II)" do
|
42
42
|
message = "o hai. ur home erly."
|
43
43
|
bar = Foo::Bar.new
|
44
|
-
::Logging.logger[Foo::Bar].
|
44
|
+
expect(::Logging.logger[Foo::Bar]).to receive(:info).once.with(message)
|
45
45
|
bar.logger.info message
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should create a new logger when given method_missing' do
|
49
49
|
FooBar = Class.new Foo
|
50
|
-
::Logging::Repository.instance[FooBar].
|
50
|
+
expect(::Logging::Repository.instance[FooBar]).to be_nil
|
51
51
|
FooBar.logger.info "o hai. ur home erly."
|
52
|
-
::Logging::Repository.instance[FooBar].
|
52
|
+
expect(::Logging::Repository.instance[FooBar]).not_to be_nil
|
53
53
|
end
|
54
54
|
|
55
55
|
it "initializes properly a Logging object" do
|
56
|
-
::Logging.logger.root.appenders.length.
|
57
|
-
::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length.
|
56
|
+
expect(::Logging.logger.root.appenders.length).to eql(1)
|
57
|
+
expect(::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length).to eql(1)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "initializes properly a Logging object with appenders as parameter" do
|
61
61
|
Adhearsion::Logging.start([::Logging.appenders.stdout, ::Logging.appenders.file('example.log')])
|
62
|
-
::Logging.logger.root.appenders.length.
|
63
|
-
::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length.
|
64
|
-
::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::File)}.length.
|
62
|
+
expect(::Logging.logger.root.appenders.length).to eql(2)
|
63
|
+
expect(::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length).to eql(1)
|
64
|
+
expect(::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::File)}.length).to eql(1)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "initializes properly a Logging object with appenders and log level as parameter" do
|
68
68
|
Adhearsion::Logging.start([::Logging.appenders.stdout, ::Logging.appenders.file('example.log')], :debug)
|
69
|
-
::Logging.logger.root.appenders.length.
|
70
|
-
::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length.
|
71
|
-
::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::File)}.length.
|
72
|
-
::Logging.logger.root.level.
|
69
|
+
expect(::Logging.logger.root.appenders.length).to eql(2)
|
70
|
+
expect(::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length).to eql(1)
|
71
|
+
expect(::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::File)}.length).to eql(1)
|
72
|
+
expect(::Logging.logger.root.level).to eql(::Logging::LEVELS["debug"])
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should create only a Logging object per Class (reuse per all the instances)" do
|
76
76
|
_logger = Foo.new.logger
|
77
77
|
10.times do
|
78
|
-
Foo.new.logger.object_id.
|
78
|
+
expect(Foo.new.logger.object_id).to eql(_logger.object_id)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should reuse a Logging instance in all Class instances but not with child instances" do
|
83
83
|
_foo_logger = Foo.new.logger
|
84
84
|
_bar_logger = Foo::Bar.new.logger
|
85
|
-
_foo_logger.object_id.
|
85
|
+
expect(_foo_logger.object_id).not_to eql(_bar_logger)
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'should reopen logfiles' do
|
89
|
-
::Logging.
|
89
|
+
expect(::Logging).to receive(:reopen).once
|
90
90
|
Adhearsion::Logging.reopen_logs
|
91
91
|
end
|
92
92
|
|
@@ -95,9 +95,9 @@ describe Adhearsion::Logging do
|
|
95
95
|
Adhearsion.config.platform.logging['level'] = :warn
|
96
96
|
Adhearsion::Logging.level = :warn
|
97
97
|
Adhearsion::Logging.toggle_trace!
|
98
|
-
Adhearsion::Logging.level.
|
98
|
+
expect(Adhearsion::Logging.level).to eq(0)
|
99
99
|
Adhearsion::Logging.toggle_trace!
|
100
|
-
Adhearsion::Logging.level.
|
100
|
+
expect(Adhearsion::Logging.level).to eq(3)
|
101
101
|
Adhearsion.config.platform.logging['level'] = orig_level
|
102
102
|
end
|
103
103
|
|
@@ -108,40 +108,40 @@ describe Adhearsion::Logging do
|
|
108
108
|
|
109
109
|
it 'changing the logging level should affect all loggers' do
|
110
110
|
loggers = [::Foo.logger, ::Foo::Bar.logger]
|
111
|
-
loggers.map(&:level).
|
112
|
-
loggers.map(&:level).
|
111
|
+
expect(loggers.map(&:level)).not_to eq([Adhearsion::Logging::DEBUG] * 2)
|
112
|
+
expect(loggers.map(&:level)).to eq([Adhearsion::Logging::INFO] * 2)
|
113
113
|
Adhearsion::Logging.logging_level = :warn
|
114
|
-
loggers.map(&:level).
|
114
|
+
expect(loggers.map(&:level)).to eq([Adhearsion::Logging::WARN] * 2)
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'changing the logging level, using level=, should affect all loggers' do
|
118
118
|
loggers = [Foo.logger, ::Foo::Bar.logger]
|
119
|
-
loggers.map(&:level).
|
120
|
-
loggers.map(&:level).
|
119
|
+
expect(loggers.map(&:level)).not_to eq([::Logging::LEVELS["debug"]] * 2)
|
120
|
+
expect(loggers.map(&:level)).to eq([::Logging::LEVELS["info"]] * 2)
|
121
121
|
Adhearsion::Logging.level = :warn
|
122
|
-
loggers.map(&:level).
|
122
|
+
expect(loggers.map(&:level)).to eq([::Logging::LEVELS["warn"]] * 2)
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'should change all the Logger instance level' do
|
126
|
-
Foo.logger.level.
|
126
|
+
expect(Foo.logger.level).to be Adhearsion::Logging::INFO
|
127
127
|
Adhearsion::Logging.logging_level = :fatal
|
128
|
-
Foo.logger.level.
|
128
|
+
expect(Foo.logger.level).to be Adhearsion::Logging::FATAL
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'a new logger should have the :root logging level' do
|
132
|
-
Foo.logger.level.
|
132
|
+
expect(Foo.logger.level).to be Adhearsion::Logging::INFO
|
133
133
|
Adhearsion::Logging.logging_level = :fatal
|
134
|
-
Foo::Bar.logger.level.
|
134
|
+
expect(Foo::Bar.logger.level).to be Adhearsion::Logging::FATAL
|
135
135
|
end
|
136
136
|
|
137
137
|
it '#silence! should change the level to be FATAL' do
|
138
138
|
Adhearsion::Logging.silence!
|
139
|
-
Adhearsion::Logging.logging_level.
|
139
|
+
expect(Adhearsion::Logging.logging_level).to be(Adhearsion::Logging::FATAL)
|
140
140
|
end
|
141
141
|
|
142
142
|
it '#unsilence! should change the level to be INFO' do
|
143
143
|
Adhearsion::Logging.unsilence!
|
144
|
-
Adhearsion::Logging.logging_level.
|
144
|
+
expect(Adhearsion::Logging.logging_level).to be(Adhearsion::Logging::INFO)
|
145
145
|
end
|
146
146
|
|
147
147
|
end
|