module Spectator::DSL::ExampleDSL

Overview

Methods that are available inside test code. Basically, inside an StructureDSL#it block.

Included Modules

Defined in:

spectator/dsl/example_dsl.cr

Instance Method Summary

Macro Summary

Instance Method Detail

def fail(reason : String) #

Immediately fail the current test. A reason can be passed, which is reported in the output.


[View source]
def fail #

ditto


[View source]

Macro Detail

macro expect(actual, _source_file = __FILE__, _source_line = __LINE__) #

Starts an expectation. This should be followed up with Spectator::Expectations::ExpectationPartial#to or Spectator::Expectations::ExpectationPartial#to_not. The value passed in will be checked to see if it satisfies the conditions specified.

This method should be used like so:

expect(actual).to eq(expected)

Where the actual value is returned by the system-under-test, and the expected value is what the actual value should be to satisfy the condition.


[View source]
macro expect(_source_file = __FILE__, _source_line = __LINE__, &block) #

Starts an expectation on a block of code. This should be followed up with Spectator::Expectations::ExpectationPartial#to or Spectator::Expectations::ExpectationPartial#to_not. The block passed in, or its return value, will be checked to see if it satisfies the conditions specified.

This method should be used like so:

expect { raise "foo" }.to raise_error

The block of code is passed along for validation to the matchers.

The short, one argument syntax used for passing methods to blocks can be used. So instead of doing this:

expect(subject.size).to eq(5)

The following syntax can be used instead:

expect(&.size).to eq(5)

The method passed will always be evaluated on the subject.


[View source]
macro expects(actual) #

Starts an expectation. This should be followed up with Spectator::Expectations::ExpectationPartial#to or Spectator::Expectations::ExpectationPartial#to_not. The value passed in will be checked to see if it satisfies the conditions specified.

This method is identical to #expect, but is grammatically correct for the one-liner syntax. It can be used like so:

it expects(actual).to eq(expected)

Where the actual value is returned by the system-under-test, and the expected value is what the actual value should be to satisfy the condition.


[View source]
macro expects(&block) #

Starts an expectation on a block of code. This should be followed up with Spectator::Expectations::ExpectationPartial#to or Spectator::Expectations::ExpectationPartial#to_not. The block passed in, or its return value, will be checked to see if it satisfies the conditions specified.

This method is identical to #expect, but is grammatically correct for the one-liner syntax. It can be used like so:

it expects { 5 / 0 }.to raise_error

The block of code is passed along for validation to the matchers.

The short, one argument syntax used for passing methods to blocks can be used. So instead of doing this:

it expects(subject.size).to eq(5)

The following syntax can be used instead:

it expects(&.size).to eq(5)

The method passed will always be evaluated on the subject.


[View source]
macro is(expected) #

Short-hand form of #is_expected that can be used for one-liner syntax. For instance:

it "is 42" do
  expect(subject).to eq(42)
end

Can be shortened to:

it is(42)

These three are functionally equivalent:

expect(subject).to eq("foo")
is_expected.to eq("foo")
is("foo")

See also: #is_not


[View source]
macro is_expected #

Short-hand for expecting something of the subject. These two are functionally equivalent:

expect(subject).to eq("foo")
is_expected.to eq("foo")

[View source]
macro is_not(expected) #

Short-hand, negated form of #is_expected that can be used for one-liner syntax. For instance:

it "is not 42" do
  expect(subject).to_not eq(42)
end

Can be shortened to:

it is_not(42)

These three are functionally equivalent:

expect(subject).to_not eq("foo")
is_expected.to_not eq("foo")
is_not("foo")

See also: #is


[View source]