Class: Spikard::Testing::TestClient

Inherits:
Object
  • Object
show all
Defined in:
lib/spikard/testing.rb

Overview

High level wrapper around the native test client.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ TestClient

Returns a new instance of TestClient.



49
50
51
# File 'lib/spikard/testing.rb', line 49

def initialize(native)
  @native = native
end

Class Method Details

.new(app_or_native, config: nil) ⇒ Object

Factory method for creating test client from an app



54
55
56
57
58
59
60
# File 'lib/spikard/testing.rb', line 54

def self.new(app_or_native, config: nil)
  # If passed a native client directly, use it
  return super(app_or_native) if app_or_native.is_a?(Spikard::Native::TestClient)

  # Otherwise, create test client from app
  Spikard::Testing.create_test_client(app_or_native, config: config)
end

Instance Method Details

#closeObject



80
81
82
# File 'lib/spikard/testing.rb', line 80

def close
  @native.close
end

#request(method, path, headers = nil, body = nil, **options) ⇒ Object



62
63
64
65
66
# File 'lib/spikard/testing.rb', line 62

def request(method, path, headers = nil, body = nil, **options)
  payload = build_request_payload(headers, body, options)
  payload = @native.request(method.to_s.upcase, path, payload)
  Response.new(payload)
end

#sse(path) ⇒ Object



75
76
77
78
# File 'lib/spikard/testing.rb', line 75

def sse(path)
  native_sse = @native.sse(path)
  SseStream.new(native_sse)
end

#websocket(path) ⇒ Object



68
69
70
71
72
73
# File 'lib/spikard/testing.rb', line 68

def websocket(path)
  Testing.trace("websocket:start #{path}")
  native_ws = @native.websocket(path)
  Testing.trace("websocket:connected #{path}")
  WebSocketTestConnection.new(native_ws)
end