Skip to content

Commit 4dc98b0

Browse files
committed
closes #96
1 parent 0b4523c commit 4dc98b0

File tree

8 files changed

+39
-5
lines changed

8 files changed

+39
-5
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Change LOG
22

3+
**2017-08-31**
4+
- added **BeforeFeature** and **AfterFeature** hooks.
5+
- failed multistep error is now prepended with a parent step text in order
6+
to determine failed nested step.
7+
- pretty format now removes the step definition location package name in
8+
comment next to step if the step definition matches tested package. If
9+
step definition is imported from other package, full package name will
10+
be printed.
11+
312
**2017-05-04**
413
- added **--strict** option in order to fail suite when there are pending
514
or undefined steps. By default, suite passes and treats pending or

builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
3636
func main() {
3737
status := godog.Run("{{ .Name }}", func (suite *godog.Suite) {
38+
os.Setenv("GODOG_TESTED_PACKAGE", "{{.ImportPath}}")
3839
{{range .Contexts}}
3940
_test.{{ . }}(suite)
4041
{{end}}

examples/api/version.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Feature: get version
2020
And the response should match json:
2121
"""
2222
{
23-
"version": "v0.7.2"
23+
"version": "v0.7.4"
2424
}
2525
"""

fmt_progress_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,14 @@ Error: sub2: sub-sub: errored
184184
185185
1 scenarios (1 failed)
186186
2 steps (1 passed, 1 failed)
187-
0s
187+
%s
188188
189189
Randomized with seed: %s
190190
`
191191

192192
expected = trimAllLines(expected)
193-
expected = fmt.Sprintf(expected, os.Getenv("GODOG_SEED"))
193+
var zeroDuration time.Duration
194+
expected = fmt.Sprintf(expected, zeroDuration.String(), os.Getenv("GODOG_SEED"))
194195
actual := trimAllLines(buf.String())
195196

196197
shouldMatchOutput(expected, actual, t)

godog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ Godog was inspired by Behat and Cucumber the above description is taken from it'
3939
package godog
4040

4141
// Version of package - based on Semantic Versioning 2.0.0 http://semver.org/
42-
const Version = "v0.7.3"
42+
const Version = "v0.7.4"

run.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"io"
66
"os"
7+
"path/filepath"
8+
"runtime"
79
"strconv"
810
"strings"
911

@@ -154,6 +156,9 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt
154156

155157
// store chosen seed in environment, so it could be seen in formatter summary report
156158
os.Setenv("GODOG_SEED", strconv.FormatInt(r.randomSeed, 10))
159+
// determine tested package
160+
_, filename, _, _ := runtime.Caller(1)
161+
os.Setenv("GODOG_TESTED_PACKAGE", runsFromPackage(filename))
157162

158163
var failed bool
159164
if opt.Concurrency > 1 {
@@ -167,6 +172,17 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt
167172
return exitSuccess
168173
}
169174

175+
func runsFromPackage(fp string) string {
176+
dir := filepath.Dir(fp)
177+
for _, gp := range gopaths {
178+
gp = filepath.Join(gp, "src")
179+
if strings.Index(dir, gp) == 0 {
180+
return strings.TrimLeft(strings.Replace(dir, gp, "", 1), string(filepath.Separator))
181+
}
182+
}
183+
return dir
184+
}
185+
170186
// Run creates and runs the feature suite.
171187
// Reads all configuration options from flags.
172188
// uses contextInitializer to register contexts

run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestPrintsStepDefinitions(t *testing.T) {
3333
s.printStepDefinitions(w)
3434

3535
out := buf.String()
36-
ref := `github.com/DATA-DOG/godog.okStep`
36+
ref := `okStep`
3737
for i, def := range strings.Split(strings.TrimSpace(out), "\n") {
3838
if idx := strings.Index(def, steps[i]); idx == -1 {
3939
t.Fatalf(`step "%s" was not found in output`, steps[i])

stepdef.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package godog
22

33
import (
44
"fmt"
5+
"os"
56
"path/filepath"
67
"reflect"
78
"regexp"
@@ -68,6 +69,12 @@ func (sd *StepDef) definitionID() string {
6869
fn = strings.Trim(fn, "_.")
6970
}
7071

72+
if pkg := os.Getenv("GODOG_TESTED_PACKAGE"); len(pkg) > 0 {
73+
fn = strings.Replace(fn, pkg, "", 1)
74+
fn = strings.TrimLeft(fn, ".")
75+
fn = strings.Replace(fn, "..", ".", -1)
76+
}
77+
7178
return fmt.Sprintf("%s:%d -> %s", filepath.Base(file), line, fn)
7279
}
7380

0 commit comments

Comments
 (0)