class Cossack::TestConnection

Overview

A connection, that is supposed to be used in tests in order to stub HTTP requests.

# Create and stub connection
connection = Cossack::TestConnection.new
connection.stub_get("/hello", {200, "World!"})

Create a client and swap the connection
client = Cossack::Client.new("http://example.org")
client.connection = connection

# Just use client
response = client.get("/hello")
response.status # => 200
response.body   # => "World!"

Defined in:

cossack/connection/test_connection.cr
cossack/connection/test_connection/request_matcher.cr
cossack/connection/test_connection/stub.cr

Constructors

Instance Method Summary

Instance methods inherited from class Cossack::Connection

call(request : Request) : Response call

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def call(request : Request) : Response #

[View source]
def stub_delete(url : String, headers : Hash(String, String), response : Tuple(Int32, String)) #

[View source]
def stub_delete(url : String, headers : Hash(String, String), response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_delete(url : String, response : Tuple(Int32, String)) #

[View source]
def stub_delete(url : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_get(url : String, headers : Hash(String, String), response : Tuple(Int32, String)) #

[View source]
def stub_get(url : String, headers : Hash(String, String), response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_get(url : String, response : Tuple(Int32, String)) #

[View source]
def stub_get(url : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_head(url : String, headers : Hash(String, String), response : Tuple(Int32, String)) #

[View source]
def stub_head(url : String, headers : Hash(String, String), response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_head(url : String, response : Tuple(Int32, String)) #

[View source]
def stub_head(url : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_options(url : String, headers : Hash(String, String), response : Tuple(Int32, String)) #

[View source]
def stub_options(url : String, headers : Hash(String, String), response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_options(url : String, response : Tuple(Int32, String)) #

[View source]
def stub_options(url : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_patch(url : String, headers : Hash(String, String), body : String, response : Tuple(Int32, String)) #

[View source]
def stub_patch(url : String, headers : Hash(String, String), body : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_patch(url : String, headers : Hash(String, String), response : Tuple(Int32, String)) #

[View source]
def stub_patch(url : String, headers : Hash(String, String), response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_patch(url : String, body : String, response : Tuple(Int32, String)) #

[View source]
def stub_patch(url : String, body : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_patch(url : String, response : Tuple(Int32, String)) #

[View source]
def stub_patch(url : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_post(url : String, headers : Hash(String, String), body : String, response : Tuple(Int32, String)) #

[View source]
def stub_post(url : String, headers : Hash(String, String), body : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_post(url : String, headers : Hash(String, String), response : Tuple(Int32, String)) #

[View source]
def stub_post(url : String, headers : Hash(String, String), response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_post(url : String, body : String, response : Tuple(Int32, String)) #

[View source]
def stub_post(url : String, body : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_post(url : String, response : Tuple(Int32, String)) #

[View source]
def stub_post(url : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_put(url : String, headers : Hash(String, String), body : String, response : Tuple(Int32, String)) #

[View source]
def stub_put(url : String, headers : Hash(String, String), body : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_put(url : String, headers : Hash(String, String), response : Tuple(Int32, String)) #

[View source]
def stub_put(url : String, headers : Hash(String, String), response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_put(url : String, body : String, response : Tuple(Int32, String)) #

[View source]
def stub_put(url : String, body : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]
def stub_put(url : String, response : Tuple(Int32, String)) #

[View source]
def stub_put(url : String, response : Tuple(Int32, Hash(String, String), String)) #

[View source]