Class: Tina4::TestClient
- Inherits:
-
Object
- Object
- Tina4::TestClient
- Defined in:
- lib/tina4/test_client.rb
Instance Method Summary collapse
- #app ⇒ Object
-
#delete(path, headers: nil) ⇒ Object
Send a DELETE request.
-
#get(path, headers: nil) ⇒ Object
Send a GET request.
-
#initialize(app = nil, root_dir: nil) ⇒ TestClient
constructor
app— the Rack app every request is dispatched through. -
#patch(path, json: nil, body: nil, headers: nil) ⇒ Object
Send a PATCH request.
-
#post(path, json: nil, body: nil, headers: nil) ⇒ Object
Send a POST request.
-
#put(path, json: nil, body: nil, headers: nil) ⇒ Object
Send a PUT request.
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
#app ⇒ Object
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 |