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.



47
48
49
# File 'lib/spikard/testing.rb', line 47

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



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

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



78
79
80
# File 'lib/spikard/testing.rb', line 78

def close
  @native.close
end

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



60
61
62
63
64
# File 'lib/spikard/testing.rb', line 60

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



73
74
75
76
# File 'lib/spikard/testing.rb', line 73

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

#websocket(path) ⇒ Object



66
67
68
69
70
71
# File 'lib/spikard/testing.rb', line 66

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