switest 0.1.1 → 0.2.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/README.md +18 -2
- data/lib/switest/agent.rb +5 -0
- data/lib/switest/esl/call.rb +4 -0
- data/lib/switest/scenario.rb +12 -2
- data/lib/switest/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 46d12432ffab240a974d72b3dd40c644881db795afdf01f0907837bf6a07f749
|
|
4
|
+
data.tar.gz: 599397a725f50b57b243a42a451b8dea72497fbc86fd8dd2908096627a22e097
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a409ab5e4948ac6bd38518f3a5bcbbaac61e8154ce6e162916f0ae0fa66ab819b68f0f3cf073127703ebb38741d616c8437f3a1a3cebad376d6d240b188eb6cd
|
|
7
|
+
data.tar.gz: eda147e356709c794896b2e274b2bf7e74f15dc42c422e5898255ec8c62c112deb5f8249cded86b056257a91befc1f65a498ff76eb680dfa6584b0631a871e01
|
data/README.md
CHANGED
|
@@ -172,7 +172,8 @@ assert_call(agent, timeout: 5) # Agent receives a call
|
|
|
172
172
|
assert_no_call(agent, timeout: 2) # Agent does NOT receive a call
|
|
173
173
|
assert_hungup(agent, timeout: 5) # Call has ended
|
|
174
174
|
assert_not_hungup(agent, timeout: 2) # Call is still active
|
|
175
|
-
assert_dtmf(agent, "123", timeout: 5)
|
|
175
|
+
assert_dtmf(agent, "123", timeout: 5) # Agent receives expected DTMF digits
|
|
176
|
+
assert_dtmf(agent, "123") { other.send_dtmf("123") } # With block: flushes stale DTMF first
|
|
176
177
|
```
|
|
177
178
|
|
|
178
179
|
The `hangup_all` helper ends all active calls (useful before CDR assertions):
|
|
@@ -228,7 +229,22 @@ digits = alice.receive_dtmf(count: 4, timeout: 5)
|
|
|
228
229
|
assert_equal "1234", digits
|
|
229
230
|
```
|
|
230
231
|
|
|
231
|
-
Or use the assertion helper
|
|
232
|
+
Or use the assertion helper with a block to avoid stale DTMF issues.
|
|
233
|
+
The block is executed after a configurable delay (`after:`, default 1s)
|
|
234
|
+
while the assertion is already listening:
|
|
235
|
+
|
|
236
|
+
```ruby
|
|
237
|
+
assert_dtmf(bob, "1234") do
|
|
238
|
+
alice.send_dtmf("1234")
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# With custom delay and timeout:
|
|
242
|
+
assert_dtmf(bob, "1234", timeout: 10, after: 0.5) do
|
|
243
|
+
alice.send_dtmf("1234")
|
|
244
|
+
end
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Without a block it works as a simple wait (backward compatible):
|
|
232
248
|
|
|
233
249
|
```ruby
|
|
234
250
|
assert_dtmf(alice, "1234", timeout: 5)
|
data/lib/switest/agent.rb
CHANGED
|
@@ -72,6 +72,11 @@ module Switest
|
|
|
72
72
|
@call.receive_dtmf(count: count, timeout: timeout)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
def flush_dtmf
|
|
76
|
+
raise "No call for DTMF" unless @call
|
|
77
|
+
@call.flush_dtmf
|
|
78
|
+
end
|
|
79
|
+
|
|
75
80
|
def wait_for_call(timeout: 5)
|
|
76
81
|
deadline = Time.now + timeout
|
|
77
82
|
while Time.now < deadline
|
data/lib/switest/esl/call.rb
CHANGED
data/lib/switest/scenario.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "minitest/test"
|
|
4
|
+
require "concurrent"
|
|
4
5
|
|
|
5
6
|
module Switest
|
|
6
7
|
class Scenario < Minitest::Test
|
|
@@ -60,9 +61,18 @@ module Switest
|
|
|
60
61
|
refute agent.ended?, "Expected call to still be active"
|
|
61
62
|
end
|
|
62
63
|
|
|
63
|
-
def assert_dtmf(agent, expected_dtmf, timeout: 5)
|
|
64
|
+
def assert_dtmf(agent, expected_dtmf, timeout: 5, after: 1, &block)
|
|
64
65
|
assert agent.call?, "Agent has no call"
|
|
65
|
-
|
|
66
|
+
|
|
67
|
+
if block
|
|
68
|
+
agent.flush_dtmf
|
|
69
|
+
task = Concurrent::ScheduledTask.execute(after) { block.call }
|
|
70
|
+
received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout)
|
|
71
|
+
task.wait
|
|
72
|
+
else
|
|
73
|
+
received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout)
|
|
74
|
+
end
|
|
75
|
+
|
|
66
76
|
assert_equal expected_dtmf, received, "Expected DTMF '#{expected_dtmf}' but received '#{received}'"
|
|
67
77
|
end
|
|
68
78
|
end
|
data/lib/switest/version.rb
CHANGED