gospel

package module
v0.0.0-...-32d2759 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 8 Imported by: 0

README

Gospel

[!NOTE] This project is archived because I no longer actively use it, and there seems to be no recent activity from other users either. If you are still using it and would like to take over maintenance, please contact me somewhere.

BDD-style testing library for Golang.

Install

go get github.com/r7kamura/gospel

Usage

package main

import (
	. "github.com/r7kamura/gospel"
	"testing"
)

func TestDescribe(t *testing.T) {
	Describe(t, "Expectation#To", func() {
		Context("with Equal", func() {
			It("evaluates actual == expected", func() {
				Expect(1).To(Equal, 1)
			})
		})

		Context("with NotEqual", func() {
			Before(func() {
				// Called before each examples in this Context.
			})

			After(func() {
				// Called after each examples in this Context.
			})

			It("evaluates actual != expected", func() {
				Expect(1).To(NotEqual, 2)
			})
		})

		Context("with Exist", func() {
			It("evaluates actual != nil", func() {
				Expect(1).To(Exist)
			})
		})

		Context("with NotExist", func() {
			It("evaluates actual == nil", func() {
				Expect(nil).To(NotExist)
			})
		})
	})
}
$ go test

$ go test -v

Documentation

Index

Constants

This section is empty.

Variables

Functions

func After

func After(filter func())

func Before

func Before(filter func())

func Context

func Context(description string, callback func())

func Describe

func Describe(t *testing.T, description string, callback func())

func Equal

func Equal(values ...interface{}) (failureMessage string)

Checks if actual == expected.

func Exist

func Exist(values ...interface{}) (failureMessage string)

Checks if actual != nil.

func It

func It(message string, evaluator func())

func NotEqual

func NotEqual(values ...interface{}) (failureMessage string)

Checks if actual != expected.

func NotExist

func NotExist(values ...interface{}) (failureMessage string)

Checks if actual == nil.

Types

type DocumentFormatter

type DocumentFormatter struct{}

func (*DocumentFormatter) Failed

func (formatter *DocumentFormatter) Failed(example *Example, message string)

func (*DocumentFormatter) Started

func (formatter *DocumentFormatter) Started(example *Example)

func (*DocumentFormatter) Succeeded

func (formatter *DocumentFormatter) Succeeded(example *Example)

type DotFormatter

type DotFormatter struct{}

func (*DotFormatter) Failed

func (formatter *DotFormatter) Failed(example *Example, message string)

func (*DotFormatter) Started

func (formatter *DotFormatter) Started(example *Example)

Does nothing.

func (*DotFormatter) Succeeded

func (formatter *DotFormatter) Succeeded(example *Example)

type Example

type Example struct {
	*ExampleGroup
	Message    string
	Evaluator  func()
	HasFailure bool
	Formatter
}

func It() creates a new Example object.

func (*Example) Descriptions

func (example *Example) Descriptions() []string

Returns its ExamplesGroups' descriptions as an array of string.

func (*Example) Evaluate

func (example *Example) Evaluate()

Invokes its Evaluator function.

func (*Example) Failed

func (example *Example) Failed(message string)

Called when any of expectations failed.

func (*Example) FullDescription

func (example *Example) FullDescription() string

Returns its entire descriptions + message as a string.

func (*Example) Run

func (example *Example) Run()

func It() calls this function to run the newly created example.

func (*Example) Started

func (example *Example) Started()

Called when started.

func (*Example) Succeeded

func (example *Example) Succeeded()

Called when all of expectations passed.

type ExampleGroup

type ExampleGroup struct {
	*testing.T
	Parent        *ExampleGroup
	Description   string
	Result        string
	BeforeFilters []func()
	AfterFilters  []func()
}

Describe or Context creates this object.

func (*ExampleGroup) Ancestors

func (group *ExampleGroup) Ancestors() []*ExampleGroup

Returns its ancestor ExampleGroups in ascending order according to distance.

func (*ExampleGroup) PrintResult

func (group *ExampleGroup) PrintResult()

In non-verbose mode, we print test results for each Describe.

func (*ExampleGroup) ReverseAncestors

func (group *ExampleGroup) ReverseAncestors() []*ExampleGroup

Returns its ancestor ExampleGroups in descending order according to distance.

func (*ExampleGroup) ReverseAncestorsAndSelf

func (group *ExampleGroup) ReverseAncestorsAndSelf() []*ExampleGroup

Merges its ancestors and itself.

func (*ExampleGroup) Root

func (group *ExampleGroup) Root() *ExampleGroup

Gets root ExampleGroup defined by Describe func.

func (*ExampleGroup) RunAfterFilters

func (group *ExampleGroup) RunAfterFilters()

Runs all AfterFilters defined to its ancestors and itself.

func (*ExampleGroup) RunBeforeFilters

func (group *ExampleGroup) RunBeforeFilters()

Runs all BeforeFilters defined to its ancestors and itself.

type Expectation

type Expectation struct {
	*Example
	Actual interface{}
}

func Expect() creates a new Expectation object.

func Expect

func Expect(actual interface{}) *Expectation

func (*Expectation) To

func (expectation *Expectation) To(matcher Matcher, expected ...interface{})

Checks if a given matcher satisfies actual & optional values.

type Formatter

type Formatter interface {
	Started(*Example)
	Failed(*Example, string)
	Succeeded(*Example)
}

type Matcher

type Matcher func(...interface{}) string

Returns a non-empty failure message if given actual & optional values are not matched.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL