Skip to content

Commit bcf6bce

Browse files
Johnlonvearutop
andauthored
ambiguous step def detection akin to cucumber jvm (#636)
* added basic detection for ambiguous steps, but causes an error and not yet recorded in the reports as 'Ambiguous', and no test cases figured out yet * added initial support for detection of ambiguous steps - further work take a look at how cuke jvm report ambiguous steps and sets the step status to 'ambiguous' rather than my current solution which just blows the test up as a regular step error * added suite_context_test and also introduced missing 'ambiguous' status to make cucumber jvm' * update CHANGELOG for ambiguous step defs * missed file from commit * added internal/formatters/fmt_multi_test.go * add tests for other peoples code * added "ambigous" to the help text * tests * added some more tests for attachments * Update internal/flags/flags.go Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com> --------- Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>
1 parent 3abb346 commit bcf6bce

File tree

15 files changed

+442
-118
lines changed

15 files changed

+442
-118
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
88

99
## Unreleased
1010

11+
- Ambiguous step definitions will now be detected when strit mode is activated - ([636](https://github.com/cucumber/godog/pull/636) - [johnlon](https://github.com/johnlon))
1112
- Provide support for attachments / embeddings including a new example in the examples dir - ([623](https://github.com/cucumber/godog/pull/623) - [johnlon](https://github.com/johnlon))
1213

1314
## [v0.14.1]

attachment_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package godog
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestAttach(t *testing.T) {
11+
12+
ctx := context.Background()
13+
14+
ctx = Attach(ctx, Attachment{Body: []byte("body1"), FileName: "fileName1", MediaType: "mediaType1"})
15+
ctx = Attach(ctx, Attachment{Body: []byte("body2"), FileName: "fileName2", MediaType: "mediaType2"})
16+
17+
attachments := Attachments(ctx)
18+
19+
assert.Equal(t, 2, len(attachments))
20+
21+
assert.Equal(t, []byte("body1"), attachments[0].Body)
22+
assert.Equal(t, "fileName1", attachments[0].FileName)
23+
assert.Equal(t, "mediaType1", attachments[0].MediaType)
24+
25+
assert.Equal(t, []byte("body2"), attachments[1].Body)
26+
assert.Equal(t, "fileName2", attachments[1].FileName)
27+
assert.Equal(t, "mediaType2", attachments[1].MediaType)
28+
}

flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func BindFlags(prefix string, set *flag.FlagSet, opt *Options) {
121121
set.BoolVar(&opt.ShowStepDefinitions, prefix+"definitions", defShowStepDefinitions, "Print all available step definitions.")
122122
set.BoolVar(&opt.ShowStepDefinitions, prefix+"d", defShowStepDefinitions, "Print all available step definitions.")
123123
set.BoolVar(&opt.StopOnFailure, prefix+"stop-on-failure", defStopOnFailure, "Stop processing on first failed scenario.")
124-
set.BoolVar(&opt.Strict, prefix+"strict", defStrict, "Fail suite when there are pending or undefined steps.")
124+
set.BoolVar(&opt.Strict, prefix+"strict", defStrict, "Fail suite when there are pending or undefined or ambiguous steps.")
125125
set.BoolVar(&opt.NoColors, prefix+"no-colors", defNoColors, "Disable ansi colors.")
126126
set.Var(&randomSeed{&opt.Randomize}, prefix+"random", descRandomOption)
127127
set.BoolVar(&opt.ShowHelp, "godog.help", false, "Show usage help.")

formatters/fmt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type Formatter interface {
7070
Skipped(*messages.Pickle, *messages.PickleStep, *StepDefinition)
7171
Undefined(*messages.Pickle, *messages.PickleStep, *StepDefinition)
7272
Pending(*messages.Pickle, *messages.PickleStep, *StepDefinition)
73+
Ambiguous(*messages.Pickle, *messages.PickleStep, *StepDefinition, error)
7374
Summary()
7475
}
7576

internal/flags/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ built-in formatters are:
3939

4040
flagSet.BoolVarP(&opts.ShowStepDefinitions, prefix+"definitions", "d", opts.ShowStepDefinitions, "print all available step definitions")
4141
flagSet.BoolVar(&opts.StopOnFailure, prefix+"stop-on-failure", opts.StopOnFailure, "stop processing on first failed scenario")
42-
flagSet.BoolVar(&opts.Strict, prefix+"strict", opts.Strict, "fail suite when there are pending or undefined steps")
42+
flagSet.BoolVar(&opts.Strict, prefix+"strict", opts.Strict, "fail suite when there are pending or undefined or ambiguous steps")
4343

4444
flagSet.Int64Var(&opts.Randomize, prefix+"random", opts.Randomize, `randomly shuffle the scenario execution order
4545
--random

internal/flags/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Options struct {
3838
// Stops on the first failure
3939
StopOnFailure bool
4040

41-
// Fail suite when there are pending or undefined steps
41+
// Fail suite when there are pending or undefined or ambiguous steps
4242
Strict bool
4343

4444
// Forces ansi color stripping

internal/formatters/fmt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636
skipped = models.Skipped
3737
undefined = models.Undefined
3838
pending = models.Pending
39+
ambiguous = models.Skipped
3940
)
4041

4142
type sortFeaturesByName []*models.Feature

internal/formatters/fmt_base.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func (f *Base) Failed(*messages.Pickle, *messages.PickleStep, *formatters.StepDe
8585
func (f *Base) Pending(*messages.Pickle, *messages.PickleStep, *formatters.StepDefinition) {
8686
}
8787

88+
// Ambiguous captures ambiguous step.
89+
func (f *Base) Ambiguous(*messages.Pickle, *messages.PickleStep, *formatters.StepDefinition, error) {
90+
}
91+
8892
// Summary renders summary information.
8993
func (f *Base) Summary() {
9094
var totalSc, passedSc, undefinedSc int

internal/formatters/fmt_cucumber.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ func (f *Cuke) buildCukeElements(pickles []*messages.Pickle) (res []cukeElement)
101101
cukeStep.Result.Duration = &d
102102
if stepResult.Status == undefined ||
103103
stepResult.Status == pending ||
104-
stepResult.Status == skipped {
104+
stepResult.Status == skipped ||
105+
stepResult.Status == ambiguous {
105106
cukeStep.Result.Duration = nil
106107
}
107108

internal/formatters/fmt_multi.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ func (r repeater) Pending(pickle *messages.Pickle, step *messages.PickleStep, de
9797
}
9898
}
9999

100+
// Ambiguous triggers Ambiguous for all added formatters.
101+
func (r repeater) Ambiguous(pickle *messages.Pickle, step *messages.PickleStep, definition *formatters.StepDefinition, err error) {
102+
for _, f := range r {
103+
f.Ambiguous(pickle, step, definition, err)
104+
}
105+
}
106+
100107
// Summary triggers Summary for all added formatters.
101108
func (r repeater) Summary() {
102109
for _, f := range r {

0 commit comments

Comments
 (0)