adhearsion 2.5.4 → 2.6.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.
- 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
@@ -4,10 +4,17 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
module Adhearsion
|
6
6
|
describe OutboundCall do
|
7
|
-
it {
|
7
|
+
it { is_expected.to be_a Call }
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
describe '#id' do
|
10
|
+
subject { super().id }
|
11
|
+
it { is_expected.to be_nil }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#variables' do
|
15
|
+
subject { super().variables }
|
16
|
+
it { is_expected.to eq({}) }
|
17
|
+
end
|
11
18
|
|
12
19
|
let(:mock_client) { double 'Punchblock Client', execute_command: true, new_call_uri: call_uri }
|
13
20
|
|
@@ -16,8 +23,15 @@ module Adhearsion
|
|
16
23
|
Adhearsion.active_calls.clear
|
17
24
|
end
|
18
25
|
|
19
|
-
|
20
|
-
|
26
|
+
describe '#client' do
|
27
|
+
subject { super().client }
|
28
|
+
it { is_expected.to be mock_client }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#start_time' do
|
32
|
+
subject { super().start_time }
|
33
|
+
it { is_expected.to be nil }
|
34
|
+
end
|
21
35
|
|
22
36
|
let(:transport) { 'xmpp' }
|
23
37
|
let(:call_id) { SecureRandom.uuid }
|
@@ -30,7 +44,7 @@ module Adhearsion
|
|
30
44
|
foo = :bar
|
31
45
|
subject.after(1) { foo = :baz }
|
32
46
|
sleep 1.1
|
33
|
-
foo.
|
47
|
+
expect(foo).to eq(:baz)
|
34
48
|
end
|
35
49
|
|
36
50
|
describe ".originate" do
|
@@ -40,18 +54,18 @@ module Adhearsion
|
|
40
54
|
|
41
55
|
before do
|
42
56
|
mock_call
|
43
|
-
OutboundCall.
|
57
|
+
expect(OutboundCall).to receive(:new).and_return mock_call
|
44
58
|
end
|
45
59
|
|
46
60
|
it "should dial the call to the correct endpoint and return it" do
|
47
|
-
mock_call.wrapped_object.
|
48
|
-
OutboundCall.originate(to, :from => 'foo').
|
61
|
+
expect(mock_call.wrapped_object).to receive(:dial).with(to, :from => 'foo').once
|
62
|
+
expect(OutboundCall.originate(to, :from => 'foo')).to be mock_call
|
49
63
|
end
|
50
64
|
|
51
65
|
it "should run through the router when the call is answered" do
|
52
|
-
mock_call.wrapped_object.
|
66
|
+
expect(mock_call.wrapped_object).to receive(:dial).once
|
53
67
|
|
54
|
-
Adhearsion.router.
|
68
|
+
expect(Adhearsion.router).to receive(:handle).once.with(mock_call)
|
55
69
|
|
56
70
|
OutboundCall.originate(to) << Punchblock::Event::Answered.new
|
57
71
|
end
|
@@ -60,15 +74,15 @@ module Adhearsion
|
|
60
74
|
let(:controller) { CallController }
|
61
75
|
|
62
76
|
it "should execute the controller on the call when it is answered" do
|
63
|
-
mock_call.
|
64
|
-
mock_call.
|
77
|
+
expect(mock_call).to receive(:dial).once.with(to, {})
|
78
|
+
expect(mock_call).to receive(:execute_controller).once.with kind_of(controller), kind_of(Proc)
|
65
79
|
call = OutboundCall.originate to, :controller => controller
|
66
80
|
call << Punchblock::Event::Answered.new
|
67
81
|
end
|
68
82
|
|
69
83
|
it "should hangup the call after all controllers have executed" do
|
70
|
-
mock_call.
|
71
|
-
mock_call.
|
84
|
+
expect(mock_call).to receive(:dial).once
|
85
|
+
expect(mock_call).to receive(:hangup).once
|
72
86
|
|
73
87
|
call = OutboundCall.originate to, :controller => controller
|
74
88
|
call << Punchblock::Event::Answered.new
|
@@ -77,9 +91,9 @@ module Adhearsion
|
|
77
91
|
|
78
92
|
context "with controller metadata specified" do
|
79
93
|
it "should set the metadata on the controller" do
|
80
|
-
mock_call.
|
94
|
+
expect(mock_call).to receive(:dial).once.with(to, {})
|
81
95
|
expected_controller = controller.new mock_call, foo: 'bar'
|
82
|
-
mock_call.
|
96
|
+
expect(mock_call).to receive(:execute_controller).with(expected_controller, kind_of(Proc)).once
|
83
97
|
call = OutboundCall.originate to, :controller => controller, :controller_metadata => {:foo => 'bar'}
|
84
98
|
call << Punchblock::Event::Answered.new
|
85
99
|
end
|
@@ -88,9 +102,9 @@ module Adhearsion
|
|
88
102
|
|
89
103
|
context "when given a block" do
|
90
104
|
it "should execute the block as a controller on the call when it is answered" do
|
91
|
-
mock_call.
|
92
|
-
mock_call.
|
93
|
-
controller.block.call.
|
105
|
+
expect(mock_call).to receive(:dial).once.with(to, {})
|
106
|
+
expect(mock_call).to receive(:execute_controller).once.with(kind_of(CallController), kind_of(Proc)) do |controller|
|
107
|
+
expect(controller.block.call).to eq(:foobar)
|
94
108
|
end
|
95
109
|
|
96
110
|
call = OutboundCall.originate to do
|
@@ -102,8 +116,8 @@ module Adhearsion
|
|
102
116
|
|
103
117
|
context "when the dial fails" do
|
104
118
|
before do
|
105
|
-
subject.wrapped_object.
|
106
|
-
Punchblock::Command::Dial.
|
119
|
+
expect(subject.wrapped_object).to receive(:write_command)
|
120
|
+
expect_any_instance_of(Punchblock::Command::Dial).to receive(:response).and_return StandardError.new("User not registered")
|
107
121
|
end
|
108
122
|
|
109
123
|
after do
|
@@ -117,7 +131,7 @@ module Adhearsion
|
|
117
131
|
it "should kill the actor" do
|
118
132
|
expect { subject.dial to }.to raise_error("User not registered")
|
119
133
|
sleep 0.1
|
120
|
-
subject.
|
134
|
+
expect(subject.alive?).to be false
|
121
135
|
end
|
122
136
|
end
|
123
137
|
end
|
@@ -129,7 +143,7 @@ module Adhearsion
|
|
129
143
|
let(:event) { Punchblock::Event::Answered.new }
|
130
144
|
|
131
145
|
it "should trigger any on_answer callbacks set" do
|
132
|
-
response.
|
146
|
+
expect(response).to receive(:call).once.with(event)
|
133
147
|
subject.on_answer { |event| response.call event }
|
134
148
|
subject << event
|
135
149
|
end
|
@@ -137,27 +151,27 @@ module Adhearsion
|
|
137
151
|
it "should record the call start time" do
|
138
152
|
originate_time = Time.local(2008, 9, 1, 12, 0, 0)
|
139
153
|
Timecop.freeze originate_time
|
140
|
-
subject.duration.
|
154
|
+
expect(subject.duration).to eq(0.0)
|
141
155
|
|
142
156
|
mid_point_time = Time.local(2008, 9, 1, 12, 0, 20)
|
143
157
|
Timecop.freeze mid_point_time
|
144
|
-
subject.duration.
|
158
|
+
expect(subject.duration).to eq(0.0)
|
145
159
|
|
146
160
|
answer_time = Time.local(2008, 9, 1, 12, 0, 40)
|
147
161
|
Timecop.freeze answer_time
|
148
162
|
subject << event
|
149
|
-
subject.start_time.
|
163
|
+
expect(subject.start_time).to eq(answer_time)
|
150
164
|
|
151
165
|
later_time = Time.local(2008, 9, 1, 12, 0, 50)
|
152
166
|
Timecop.freeze later_time
|
153
|
-
subject.duration.
|
167
|
+
expect(subject.duration).to eq(10.0)
|
154
168
|
end
|
155
169
|
end
|
156
170
|
end
|
157
171
|
|
158
172
|
describe "#dial" do
|
159
173
|
def expect_message_waiting_for_response(message, uri = call_uri)
|
160
|
-
subject.wrapped_object.
|
174
|
+
expect(subject.wrapped_object).to receive(:write_and_await_response).once.with(message, 60, true) do |real_message|
|
161
175
|
real_message.request!
|
162
176
|
real_message.response = Punchblock::Ref.new(uri: uri)
|
163
177
|
real_message
|
@@ -168,29 +182,29 @@ module Adhearsion
|
|
168
182
|
|
169
183
|
context "while waiting for a response" do
|
170
184
|
before do
|
171
|
-
mock_client.
|
185
|
+
expect(mock_client).to receive(:execute_command).once.with(expected_dial_command).and_return true
|
172
186
|
subject.async.dial to, from: from
|
173
187
|
sleep 1
|
174
188
|
end
|
175
189
|
|
176
190
|
it "should set the dial command" do
|
177
|
-
subject.dial_command.
|
191
|
+
expect(subject.dial_command).to eq(expected_dial_command)
|
178
192
|
end
|
179
193
|
|
180
194
|
it "should know its requested URI" do
|
181
|
-
subject.uri.
|
195
|
+
expect(subject.uri).to eq(call_uri)
|
182
196
|
end
|
183
197
|
|
184
198
|
it "should know its requested ID" do
|
185
|
-
subject.id.
|
199
|
+
expect(subject.id).to eq(call_id)
|
186
200
|
end
|
187
201
|
|
188
202
|
it "should know its domain" do
|
189
|
-
subject.domain.
|
203
|
+
expect(subject.domain).to eq(domain)
|
190
204
|
end
|
191
205
|
|
192
206
|
it "should be entered in the active calls registry" do
|
193
|
-
Adhearsion.active_calls[call_id].
|
207
|
+
expect(Adhearsion.active_calls[call_id]).to be subject
|
194
208
|
end
|
195
209
|
end
|
196
210
|
|
@@ -207,37 +221,37 @@ module Adhearsion
|
|
207
221
|
|
208
222
|
it "should set the dial command" do
|
209
223
|
subject.dial to, :from => from
|
210
|
-
subject.dial_command.
|
224
|
+
expect(subject.dial_command).to eq(Punchblock::Command::Dial.new(:to => to, :from => from, :uri => call_uri, target_call_id: call_id, domain: domain, transport: transport))
|
211
225
|
end
|
212
226
|
|
213
227
|
it "should set the URI from the reference" do
|
214
228
|
subject.dial to, :from => from
|
215
|
-
subject.uri.
|
229
|
+
expect(subject.uri).to eq(call_uri)
|
216
230
|
end
|
217
231
|
|
218
232
|
it "should set the call ID from the reference" do
|
219
233
|
subject.dial to, :from => from
|
220
|
-
subject.id.
|
234
|
+
expect(subject.id).to eq(call_id)
|
221
235
|
end
|
222
236
|
|
223
237
|
it "should set the call domain from the reference" do
|
224
238
|
subject.dial to, :from => from
|
225
|
-
subject.domain.
|
239
|
+
expect(subject.domain).to eq(domain)
|
226
240
|
end
|
227
241
|
|
228
242
|
it "should set the to from the dial command" do
|
229
243
|
subject.dial to, :from => from
|
230
|
-
subject.to.
|
244
|
+
expect(subject.to).to eq(to)
|
231
245
|
end
|
232
246
|
|
233
247
|
it "should set the 'from' from the dial command" do
|
234
248
|
subject.dial to, :from => from
|
235
|
-
subject.from.
|
249
|
+
expect(subject.from).to eq(from)
|
236
250
|
end
|
237
251
|
|
238
252
|
it "should add the call to the active calls registry" do
|
239
253
|
subject.dial to, :from => from
|
240
|
-
Adhearsion.active_calls[call_id].
|
254
|
+
expect(Adhearsion.active_calls[call_id]).to be subject
|
241
255
|
end
|
242
256
|
|
243
257
|
context "when a different ref is returned than the one expected" do
|
@@ -248,41 +262,41 @@ module Adhearsion
|
|
248
262
|
end
|
249
263
|
|
250
264
|
it "should set the URI from the reference" do
|
251
|
-
subject.uri.
|
265
|
+
expect(subject.uri).to eq(returned_uri)
|
252
266
|
end
|
253
267
|
|
254
268
|
it "should set the call ID from the reference" do
|
255
|
-
subject.id.
|
269
|
+
expect(subject.id).to eq('otherid')
|
256
270
|
end
|
257
271
|
|
258
272
|
it "should set the call domain from the reference" do
|
259
|
-
subject.domain.
|
273
|
+
expect(subject.domain).to eq('wonderland.lit')
|
260
274
|
end
|
261
275
|
|
262
276
|
it "should make the call addressible in the active calls registry by the new ID" do
|
263
|
-
Adhearsion.active_calls[call_id].
|
264
|
-
Adhearsion.active_calls['otherid'].
|
277
|
+
expect(Adhearsion.active_calls[call_id]).to be_nil
|
278
|
+
expect(Adhearsion.active_calls['otherid']).to be subject
|
265
279
|
end
|
266
280
|
end
|
267
281
|
|
268
282
|
it "should immediately fire the :call_dialed event giving the call" do
|
269
|
-
Adhearsion::Events.
|
283
|
+
expect(Adhearsion::Events).to receive(:trigger_immediately).once.with(:call_dialed, subject)
|
270
284
|
subject.dial to, :from => from
|
271
285
|
end
|
272
286
|
|
273
287
|
it "should not modify the provided options" do
|
274
288
|
options = {:from => from}
|
275
289
|
original_options = Marshal.load(Marshal.dump(options))
|
276
|
-
options.
|
290
|
+
expect(options).to eq(original_options)
|
277
291
|
subject.dial to, options
|
278
|
-
options.
|
292
|
+
expect(options).to eq(original_options)
|
279
293
|
end
|
280
294
|
end
|
281
295
|
|
282
296
|
context "when the dial fails" do
|
283
297
|
before do
|
284
|
-
subject.wrapped_object.
|
285
|
-
Punchblock::Command::Dial.
|
298
|
+
expect(subject.wrapped_object).to receive(:write_command)
|
299
|
+
expect_any_instance_of(Punchblock::Command::Dial).to receive(:response).and_return StandardError.new("User not registered")
|
286
300
|
end
|
287
301
|
|
288
302
|
after do
|
@@ -296,20 +310,20 @@ module Adhearsion
|
|
296
310
|
it "should kill the actor" do
|
297
311
|
expect { subject.dial to }.to raise_error("User not registered")
|
298
312
|
sleep 0.1
|
299
|
-
subject.
|
313
|
+
expect(subject.alive?).to be false
|
300
314
|
end
|
301
315
|
|
302
316
|
it "should remove the call from the active calls hash" do
|
303
317
|
expect { subject.dial to }.to raise_error("User not registered")
|
304
318
|
sleep 0.1
|
305
|
-
Adhearsion.active_calls[call_id].
|
319
|
+
expect(Adhearsion.active_calls[call_id]).to be_nil
|
306
320
|
end
|
307
321
|
end
|
308
322
|
end
|
309
323
|
|
310
324
|
describe "basic control commands" do
|
311
325
|
def expect_no_message_waiting_for_response
|
312
|
-
subject.wrapped_object.
|
326
|
+
expect(subject.wrapped_object).to receive(:write_and_await_response).never
|
313
327
|
end
|
314
328
|
|
315
329
|
describe '#accept' do
|
@@ -12,7 +12,7 @@ describe Adhearsion::Plugin do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
before do
|
15
|
-
Adhearsion::PunchblockPlugin::Initializer.
|
15
|
+
allow(Adhearsion::PunchblockPlugin::Initializer).to receive_messages :start => true
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "inheritance" do
|
@@ -22,12 +22,12 @@ describe Adhearsion::Plugin do
|
|
22
22
|
|
23
23
|
it "should provide the plugin name in a plugin class" do
|
24
24
|
::FooBar = Class.new Adhearsion::Plugin
|
25
|
-
::FooBar.plugin_name.
|
25
|
+
expect(::FooBar.plugin_name).to eq("foo_bar")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should provide the plugin name in a plugin instance" do
|
29
29
|
::FooBar = Class.new Adhearsion::Plugin
|
30
|
-
::FooBar.new.plugin_name.
|
30
|
+
expect(::FooBar.new.plugin_name).to eq("foo_bar")
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should provide a setter for plugin name" do
|
@@ -35,7 +35,7 @@ describe Adhearsion::Plugin do
|
|
35
35
|
self.plugin_name = "bar_foo"
|
36
36
|
end
|
37
37
|
|
38
|
-
::FooBar.plugin_name.
|
38
|
+
expect(::FooBar.plugin_name).to eq("bar_foo")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -54,28 +54,34 @@ describe Adhearsion::Plugin do
|
|
54
54
|
end
|
55
55
|
}
|
56
56
|
|
57
|
-
|
57
|
+
describe '#plugin_name' do
|
58
|
+
subject { super().plugin_name }
|
59
|
+
it { is_expected.to eq(:bar_foo) }
|
60
|
+
end
|
58
61
|
|
59
|
-
|
62
|
+
describe '#config' do
|
63
|
+
subject { super().config }
|
64
|
+
it { is_expected.to be_instance_of Loquacious::Configuration }
|
65
|
+
end
|
60
66
|
|
61
67
|
it "should keep a default configuration and a description" do
|
62
68
|
[:name, :password, :host].each do |value|
|
63
|
-
subject.config.
|
69
|
+
expect(subject.config).to respond_to value
|
64
70
|
end
|
65
71
|
|
66
|
-
subject.config.name.
|
67
|
-
subject.config.password.
|
68
|
-
subject.config.host.
|
72
|
+
expect(subject.config.name).to eq("user")
|
73
|
+
expect(subject.config.password).to eq("password")
|
74
|
+
expect(subject.config.host).to eq("localhost")
|
69
75
|
end
|
70
76
|
|
71
77
|
it "should return a description of configuration options" do
|
72
|
-
subject.show_description.
|
78
|
+
expect(subject.show_description).to be_kind_of Loquacious::Configuration::Help
|
73
79
|
end
|
74
80
|
|
75
81
|
describe "while updating config values" do
|
76
82
|
it "should return the updated value" do
|
77
83
|
subject.config.name = "usera"
|
78
|
-
subject.config.name.
|
84
|
+
expect(subject.config.name).to eq("usera")
|
79
85
|
end
|
80
86
|
end
|
81
87
|
|
@@ -87,15 +93,15 @@ describe Adhearsion::Plugin do
|
|
87
93
|
it "should add plugins on the air" do
|
88
94
|
Adhearsion::Plugin.delete_all
|
89
95
|
Adhearsion::Plugin.add AhnPluginDemo
|
90
|
-
Adhearsion::Plugin.count.
|
96
|
+
expect(Adhearsion::Plugin.count).to eql 1
|
91
97
|
end
|
92
98
|
|
93
99
|
it "should delete plugins on the air" do
|
94
100
|
Adhearsion::Plugin.delete_all
|
95
101
|
Adhearsion::Plugin.add AhnPluginDemo
|
96
|
-
Adhearsion::Plugin.count.
|
102
|
+
expect(Adhearsion::Plugin.count).to eql 1
|
97
103
|
Adhearsion::Plugin.delete AhnPluginDemo
|
98
|
-
Adhearsion::Plugin.count.
|
104
|
+
expect(Adhearsion::Plugin.count).to eql 0
|
99
105
|
end
|
100
106
|
end
|
101
107
|
|
@@ -107,7 +113,7 @@ describe Adhearsion::Plugin do
|
|
107
113
|
it "should count the number of registered plugins" do
|
108
114
|
number = Adhearsion::Plugin.count
|
109
115
|
FooBar = Class.new Adhearsion::Plugin
|
110
|
-
Adhearsion::Plugin.count.
|
116
|
+
expect(Adhearsion::Plugin.count).to eql(number + 1)
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
@@ -142,7 +148,7 @@ describe Adhearsion::Plugin do
|
|
142
148
|
FooBar = Class.new Adhearsion::Plugin
|
143
149
|
|
144
150
|
# 1 => Punchblock. Must be empty once punchblock initializer is an external Plugin
|
145
|
-
Adhearsion::Plugin.initializers.
|
151
|
+
expect(Adhearsion::Plugin.initializers.size).to eq(1)
|
146
152
|
Adhearsion::Plugin.init_plugins
|
147
153
|
end
|
148
154
|
|
@@ -155,8 +161,8 @@ describe Adhearsion::Plugin do
|
|
155
161
|
end
|
156
162
|
end
|
157
163
|
|
158
|
-
FooBar.
|
159
|
-
Adhearsion::Plugin.initializers.length.
|
164
|
+
expect(FooBar).to receive(:log).once
|
165
|
+
expect(Adhearsion::Plugin.initializers.length).to be 1
|
160
166
|
Adhearsion::Plugin.init_plugins
|
161
167
|
end
|
162
168
|
|
@@ -181,7 +187,7 @@ describe Adhearsion::Plugin do
|
|
181
187
|
end
|
182
188
|
end
|
183
189
|
|
184
|
-
FooBar.
|
190
|
+
expect(FooBar).to receive(:log).exactly(3).times
|
185
191
|
Adhearsion::Plugin.init_plugins
|
186
192
|
end
|
187
193
|
|
@@ -201,8 +207,8 @@ describe Adhearsion::Plugin do
|
|
201
207
|
end
|
202
208
|
end
|
203
209
|
|
204
|
-
Adhearsion::Plugin.initializers.tsort.first.name.
|
205
|
-
Adhearsion::Plugin.initializers.tsort.last.name.
|
210
|
+
expect(Adhearsion::Plugin.initializers.tsort.first.name).to eql :foo_bar_baz
|
211
|
+
expect(Adhearsion::Plugin.initializers.tsort.last.name).to eql :foo_bar
|
206
212
|
end
|
207
213
|
|
208
214
|
it "should allow to include an initializer after another one" do
|
@@ -227,9 +233,9 @@ describe Adhearsion::Plugin do
|
|
227
233
|
end
|
228
234
|
end
|
229
235
|
|
230
|
-
Adhearsion::Plugin.initializers.length.
|
231
|
-
Adhearsion::Plugin.initializers.tsort.first.name.
|
232
|
-
Adhearsion::Plugin.initializers.tsort.last.name.
|
236
|
+
expect(Adhearsion::Plugin.initializers.length).to eql 3
|
237
|
+
expect(Adhearsion::Plugin.initializers.tsort.first.name).to eql :foo_bar
|
238
|
+
expect(Adhearsion::Plugin.initializers.tsort.last.name).to eql :foo_bar_baz
|
233
239
|
end
|
234
240
|
end
|
235
241
|
|
@@ -238,7 +244,7 @@ describe Adhearsion::Plugin do
|
|
238
244
|
FooBar = Class.new Adhearsion::Plugin
|
239
245
|
|
240
246
|
# May become 1 if Punchblock defines a runner.
|
241
|
-
Adhearsion::Plugin.runners.
|
247
|
+
expect(Adhearsion::Plugin.runners.size).to eq(0)
|
242
248
|
Adhearsion::Plugin.run_plugins
|
243
249
|
end
|
244
250
|
|
@@ -251,8 +257,8 @@ describe Adhearsion::Plugin do
|
|
251
257
|
end
|
252
258
|
end
|
253
259
|
|
254
|
-
FooBar.
|
255
|
-
Adhearsion::Plugin.runners.length.
|
260
|
+
expect(FooBar).to receive(:log).once
|
261
|
+
expect(Adhearsion::Plugin.runners.length).to be 1
|
256
262
|
Adhearsion::Plugin.run_plugins
|
257
263
|
end
|
258
264
|
|
@@ -277,7 +283,7 @@ describe Adhearsion::Plugin do
|
|
277
283
|
end
|
278
284
|
end
|
279
285
|
|
280
|
-
FooBar.
|
286
|
+
expect(FooBar).to receive(:log).exactly(3).times
|
281
287
|
Adhearsion::Plugin.run_plugins
|
282
288
|
end
|
283
289
|
|
@@ -297,8 +303,8 @@ describe Adhearsion::Plugin do
|
|
297
303
|
end
|
298
304
|
end
|
299
305
|
|
300
|
-
Adhearsion::Plugin.runners.tsort.first.name.
|
301
|
-
Adhearsion::Plugin.runners.tsort.last.name.
|
306
|
+
expect(Adhearsion::Plugin.runners.tsort.first.name).to eql :foo_bar_baz
|
307
|
+
expect(Adhearsion::Plugin.runners.tsort.last.name).to eql :foo_bar
|
302
308
|
end
|
303
309
|
|
304
310
|
it "should allow to include an runner after another one" do
|
@@ -323,9 +329,9 @@ describe Adhearsion::Plugin do
|
|
323
329
|
end
|
324
330
|
end
|
325
331
|
|
326
|
-
Adhearsion::Plugin.runners.length.
|
327
|
-
Adhearsion::Plugin.runners.tsort.first.name.
|
328
|
-
Adhearsion::Plugin.runners.tsort.last.name.
|
332
|
+
expect(Adhearsion::Plugin.runners.length).to eql 3
|
333
|
+
expect(Adhearsion::Plugin.runners.tsort.first.name).to eql :foo_bar
|
334
|
+
expect(Adhearsion::Plugin.runners.tsort.last.name).to eql :foo_bar_baz
|
329
335
|
end
|
330
336
|
end
|
331
337
|
end
|
@@ -340,32 +346,35 @@ describe Adhearsion::Plugin do
|
|
340
346
|
subject { Adhearsion::Plugin.tasks }
|
341
347
|
|
342
348
|
it "should return an Array" do
|
343
|
-
subject.
|
349
|
+
expect(subject).to be_instance_of Array
|
344
350
|
end
|
345
351
|
|
346
|
-
|
352
|
+
describe '#length' do
|
353
|
+
subject { super().length }
|
354
|
+
it { is_expected.to eq(0) }
|
355
|
+
end
|
347
356
|
|
348
357
|
it "should not load a new task when there is no block in the method call" do
|
349
|
-
subject.length.
|
358
|
+
expect(subject.length).to eq(0)
|
350
359
|
FooBar = Class.new Adhearsion::Plugin do
|
351
360
|
tasks
|
352
361
|
end
|
353
362
|
|
354
|
-
subject.length.
|
363
|
+
expect(subject.length).to eq(0)
|
355
364
|
end
|
356
365
|
|
357
366
|
it "should load a new task when there is a block in the method call" do
|
358
|
-
subject.length.
|
367
|
+
expect(subject.length).to eq(0)
|
359
368
|
FooBar = Class.new Adhearsion::Plugin do
|
360
369
|
tasks do
|
361
370
|
puts "foo bar"
|
362
371
|
end
|
363
372
|
end
|
364
|
-
Adhearsion::Plugin.tasks.length.
|
373
|
+
expect(Adhearsion::Plugin.tasks.length).to eq(1)
|
365
374
|
end
|
366
375
|
|
367
376
|
it "should execute the tasks blocks while loading rake tasks" do
|
368
|
-
subject.length.
|
377
|
+
expect(subject.length).to eq(0)
|
369
378
|
FooBar = Class.new Adhearsion::Plugin do
|
370
379
|
tasks do
|
371
380
|
FooBar.foo
|
@@ -373,7 +382,7 @@ describe Adhearsion::Plugin do
|
|
373
382
|
def self.foo
|
374
383
|
end
|
375
384
|
end
|
376
|
-
FooBar.
|
385
|
+
expect(FooBar).to receive(:foo).once
|
377
386
|
Adhearsion::Plugin.load_tasks
|
378
387
|
end
|
379
388
|
|
@@ -392,8 +401,8 @@ describe Adhearsion::Plugin do
|
|
392
401
|
generators :gen1 => TestGenerator1, :gen2 => TestGenerator2
|
393
402
|
end
|
394
403
|
|
395
|
-
Adhearsion::Generators.mappings[:gen1].
|
396
|
-
Adhearsion::Generators.mappings[:gen2].
|
404
|
+
expect(Adhearsion::Generators.mappings[:gen1]).to be TestGenerator1
|
405
|
+
expect(Adhearsion::Generators.mappings[:gen2]).to be TestGenerator2
|
397
406
|
end
|
398
407
|
end
|
399
408
|
|