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) inspect, location : Location location, location? : Location? location?, metadata : Metadata metadata, name : Label name, name? : Label? name?, pending? pending?, pending_reason pending_reason, tags tags, to_s(io) to_s

Constructor methods inherited from class Spectator::Node

new(name : Label = nil, location : Location? = nil, metadata : Metadata = Metadata.new) new

Instance methods inherited from class Object

should(matcher, message = nil) should, should_eventually(matcher, message = nil) should_eventually, should_never(matcher, message = nil) should_never, should_not(matcher, message = nil) should_not

Constructor Detail

def self.current : Example #

Currently running example.


[View source]
def self.current? : Example? #

Currently running example.


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

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 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]
def self.new(name : String? = nil, location : Location? = nil, group : ExampleGroup? = nil, metadata = Metadata.new, &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.pending(name : String? = nil, location : Location? = nil, group : ExampleGroup? = nil, metadata = Metadata.new, 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? #

Group the node belongs to.


[View source]
def inspect(io) #

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) #

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


[View source]