module Onyx::HTTP::Spec

Overview

HTTP testing module. It helps to test your Onyx application. require "onyx/http/spec" before your application, so it spawn a server instead of blocking on Onyx::HTTP.listen.

Defined in:

onyx/http/spec.cr

Class Method Summary

Class Method Detail

def self.client #

def self.client=(client : ::HTTP::Client) #

[View source]
def self.client? #

def self.delete(*args, **nargs) #

Send DELETE request to the Onyx server and return ResponseWrapper.

require "onyx/http/spec"
require "../my_server"

it "returns 200 OK" do
  response = Onyx::HTTP::Spec.get("/foo")
  response.assert(200, "OK")
end

[View source]
def self.get(*args, **nargs) #

Send GET request to the Onyx server and return ResponseWrapper.

require "onyx/http/spec"
require "../my_server"

it "returns 200 OK" do
  response = Onyx::HTTP::Spec.get("/foo")
  response.assert(200, "OK")
end

[View source]
def self.head(*args, **nargs) #

Send HEAD request to the Onyx server and return ResponseWrapper.

require "onyx/http/spec"
require "../my_server"

it "returns 200 OK" do
  response = Onyx::HTTP::Spec.get("/foo")
  response.assert(200, "OK")
end

[View source]
def self.options(*args, **nargs) #

Send OPTIONS request to the Onyx server and return ResponseWrapper.

require "onyx/http/spec"
require "../my_server"

it "returns 200 OK" do
  response = Onyx::HTTP::Spec.get("/foo")
  response.assert(200, "OK")
end

[View source]
def self.patch(*args, **nargs) #

Send PATCH request to the Onyx server and return ResponseWrapper.

require "onyx/http/spec"
require "../my_server"

it "returns 200 OK" do
  response = Onyx::HTTP::Spec.get("/foo")
  response.assert(200, "OK")
end

[View source]
def self.post(*args, **nargs) #

Send POST request to the Onyx server and return ResponseWrapper.

require "onyx/http/spec"
require "../my_server"

it "returns 200 OK" do
  response = Onyx::HTTP::Spec.get("/foo")
  response.assert(200, "OK")
end

[View source]
def self.put(*args, **nargs) #

Send PUT request to the Onyx server and return ResponseWrapper.

require "onyx/http/spec"
require "../my_server"

it "returns 200 OK" do
  response = Onyx::HTTP::Spec.get("/foo")
  response.assert(200, "OK")
end

[View source]
def self.ws(path : String, headers : ::HTTP::Headers = ::HTTP::Headers.new) #

Initialize a new websocket connection to the Onyx server and return WebSocketWrapper.

require "onyx/http/spec"
require "../my_server"

it "echoes" do
  socket = Onyx::HTTP::Spec.ws("/")
  socket.assert_response("ping", "pong")
  # Or
  socket.send("ping")
  socket.assert_response("pong")
end

[View source]