mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add docs for example and matcher DSL
This commit is contained in:
parent
2f525d49ef
commit
f6d6c859e6
2 changed files with 35 additions and 4 deletions
|
@ -1,21 +1,43 @@
|
||||||
require "./matcher_dsl"
|
require "./matcher_dsl"
|
||||||
|
|
||||||
module Spectator::DSL
|
module Spectator::DSL
|
||||||
|
# Methods that are available inside test code (an `it` block).
|
||||||
module ExampleDSL
|
module ExampleDSL
|
||||||
include MatcherDSL
|
include MatcherDSL
|
||||||
|
|
||||||
macro is_expected
|
# Starts an expectation.
|
||||||
expect(subject)
|
# This should be followed up with `to` or `to_not`.
|
||||||
end
|
# 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.
|
||||||
macro expect(actual)
|
macro expect(actual)
|
||||||
::Spectator::Expectations::ValueExpectationPartial.new({{actual.stringify}}, {{actual}})
|
::Spectator::Expectations::ValueExpectationPartial.new({{actual.stringify}}, {{actual}})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Short-hand for expecting something of the subject.
|
||||||
|
# These two are functionally equivalent:
|
||||||
|
# ```
|
||||||
|
# expect(subject).to eq("foo")
|
||||||
|
# is_expected.to eq("foo")
|
||||||
|
# ```
|
||||||
|
macro is_expected
|
||||||
|
expect(subject)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Immediately fail the current test.
|
||||||
|
# A reason can be passed,
|
||||||
|
# which is reported in the output.
|
||||||
def fail(reason : String)
|
def fail(reason : String)
|
||||||
raise ExampleFailed.new(reason)
|
raise ExampleFailed.new(reason)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ditto
|
||||||
@[AlwaysInline]
|
@[AlwaysInline]
|
||||||
def fail
|
def fail
|
||||||
fail("Example failed")
|
fail("Example failed")
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
require "../matchers"
|
require "../matchers"
|
||||||
|
|
||||||
module Spectator::DSL
|
module Spectator::DSL
|
||||||
|
# Methods for defining matchers for expectations.
|
||||||
module MatcherDSL
|
module MatcherDSL
|
||||||
|
# Indicates that some value should equal another.
|
||||||
|
# The `==` operator is used for this check.
|
||||||
|
# The value passed to this method is the expected value.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# ```
|
||||||
|
# expect(1 + 2).to eq(3)
|
||||||
|
# ```
|
||||||
macro eq(expected)
|
macro eq(expected)
|
||||||
::Spectator::Matchers::EqualityMatcher.new({{expected.stringify}}, {{expected}})
|
::Spectator::Matchers::EqualityMatcher.new({{expected.stringify}}, {{expected}})
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue