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

Instance Method Details

#delete(path, params = {}, env = {}) ⇒ Object

Public: Issues a DELETE request for the given path with the given params and Rack environment.

Examples

app = Tynn::Test.new
app.delete("/users/1")


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

Public: Issues a GET request for the given path with the given params and Rack environment.

Examples

app = Tynn::Test.new
app.get("/search", name: "alice")


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

Public: Issues a HEAD request for the given path with the given params and Rack environment.

Examples

app = Tynn::Test.new
app.head("/users/1")


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

Public: Issues a OPTIONS request for the given path with the given params and Rack environment.

Examples

app = Tynn::Test.new
app.options("/users")


187
188
189
# File 'lib/tynn/test.rb', line 187

def options(path, params = {}, env = {})
  request(path, env.merge(method: "OPTIONS".freeze, params: params))
end

#patch(path, params = {}, env = {}) ⇒ Object

Public: Issues a PATCH request for the given path with the given params and Rack environment.

Examples

app = Tynn::Test.new
app.patch("/users/1", username: "alice")


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

Public: Issues a POST request for the given path with the given params and Rack environment.

Examples

app = Tynn::Test.new
app.post("/signup", username: "alice", password: "secret")


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

Public: Issues a PUT request for the given path with the given params and Rack environment.

Examples

app = Tynn::Test.new
app.put("/users/1", username: "bob", name: "Bob")


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

#reqObject

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

#resObject

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