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.crInstance Method Summary
-
#fail(reason : String)
Immediately fail the current test.
-
#fail
ditto
Macro Summary
-
expect(actual, _source_file = __FILE__, _source_line = __LINE__)
Starts an expectation.
-
expect(_source_file = __FILE__, _source_line = __LINE__, &block)
Starts an expectation on a block of code.
-
expects(actual)
Starts an expectation.
-
expects(&block)
Starts an expectation on a block of code.
-
is(expected)
Short-hand form of
#is_expected
that can be used for one-liner syntax. -
is_expected
Short-hand for expecting something of the subject.
-
is_not(expected)
Short-hand, negated form of
#is_expected
that can be used for one-liner syntax.
Instance Method Detail
Immediately fail the current test. A reason can be passed, which is reported in the output.
Macro Detail
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.
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.
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.
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.
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
Short-hand for expecting something of the subject. These two are functionally equivalent:
expect(subject).to eq("foo")
is_expected.to eq("foo")
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