Class: Alplus::TestTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/alplus/transport.rb

Overview

In-memory transport used when config.test_mode is true. Records every envelope it would have sent instead of touching the network, so specs can assert on the exact shape without a stubbed HTTP endpoint — Alplus.test_transport.envelopes (issue #14 story 9).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTestTransport

Returns a new instance of TestTransport.



80
81
82
83
# File 'lib/alplus/transport.rb', line 80

def initialize(*)
  @envelopes = []
  @session_envelopes = []
end

Instance Attribute Details

#envelopesObject (readonly)

Returns the value of attribute envelopes.



78
79
80
# File 'lib/alplus/transport.rb', line 78

def envelopes
  @envelopes
end

#session_envelopesObject (readonly)

Returns the value of attribute session_envelopes.



78
79
80
# File 'lib/alplus/transport.rb', line 78

def session_envelopes
  @session_envelopes
end

Instance Method Details

#clearObject



99
100
101
102
# File 'lib/alplus/transport.rb', line 99

def clear
  @envelopes.clear
  @session_envelopes.clear
end

#send_envelope(envelope, kind: :error) ⇒ Object

kind: mirrors Transport#send_envelope (issue #12): a :session envelope records to session_envelopes instead of envelopes, so existing specs asserting on envelopes (error envelopes only) are unaffected by session traffic.



89
90
91
92
93
94
95
96
97
# File 'lib/alplus/transport.rb', line 89

def send_envelope(envelope, kind: :error)
  if kind == :session
    @session_envelopes << envelope
  else
    @envelopes << envelope
  end

  :sent
end