definition

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Definition

type Definition struct {
	// contains filtered or unexported fields
}

Definition represents a parsed step definition, typically located in step_definition folder underneath features folder.

func NewDefinition

func NewDefinition(in io.Reader) Definition

NewDefinition reads and parse "in" assuming that it contains content from a step definition file. Lines defining package names are omitted from resulting Definition instance.

Example
package main

import (
	"bytes"
	"fmt"

	"gomate.io/gomate/compiler/definition"
)

func main() {

	buffer := bytes.NewBufferString(`
package step_definitions

Given("^I'm successfully logged in as an admin in users pane$", func(args Args) error {
	_ = ioutil.Discard
	return Pending("Not implemented")
})
And("^I fill in a new developer named hacker with password changeme$", func(args Args) error {
	_ = strings.Join([]string{}, "")
	return Pending("Not implemented")
})

import "strings"

	`)

	def := definition.NewDefinition(buffer)

	fmt.Println(def.Code())
	
Output:

func (Definition) Code

func (definition Definition) Code() string

Code method generates source code based on a step definition. The step definition are located into a go function named setup, this function sets up all definition just before the parsement of the feature file that has been supplied as first argument on commandline. Second argument must be text string "true" or "false", that enables and disables pretty print i.e., print to STDOUT with or without color.

type Definitions

type Definitions struct {
	// contains filtered or unexported fields
}

Definitions has been composed by multiple Definion instances, but does also contain logic to decide what and where to execute, plus rules how to clean up binary result.

func NewDefinitions

func NewDefinitions(defs []io.Reader, forensic bool) Definitions

NewDefinitions reads and parse "defs" assuming that each element contains content from a step definition file. Lines defining package names are omitted from resulting Definition instance.

NOTE: It's callers responsibility to call Remove method before Definitions instance are garbage collected.

func (Definitions) Code

func (definitions Definitions) Code() string

Code method generates source code based on step definitions. The composited step definitions are located into a go function named setup, this function sets up all definition just before the parsement of the feature file that has been supplied as first argument on commandline. Second argument must be text string "true" or "false", that enables and disables pretty print i.e., print to STDOUT with or without color.

func (Definitions) Remove

func (definitions Definitions) Remove()

Remove will remove temporary file containing the generated step definition After this method has been called, it's no longer possible to execute Run method.

func (Definitions) Run

func (definitions Definitions) Run(features io.Reader, pprint bool)

Run takes a DSL written feature from io.Reader and supply the data into precompiled behaviour code. After execution of the binary, the result are written to STDOUT. Method respects global.PPrint to enable/disable pretty print i.e., colors enabled.

Example
package main

import (
	"bytes"
	"io"
	"log/syslog"

	"gomate.io/gomate/compiler/definition"
	"gomate.io/gomate/logging"
)

func main() {

	definitions := definition.NewDefinitions([]io.Reader{
		bytes.NewBufferString(`
package step_definitions

Given("^I'm successfully logged in as an admin in users pane$", func(args Args) error {
	_ = ioutil.Discard
	return Pending("Not implemented")
})
And("^I fill in a new developer named hacker with password changeme$", func(args Args) error {
	_ = strings.Join([]string{}, "")
	return Pending("Not implemented")
})

import "strings"

	`),
	}, false)

	features := bytes.NewBufferString(`
Feature: Manage users
    Administrators are able to manage all users.
    It's possible to add and remove users, but also
    change user kind, password and username.

    Following user kinds are supported by default
    setup:

    * Administrators:
        Setup new users and configures accessibility
        (Users and network interfaces)
    * Developers:
        Are able to setup new projects containing
        build and test configuration.
    * Applications:
        Rest and API systems, for instance external webpages.
    * Others:
        This category contains users with limited access.
        Project managers and field engineers are canonical users.
        Typical user scenario: tag release, download doployable
        build.

  Scenario: Create a new developer
    Given I'm successfully logged in as an admin in users pane
    And I fill in a new developer named hacker with password changeme
    When I press the create button
    Then only one user-record with name hacker should exist
    And user hacker should have password changeme
`)
	logging.ReconfigureLogger(logging.Settings{Priority: syslog.LOG_INFO})
	definitions.Run(features, false)

}
Output:

Feature: Manage users

  Scenario: Create a new developer

    Given I'm successfully logged in as an admin in users pane

    And I fill in a new developer named hacker with password changeme

    When I press the create button

    Then only one user-record with name hacker should exist

    And user hacker should have password changeme

    1 scenario (0 undefined, 0 failures, 1 pending)
    5 steps (3 undefined, 0 failures, 1 pending, 1 optout)

    You can implement step definition for undefined steps with these snippets:

    And("^user hacker should have password changeme$", func(args Args) error {
        return Pending("Not implemented")
    })

    Then("^only one user-record with name hacker should exist$", func(args Args) error {
        return Pending("Not implemented")
    })

    When("^I press the create button$", func(args Args) error {
        return Pending("Not implemented")
    })

Jump to

Keyboard shortcuts

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