class Spectator::Example

Overview

Standard example that runs a test case.

Defined in:

spectator/example.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Spectator::Node

display_name display_name, finished? : Bool finished?, inspect(io : IO) : Nil inspect, location : Location location, location? : Location | Nil location?, metadata : Metadata metadata, name : Label name, name? : Label | Nil name?, pending? pending?, pending_reason pending_reason, tags tags, to_s(io : IO) : Nil to_s

Constructor methods inherited from class Spectator::Node

new(name : Label = nil, location : Location | Nil = nil, metadata : Metadata | Nil = nil) new

Instance methods inherited from class Object

should(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
should(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
should
, should_eventually(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_eventually, should_never(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_never, should_not(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
should_not(matcher : Spectator::Matchers::NilMatcher, message = nil, *, _file = __FILE__, _line = __LINE__)
should_not(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
should_not

Constructor Detail

def self.current : Example #

Currently running example.


[View source]
def self.new(context : Context, entrypoint : self -> , name : String | Nil = nil, location : Location | Nil = nil, group : ExampleGroup | Nil = nil, metadata = nil) #

Creates the example. An instance to run the test code in is given by context. The entrypoint defines the test code (typically inside context). The name describes the purpose of the example. The location tracks where the example exists in source code. The example will be assigned to group if it is provided. A set of metadata can be used for filtering and modifying example behavior. Note: The metadata will not be merged with the parent metadata.


[View source]
def self.new(context : Context, entrypoint : self -> , name_proc : Example -> String, location : Location | Nil = nil, group : ExampleGroup | Nil = nil, metadata = nil) #

Creates the example. An instance to run the test code in is given by context. The entrypoint defines the test code (typically inside context). The name describes the purpose of the example. It can be a proc to be evaluated in the context of the example. The location tracks where the example exists in source code. The example will be assigned to group if it is provided. A set of metadata can be used for filtering and modifying example behavior. Note: The metadata will not be merged with the parent metadata.


[View source]
def self.new(name : String | Nil = nil, location : Location | Nil = nil, group : ExampleGroup | Nil = nil, metadata = nil, &block : self -> ) #

Creates a dynamic example. A block provided to this method will be called as-if it were the test code for the example. The block will be given this example instance as an argument. The name describes the purpose of the example. It can be a Symbol to describe a type. The location tracks where the example exists in source code. The example will be assigned to group if it is provided. A set of metadata can be used for filtering and modifying example behavior. Note: The metadata will not be merged with the parent metadata.


[View source]

Class Method Detail

def self.current? : Example | Nil #

Currently running example.


[View source]
def self.pending(name : String | Nil = nil, location : Location | Nil = nil, group : ExampleGroup | Nil = nil, metadata = nil, reason = nil) #

Creates a pending example. The name describes the purpose of the example. It can be a Symbol to describe a type. The location tracks where the example exists in source code. The example will be assigned to group if it is provided. A set of metadata can be used for filtering and modifying example behavior. Note: The metadata will not be merged with the parent metadata.


[View source]

Instance Method Detail

def ascend(&) #

Yields this example and all parent groups.


[View source]
def finished? : Bool #

Indicates whether the example already ran.


[View source]
def group : ExampleGroup #

Group the node belongs to.


[View source]
def group? : ExampleGroup | Nil #

Group the node belongs to.


[View source]
def inspect(io : IO) : Nil #

Exposes information about the example useful for debugging.


[View source]
def procsy #

Creates a procsy from this example that runs the example.


[View source]
def procsy(&block : -> ) #

Creates a procsy from this example and the provided block.


[View source]
def result : Result #

Result of the last time the example ran. Is pending if the example hasn't run.


[View source]
def run : Result #

Executes the test case. Returns the result of the execution. The result will also be stored in #result.


[View source]
def to_json(json : JSON::Builder) #

Creates the JSON representation of the example, which is just its name.


[View source]
def to_s(io : IO) : Nil #

Constructs the full name or description of the example. This prepends names of groups this example is part of.


[View source]