module Amber::Testing::Assertions

Overview

Custom assertion helpers for use in Crystal specs. These complement the built-in should matchers with domain-specific assertions for HTTP responses.

describe "API" do
  include Amber::Testing::Assertions
  include Amber::Testing::RequestHelpers

  it "returns success" do
    response = get("/api/status")
    assert_response_status(response, 200)
    assert_response_success(response)
    assert_json_content_type(response)
  end
end

Defined in:

amber/testing/assertions.cr

Instance Method Summary

Instance Method Detail

def assert_body_contains(response : TestResponse, text : String) #

Assert that the response body contains the given string.


[View source]
def assert_content_type(response : TestResponse, type : String) #

Assert that the response Content-Type contains the expected type string.


[View source]
def assert_header(response : TestResponse, key : String, value : String) #

Assert that a specific response header is present with the expected value.


[View source]
def assert_html_content_type(response : TestResponse) #

Assert that the response Content-Type is HTML.


[View source]
def assert_json_body(response : TestResponse) : JSON::Any #

Assert that the response body is valid JSON and return the parsed result.


[View source]
def assert_json_content_type(response : TestResponse) #

Assert that the response Content-Type is JSON.


[View source]
def assert_redirect_to(response : TestResponse, path : String) #

Assert that a TestResponse is a redirect to the given URL.


[View source]
def assert_response_client_error(response : TestResponse) #

Assert that a TestResponse is a client error (4xx).


[View source]
def assert_response_not_found(response : TestResponse) #

Assert that a TestResponse is a not found error (404).


[View source]
def assert_response_redirect(response : TestResponse) #

Assert that a TestResponse is a redirect (3xx).


[View source]
def assert_response_server_error(response : TestResponse) #

Assert that a TestResponse is a server error (5xx).


[View source]
def assert_response_status(response : TestResponse, status : Int32) #

Assert that a TestResponse has the given status code.


[View source]
def assert_response_success(response : TestResponse) #

Assert that a TestResponse is successful (2xx).


[View source]