W3cubDocs

/Crystal 0.31

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

Instance Method Summary

  • #be(value)

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

  • #be

    Returns a factory to create a comparison Expectation that:

  • #be_close(expected, delta)

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

  • #be_empty

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

  • #be_false

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

  • #be_falsey

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

  • #be_nil

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

  • #be_true

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

  • #be_truthy

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

  • #contain(expected)

    Creates an Expectation that passes if actual includes expected (.includes?).

  • #end_with(expected)

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

  • #eq(value)

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

  • #expect_raises(klass : T.class, message = nil, file = __FILE__, line = __LINE__, &block) forall T

    Runs the block and passes if it raises an exception of type klass and the error message matches.

  • #match(value)

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

  • #start_with(expected)

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

Macro Summary

  • be_a(type)

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

Instance Method Detail

def be(value)Source

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

def beSource

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

def be_close(expected, delta)Source

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

def be_emptySource

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

def be_falseSource

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

def be_falseySource

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

def be_nilSource

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

def be_trueSource

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

def be_truthySource

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

def contain(expected)Source

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

def end_with(expected)Source

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

def eq(value)Source

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

def expect_raises(klass : T.class, message = nil, file = __FILE__, line = __LINE__, &block) forall TSource

Runs the block and passes if it raises an exception of type klass and the error message matches.

If message is a string, it matches if the exception's error message contains that string. If message is a regular expression, it is used to match the error message.

It returns the rescued exception.

def match(value)Source

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

def start_with(expected)Source

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

Macro Detail

macro be_a(type)Source

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

© 2012–2019 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.31.1/Spec/Expectations.html