module Spec::Expectations

Overview

This module defines a number of methods to create expectations, which are automatically included into the top level namespace.

Expectations are used by Spec::ObjectExtensions#should and Spec::ObjectExtensions#should_not.

Defined in:

spec/expectations.cr

Macro Summary

Instance Method Summary

Macro Detail

macro be_a(type) #

Creates an Expectation that passes if actual is of type type (is_a?).


[View source]

Instance Method Detail

def be(value) #

Creates an Expectation that passes if actual and value are identical (.same?).


[View source]
def be #

Returns a factory to create a comparison Expectation that:

  • passes if actual is lesser than value: be < value
  • passes if actual is lesser than or equal value: be <= value
  • passes if actual is greater than value: be > value
  • passes if actual is greater than or equal value: be >= value

[View source]
def be_close(expected, delta) #

Creates an Expectation that passes if actual is within delta of expected.


[View source]
def be_empty #

Creates an Expectation that passes if actual is empty (.empty?).


[View source]
def be_false #

Creates an Expectation that passes if actual is false (== false).


[View source]
def be_falsey #

Creates an Expectation that passes if actual is falsy (nil or false).


[View source]
def be_nil #

Creates an Expectation that passes if actual is nil (== nil).


[View source]
def be_true #

Creates an Expectation that passes if actual is true (== true).


[View source]
def be_truthy #

Creates an Expectation that passes if actual is truthy (neither nil nor false).


[View source]
def contain(expected) #

Creates an Expectation that passes if actual includes expected (.includes?). Works on collections and String.


[View source]
def end_with(expected) #

Creates an Expectation that passes if actual ends with expected (.ends_with?). Works on String.


[View source]
def eq(value) #

Creates an Expectation that passes if actual equals value (==).


[View source]
def expect_raises(klass : T.class, message : String | Regex | Nil = nil, file = __FILE__, line = __LINE__, &) forall T #

[View source]
def match(value) #

Creates an Expectation that passes if actual matches value (=~).


[View source]
def start_with(expected) #

Creates an Expectation that passes if actual starts with expected (.starts_with?). Works on String.


[View source]