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.



34
35
36
# File 'lib/spikard/testing.rb', line 34

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



39
40
41
42
43
44
45
# File 'lib/spikard/testing.rb', line 39

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



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

def close
  @native.close
end

#request(method, path, **options) ⇒ Object



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

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

#sse(path) ⇒ Object



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

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

#websocket(path) ⇒ Object



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

def websocket(path)
  native_ws = @native.websocket(path)
  WebSocketTestConnection.new(native_ws)
end