abstract class Object

Overview

Object is the base type of all Crystal objects.

Included Modules

Defined in:

spectator/should.cr

Instance Method Summary

Instance Method Detail

def should(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U #

Asserts that some criteria defined by the matcher is satisfied. Allows a custom message to be used. Returns the expected value cast as the expected type, if the matcher is satisfied.


[View source]
def should(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) #

Extension method to create an expectation for an object. This is part of the spec DSL and mimics Crystal Spec's default should-syntax. A matcher should immediately follow this method, or be the only argument to it. Example usage:

it "equals the expected value" do
  subject.should eq(42)
end

An optional message can be used in case the expectation fails. It can be a string or proc returning a string.

subject.should_not be_nil, "Shouldn't be nil"

NOTE By default, the should-syntax is disabled. The expect-syntax is preferred, since it doesn't monkey-patch all objects. To enable should-syntax, add the following to your spec_helper.cr file:

require "spectator/should"

[View source]
def should_eventually(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) #

Works the same as #should except that the condition check is postponed. The expectation is checked after the example finishes and all hooks have run.


[View source]
def should_never(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) #

Works the same as #should_not except that the condition check is postponed. The expectation is checked after the example finishes and all hooks have run.


[View source]
def should_not(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U #

Asserts that some criteria defined by the matcher is not satisfied. Allows a custom message to be used. Returns the expected value cast without the unexpected type, if the matcher is satisfied.


[View source]
def should_not(matcher : Spectator::Matchers::NilMatcher, message = nil, *, _file = __FILE__, _line = __LINE__) #

Asserts that some criteria defined by the matcher is not satisfied. Allows a custom message to be used. Returns the expected value cast as a non-nillable type, if the matcher is satisfied.


[View source]
def should_not(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) #

Works the same as #should except the condition is inverted. When #should succeeds, this method will fail, and vice-versa.


[View source]