Skip to content

Latest commit

 

History

History
159 lines (113 loc) · 4.1 KB

README.md

File metadata and controls

159 lines (113 loc) · 4.1 KB

Terminal Emulator for cucumber/godog

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

consolesteps provides a new Console for each cucumber/godog Scenario.

Prerequisites

  • Go >= 1.17

Install

go get go.nhat.io/consolesteps

Usage

Initialize a consolesteps.Manager with consolesteps.New() then add it into the ScenarioInitializer. If you wish to add listeners to Manager.NewConsole and Manager.CloseConsole event, use consolesteps.WithStarter and consolesteps.WithCloser option in the constructor.

For example:

package mypackage

import (
    "math/rand"
    "testing"

    expect "github.com/Netflix/go-expect"
    "github.com/cucumber/godog"
    "go.nhat.io/consolesteps"
)

type writer struct {
    console *expect.Console
}

func (w *writer) registerContext(ctx *godog.ScenarioContext) {
    ctx.Step(`write to console:`, func(s *godog.DocString) error {
        _, err := w.console.Write([]byte(s.Content))

        return err
    })
}

func (w *writer) start(_ *godog.Scenario, console *expect.Console) {
    w.console = console
}

func (w *writer) close(_ *godog.Scenario) {
    w.console = nil
}

func TestIntegration(t *testing.T) {
    t.Parallel()

    w := &writer{}
    m := consolesteps.New(t,
        consolesteps.WithStarter(w.start),
        consolesteps.WithCloser(w.close),
    )

    suite := godog.TestSuite{
        Name: "Integration",
        ScenarioInitializer: func(ctx *godog.ScenarioContext) {
            m.RegisterContext(ctx)
        },
        Options: &godog.Options{
            Strict:    true,
            Output:    out,
            Randomize: rand.Int63(),
        },
    }

    // Run the suite.
}

See more: #Examples

Resize

In case you want to resize the terminal (default is 80x100) to avoid text wrapping, for example:

        Then console output is:
        """
        panic: could not build credentials provider option: unsupported credentials prov
        ider
        """

Use consolesteps.WithTermSize(cols, rows) while initiating with consolesteps.New(), for example:

package mypackage

import (
    "testing"

    "go.nhat.io/consolesteps"
)

func TestIntegration(t *testing.T) {
    // ...
    m := consolesteps.New(t, consolesteps.WithTermSize(100, 100))
    // ...
}

Then your step will become:

        Then console output is:
        """
        panic: could not build credentials provider option: unsupported credentials provider
        """

Steps

console output is:

Asserts the output of the console.

For example:

    Scenario: Find all transaction in range with invalid format
        When I run command "transactions -d --format invalid"

        Then console output is:
        """
        panic: unknown output format
        """

Examples

Full suite: https://github.com/nhatthm/consolesteps/tree/master/features

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation

paypal

       or scan this