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.



57
58
59
60
# File 'lib/tina4/test_client.rb', line 57

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

Instance Method Details

#appObject



62
63
64
65
# File 'lib/tina4/test_client.rb', line 62

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.



88
89
90
# File 'lib/tina4/test_client.rb', line 88

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

#get(path, headers: nil) ⇒ Object

Send a GET request.



68
69
70
# File 'lib/tina4/test_client.rb', line 68

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

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

Send a PATCH request.



83
84
85
# File 'lib/tina4/test_client.rb', line 83

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.



73
74
75
# File 'lib/tina4/test_client.rb', line 73

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.



78
79
80
# File 'lib/tina4/test_client.rb', line 78

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