module Amber::Testing::ControllerHelpers

Overview

Provides helpers for testing individual controllers in isolation. Include this module in spec contexts where you want to build controller instances and make assertions about their responses.

include Amber::Testing::ControllerHelpers

describe MyController do
  it "returns the expected content" do
    controller = build_controller_context(MyController, :index)
    controller.index.should eq("expected content")
  end
end

Defined in:

amber/testing/controller_helpers.cr

Macro Summary

Instance Method Summary

Macro Detail

macro build_controller(controller_class, action = :index, method = "GET", path = "/") #

Build a controller instance with a test context. This is a macro because the controller class must be known at compile time.

controller = build_controller(MyController, "GET", "/items")
controller.index.should eq("items list")

[View source]

Instance Method Detail

def assert_controller_content_type(controller : Amber::Controller::Base, type : String) #

Assert that the given controller's response has the expected Content-Type.


[View source]
def assert_controller_redirect_to(controller : Amber::Controller::Base, path : String) #

Assert that the given controller's response is a redirect to the expected path.


[View source]
def assert_controller_response(controller : Amber::Controller::Base, status : Int32) #

Assert that the given controller's response has the expected status code.


[View source]
def build_test_context(method : String = "GET", path : String = "/", headers : HTTP::Headers = HTTP::Headers.new, params : Hash(String, String) = {} of String => String) : HTTP::Server::Context #

Build a test context suitable for creating a controller. Returns an HTTP::Server::Context configured with the given method, path, headers, and query parameters.


[View source]