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.



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

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



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

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



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

def close
  @native.close
end

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



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

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

#sse(path) ⇒ Object



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

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

#websocket(path) ⇒ Object



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

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