# README
Jump straight to the docs to learn about Gomega, including a list of all available matchers.
If you have a question, comment, bug report, feature request, etc. please open a GitHub issue.
Ginkgo: a BDD Testing Framework for Golang
Learn more about Ginkgo here
Community Matchers
A collection of community matchers is available on the wiki.
License
Gomega is MIT-Licensed
The ConsistOf
matcher uses goraph which is embedded in the source to simplify distribution. goraph has an MIT license.
# Packages
Package gbytes provides a buffer that supports incrementally detecting input.
package gcustom provides a simple mechanism for creating custom Gomega matchers
*/.
package gleak complements the Gingko/Gomega testing and matchers framework with
matchers for Goroutine leakage detection.
Package gomega/gmeasure provides support for benchmarking and measuring code.
# Functions
And succeeds only if all of the given matchers succeed.
BeADirectory succeeds if a file exists and is a directory.
BeAnExistingFile succeeds if a file exists.
BeARegularFile succeeds if a file exists and is a regular file.
BeAssignableToTypeOf succeeds if actual is assignable to the type of expected.
BeClosed succeeds if actual is a closed channel.
BeComparableTo uses gocmp.Equal from github.com/google/go-cmp (instead of reflect.DeepEqual) to perform a deep comparison.
BeElementOf succeeds if actual is contained in the passed in elements.
BeEmpty succeeds if actual is empty.
BeEquivalentTo is more lax than Equal, allowing equality between different types.
BeFalse succeeds if actual is false
In general, it's better to use `BeFalseBecause(reason)` to provide a more useful error message if a false check fails.
BeFalseBecause succeeds if actual is false and displays the provided reason if it is true.
BeIdenticalTo uses the == operator to compare actual with expected.
BeKeyOf succeeds if actual is contained in the keys of the passed in map.
BeNil succeeds if actual is nil.
BeNumerically performs numerical assertions in a type-agnostic way.
BeSent succeeds if a value can be sent to actual.
BeTemporally compares time.Time's like BeNumerically Actual and expected must be time.Time.
BeTrue succeeds if actual is true
In general, it's better to use `BeTrueBecause(reason)` to provide a more useful error message if a true check fails.
BeTrueBecause succeeds if actual is true and displays the provided reason if it is false fmt.Sprintf is used to render the reason.
BeZero succeeds if actual is the zero value for its type or if actual is nil.
Consistently, like Eventually, enables making assertions on asynchronous behavior.
ConsistentlyWithOffset operates like Consistently but takes an additional initial argument to indicate an offset in the call stack.
ConsistOf succeeds if actual contains precisely the elements passed into the matcher.
ContainElement succeeds if actual contains the passed in element.
ContainElements succeeds if actual contains the passed in elements.
ContainSubstring succeeds if actual is a string or stringer that contains the passed-in substring.
DisableDefaultTimeoutsWhenUsingContext disables the default timeout when a context is provided to `Eventually`.
EnforceDefaultTimeoutsWhenUsingContexts forces `Eventually` to apply a default timeout even when a context is provided.
Equal uses reflect.DeepEqual to compare actual with expected.
Eventually enables making assertions on asynchronous behavior.
EventuallyWithOffset operates like Eventually but takes an additional initial argument to indicate an offset in the call stack.
Expect wraps an actual value allowing assertions to be made on it:
Expect("foo").To(Equal("foo"))
If Expect is passed more than one argument it will pass the *first* argument to the matcher.
ExpectWithOffset wraps an actual value allowing assertions to be made on it:
ExpectWithOffset(1, "foo").To(Equal("foo"))
Unlike `Expect` and `Ω`, `ExpectWithOffset` takes an additional integer argument that is used to modify the call-stack offset when computing line numbers.
HaveCap succeeds if actual has the passed-in capacity.
HaveEach succeeds if actual solely contains elements that match the passed in element.
HaveExactElements succeeds if actual contains elements that precisely match the elemets passed into the matcher.
HaveExistingField succeeds if actual is a struct and the specified field exists.
HaveField succeeds if actual is a struct and the value at the passed in field matches the passed in matcher.
HaveHTTPBody matches if the body matches.
HaveHTTPHeaderWithValue succeeds if the header is found and the value matches.
HaveHTTPStatus succeeds if the Status or StatusCode field of an HTTP response matches.
HaveKey succeeds if actual is a map with the passed in key.
HaveKeyWithValue succeeds if actual is a map with the passed in key and value.
HaveLen succeeds if actual has the passed-in length.
HaveOccurred succeeds if actual is a non-nil error The typical Go error checking pattern looks like:
err := SomethingThatMightFail() Expect(err).ShouldNot(HaveOccurred()).
HavePrefix succeeds if actual is a string or stringer that contains the passed-in string as a prefix.
HaveSuffix succeeds if actual is a string or stringer that contains the passed-in string as a suffix.
HaveValue applies the given matcher to the value of actual, optionally and repeatedly dereferencing pointers or taking the concrete value of interfaces.
InterceptGomegaFailure runs a given callback and returns the first failure message generated by any Gomega assertions within the callback, wrapped in an error.
InterceptGomegaFailures runs a given callback and returns an array of failure messages generated by any Gomega assertions within the callback.
MatchError succeeds if actual is a non-nil error that matches the passed in string, error, function, or matcher.
MatchJSON succeeds if actual is a string or stringer of JSON that matches the expected JSON.
MatchRegexp succeeds if actual is a string or stringer that matches the passed-in regexp.
MatchXML succeeds if actual is a string or stringer of XML that matches the expected XML.
MatchYAML succeeds if actual is a string or stringer of YAML that matches the expected YAML.
NewGomega returns an instance of Gomega wired into the passed-in fail handler.
NewWithT takes a *testing.T and returns a `gomega.WithT` allowing you to use `Expect`, `Eventually`, and `Consistently` along with Gomega's rich ecosystem of matchers in standard `testing` test suits.
Not negates the given matcher; it succeeds if the given matcher fails.
Or succeeds if any of the given matchers succeed.
Panic succeeds if actual is a function that, when invoked, panics.
PanicWith succeeds if actual is a function that, when invoked, panics with a specific value.
Receive succeeds if there is a value to be received on actual.
RegisterFailHandler connects Ginkgo to Gomega.
RegisterFailHandlerWithT is deprecated and will be removed in a future release.
RegisterTestingT connects Gomega to Golang's XUnit style Testing.T tests.
Satisfy matches the actual value against the `predicate` function.
SatisfyAll is an alias for And().
SatisfyAny is an alias for Or().
SetDefaultConsistentlyDuration sets the default duration for Consistently.
SetDefaultConsistentlyPollingInterval sets the default polling interval for Consistently.
SetDefaultEventuallyPollingInterval sets the default polling interval for Eventually.
SetDefaultEventuallyTimeout sets the default timeout duration for Eventually.
Succeed passes if actual is a nil error Succeed is intended to be used with functions that return a single error value.
WithTransform applies the `transform` to the actual value and matches it against `matcher`.
Ω wraps an actual value allowing assertions to be made on it:
Ω("foo").Should(Equal("foo"))
If Ω is passed more than one argument it will pass the *first* argument to the matcher.
# Variables
DefaultGomega supplies the standard package-level implementation.
NewGomegaWithT is deprecated in favor of gomega.NewWithT, which does not stutter.
StopTrying can be used to signal to Eventually and Consistentlythat they should abort and stop trying.
TryAgainAfter(<duration>) allows you to adjust the polling interval for the _next_ iteration of `Eventually` or `Consistently`.
# Type aliases
Assertion is returned by Ω and Expect and compares the actual value to the matcher passed to the Should/ShouldNot and To/ToNot/NotTo methods.
AsyncAssertion is returned by Eventually and Consistently and polls the actual value passed into Eventually against the matcher passed to the Should and ShouldNot methods.
Gomega describes the essential Gomega DSL.
GomegaAssertion is deprecated in favor of Assertion, which does not stutter.
GomegaAsyncAssertion is deprecated in favor of AsyncAssertion, which does not stutter.
GomegaWithT is deprecated in favor of gomega.WithT, which does not stutter.
OmegaMatcher is deprecated in favor of the better-named and better-organized types.GomegaMatcher but sticks around to support existing code that uses it.
PollingSignalError is the error returned by StopTrying() and TryAgainAfter()
*/.
WithT wraps a *testing.T and provides `Expect`, `Eventually`, and `Consistently` methods.