module Amber::Testing::RequestHelpers

Overview

Provides HTTP request helper methods for use in specs. Include this module in your spec context to make requests against the Amber application without starting a real server.

Requests are routed through the Amber pipeline programmatically, using the routes and pipes configured on Amber::Server.

describe "MyController" do
  include Amber::Testing::RequestHelpers

  it "returns a list of items" do
    response = get("/items")
    response.status_code.should eq(200)
  end
end

Defined in:

amber/testing/request_helpers.cr

Instance Method Summary

Instance Method Detail

def delete(path : String, headers : HTTP::Headers | Nil = nil) : TestResponse #

Send a DELETE request to the given path.


[View source]
def get(path : String, headers : HTTP::Headers | Nil = nil) : TestResponse #

Send a GET request to the given path.


[View source]
def head(path : String, headers : HTTP::Headers | Nil = nil) : TestResponse #

Send a HEAD request to the given path.


[View source]
def patch(path : String, body : String | Nil = nil, headers : HTTP::Headers | Nil = nil) : TestResponse #

Send a PATCH request to the given path with an optional body.


[View source]
def patch_json(path : String, body) : TestResponse #

Send a PATCH request with a JSON body. Automatically sets the Content-Type header to application/json.


[View source]
def post(path : String, body : String | Nil = nil, headers : HTTP::Headers | Nil = nil) : TestResponse #

Send a POST request to the given path with an optional body.


[View source]
def post_json(path : String, body) : TestResponse #

Send a POST request with a JSON body. Automatically sets the Content-Type header to application/json.


[View source]
def put(path : String, body : String | Nil = nil, headers : HTTP::Headers | Nil = nil) : TestResponse #

Send a PUT request to the given path with an optional body.


[View source]
def put_json(path : String, body) : TestResponse #

Send a PUT request with a JSON body. Automatically sets the Content-Type header to application/json.


[View source]