Module: Tynn::Test::InstanceMethods
- Included in:
- Tynn::Test
- Defined in:
- lib/tynn/test.rb
Overview
Internal: This module provides the Tynn::Test API methods. If you don’t like the stand-alone version, you can integrate this module to your preferred testing environment.
The following example uses Minitest:
class HomeTest < Minitest::Test
include Tynn::Test::InstanceMethods
def app
return Tynn
end
def test_home
get("/")
assert_equal 200, res.status
end
end
Instance Method Summary collapse
-
#delete(path, params = {}, env = {}) ⇒ Object
Public: Issues a DELETE request for the given
path
with the givenparams
and Rack environment. -
#get(path, params = {}, env = {}) ⇒ Object
Public: Issues a GET request for the given
path
with the givenparams
and Rack environment. -
#head(path, params = {}, env = {}) ⇒ Object
Public: Issues a HEAD request for the given
path
with the givenparams
and Rack environment. -
#options(path, params = {}, env = {}) ⇒ Object
Public: Issues a OPTIONS request for the given
path
with the givenparams
and Rack environment. -
#patch(path, params = {}, env = {}) ⇒ Object
Public: Issues a PATCH request for the given
path
with the givenparams
and Rack environment. -
#post(path, params = {}, env = {}) ⇒ Object
Public: Issues a POST request for the given
path
with the givenparams
and Rack environment. -
#put(path, params = {}, env = {}) ⇒ Object
Public: Issues a PUT request for the given
path
with the givenparams
and Rack environment. -
#req ⇒ Object
Public: Returns the current request object or
nil
if no requests have been issued yet. -
#res ⇒ Object
Public: Returns the current response object or
nil
if no requests have been issued yet.
Instance Method Details
#delete(path, params = {}, env = {}) ⇒ Object
163 164 165 |
# File 'lib/tynn/test.rb', line 163 def delete(path, params = {}, env = {}) request(path, env.merge(method: "DELETE".freeze, params: params)) end |
#get(path, params = {}, env = {}) ⇒ Object
115 116 117 |
# File 'lib/tynn/test.rb', line 115 def get(path, params = {}, env = {}) request(path, env.merge(method: Rack::GET, params: params)) end |
#head(path, params = {}, env = {}) ⇒ Object
175 176 177 |
# File 'lib/tynn/test.rb', line 175 def head(path, params = {}, env = {}) request(path, env.merge(method: Rack::HEAD, params: params)) end |
#options(path, params = {}, env = {}) ⇒ Object
187 188 189 |
# File 'lib/tynn/test.rb', line 187 def (path, params = {}, env = {}) request(path, env.merge(method: "OPTIONS".freeze, params: params)) end |
#patch(path, params = {}, env = {}) ⇒ Object
151 152 153 |
# File 'lib/tynn/test.rb', line 151 def patch(path, params = {}, env = {}) request(path, env.merge(method: "PATCH".freeze, params: params)) end |
#post(path, params = {}, env = {}) ⇒ Object
127 128 129 |
# File 'lib/tynn/test.rb', line 127 def post(path, params = {}, env = {}) request(path, env.merge(method: "POST".freeze, params: params)) end |
#put(path, params = {}, env = {}) ⇒ Object
139 140 141 |
# File 'lib/tynn/test.rb', line 139 def put(path, params = {}, env = {}) request(path, env.merge(method: "PUT".freeze, params: params)) end |
#req ⇒ Object
Public: Returns the current request object or nil
if no requests have been issued yet.
Examples
app = Tynn::Test.new
app.get("/", {}, { "HTTP_USER_AGENT" => "Tynn::Test" })
app.req.get?
# => true
app.req.env["HTTP_USER_AGENT"]
# => "Tynn::Test"
The returned object is an instance of Rack::Request.
82 83 84 |
# File 'lib/tynn/test.rb', line 82 def req @__req end |
#res ⇒ Object
Public: Returns the current response object or nil
if no requests have been issued yet.
Examples
app = Tynn::Test.new
app.get("/", name: "alice")
app.res.status
# => 200
app.res.body
# => "Hello alice!"
The returned object is an instance of Rack::MockResponse
103 104 105 |
# File 'lib/tynn/test.rb', line 103 def res @__res end |