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.crMacro Summary
-
build_controller(controller_class, action = :index, method = "GET", path = "/")
Build a controller instance with a test context.
Instance Method Summary
-
#assert_controller_content_type(controller : Amber::Controller::Base, type : String)
Assert that the given controller's response has the expected Content-Type.
-
#assert_controller_redirect_to(controller : Amber::Controller::Base, path : String)
Assert that the given controller's response is a redirect to the expected path.
-
#assert_controller_response(controller : Amber::Controller::Base, status : Int32)
Assert that the given controller's response has the expected status code.
-
#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.
Macro Detail
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")
Instance Method Detail
Assert that the given controller's response has the expected Content-Type.
Assert that the given controller's response is a redirect to the expected path.
Assert that the given controller's response has the expected status code.
Build a test context suitable for creating a controller. Returns an HTTP::Server::Context configured with the given method, path, headers, and query parameters.