-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
100 lines (73 loc) · 2.49 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
Gourd is a wire protocol implementation for Cucumber.
Gourd allows to write step definitions in go.
You will need to install ruby and Cucumber to use Gourd.
Installing Cucumber on top of ruby is usually as simple as "gem install cucumber".
Visit http://cukes.info/ to learn more about Cucumber.
Usage
In the directory from which you wish to run cucumber create sub-directories "features/step_definitions/".
Add the wire server configuration to "features/step_definitions/gourd.wire":
host: localhost
port: 1847
Put your .feature-files into "features/".
The main of the wire server can be put in any location.
The following example will assume "features/step_definitions/steps.go".
This may work well for smaller projects.
But for easier navigation and readablity,
its own folder with step definitions split across multiple files may be more appropriate.
A minimal main creates a wire server and runs it:
package main
import (
"github.com/raphaelmeyer/gourd"
)
func main() {
cucumber := gourd.NewCucumber(func() interface{} {
return nil
})
cucumber.Run()
}
Run the wire server...
$ go run features/step_definitions/steps.go
...then start cucumber:
$ cucumber
You need at least one feature scenario.
If there is no scenario defined then cucumber will not connect to the wire server and
the server keeps waiting for a connection.
The function passed to NewCucumber is used to create a new context for each scenario.
It will be called before running a scenario and its return value is passed to all steps.
Example
The feature scenario:
Feature: Evaluate an input
Scenario: A single input
Given I enter 7
And I press evaluate
Then the result should be 42
And the wire server with the step definitions:
type my_context struct {
testee Testee
}
func main() {
cucumber := gourd.NewCucumber(func() interface{} {
return &my_context{}
})
cucumber.Given("^I enter (\\d+)$").Do(
func(context interface{}, arguments gourd.Arguments) {
scenario, _ := context.(*my_context)
scenario.testee.Enter(arguments.Int(0))
})
cucumber.When("^I press evaluate$").Do(
func(context interface{}, arguments gourd.Arguments) {
scenario, _ := context.(*my_context)
scenario.testee.Evaluate()
})
cucumber.Then("^the result should be (\\d+)$").Do(
func(context interface{}, arguments gourd.Arguments) {
scenario, _ := context.(*my_context)
if scenario.testee.Result() != arguments.Int(0) {
panic("Wrong result")
}
})
cucumber.Run()
}
*/
package gourd