Class: Switest::Scenario

Inherits:
Minitest::Test
  • Object
show all
Includes:
Assertions
Defined in:
lib/switest/scenario.rb

Constant Summary collapse

Agent =

Make Agent accessible to subclasses

Switest::Agent

Instance Method Summary collapse

Methods included from Assertions

#assert_answered, #assert_call, #assert_dtmf, #assert_hungup, #assert_no_call, #assert_not_hungup

Instance Method Details

#hangup_all(cause: "NORMAL_CLEARING", timeout: 5) ⇒ Object

Hangup all active calls and wait for them to end. Useful when tests need all legs hung up before proceeding (e.g., for CDR writes).



45
46
47
# File 'lib/switest/scenario.rb', line 45

def hangup_all(cause: "NORMAL_CLEARING", timeout: 5)
  @client&.hangup_all(cause: cause, timeout: timeout)
end

#runObject

Run each test inside an async reactor so that fibers, conditions, and async I/O work transparently for users extending Scenario.



15
16
17
# File 'lib/switest/scenario.rb', line 15

def run(...)
  Sync { super }
end

#setupObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/switest/scenario.rb', line 19

def setup
  @events = Events.new
  @client = Client.new
  @client.start

  # Route inbound calls through events system
  @client.on_offer do |call|
    @events.emit(:offer, {
      to: call.to,
      from: call.from,
      call: call,
      headers: call.headers,
      profile: call.headers[:variable_sofia_profile_name]
    })
  end

  Agent.setup(@client, @events)
end

#teardownObject



38
39
40
41
# File 'lib/switest/scenario.rb', line 38

def teardown
  Agent.teardown
  @client&.stop
end