Class: Tina4::TestClient

Inherits:
Object
  • Object
show all
Defined in:
lib/tina4/test_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, root_dir: nil) ⇒ TestClient

app — the Rack app every request is dispatched through. Defaults to the process-wide Tina4::RackApp (RackApp.current): inside a running server that IS the app serving traffic, so an in-process test request and a live request go through the same object. With no app yet (a bare spec process) one is built lazily, rooted at root_dir / Tina4.root_dir / Dir.pwd.

Mirrors Node's new TestClient(router?) optional-collaborator constructor.



90
91
92
93
# File 'lib/tina4/test_client.rb', line 90

def initialize(app = nil, root_dir: nil)
  @app = app
  @root_dir = root_dir
end

Instance Method Details

#appObject



95
96
97
98
# File 'lib/tina4/test_client.rb', line 95

def app
  @app ||= Tina4::RackApp.current ||
           Tina4::RackApp.new(root_dir: @root_dir || Tina4.root_dir || Dir.pwd)
end

#delete(path, headers: nil) ⇒ Object

Send a DELETE request.



121
122
123
# File 'lib/tina4/test_client.rb', line 121

def delete(path, headers: nil)
  request("DELETE", path, headers: headers)
end

#get(path, headers: nil) ⇒ Object

Send a GET request.



101
102
103
# File 'lib/tina4/test_client.rb', line 101

def get(path, headers: nil)
  request("GET", path, headers: headers)
end

#patch(path, json: nil, body: nil, headers: nil) ⇒ Object

Send a PATCH request.



116
117
118
# File 'lib/tina4/test_client.rb', line 116

def patch(path, json: nil, body: nil, headers: nil)
  request("PATCH", path, json: json, body: body, headers: headers)
end

#post(path, json: nil, body: nil, headers: nil) ⇒ Object

Send a POST request.



106
107
108
# File 'lib/tina4/test_client.rb', line 106

def post(path, json: nil, body: nil, headers: nil)
  request("POST", path, json: json, body: body, headers: headers)
end

#put(path, json: nil, body: nil, headers: nil) ⇒ Object

Send a PUT request.



111
112
113
# File 'lib/tina4/test_client.rb', line 111

def put(path, json: nil, body: nil, headers: nil)
  request("PUT", path, json: json, body: body, headers: headers)
end