Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: output suggestions in the order steps were defined #29

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ type suite struct {
When you run the tests, they should fail and suggest that you add these
step definitions:
```go
func (s *suite) IEat(a int64) {
func (s *suite) IHaveCukes(a int64) {
panic("PENDING")
}

func (s *suite) IHaveLeft(a int64) {
func (s *suite) IEat(a int64) {
panic("PENDING")
}

func (s *suite) IHaveCukes(a int64) {
func (s *suite) IHaveLeft(a int64) {
panic("PENDING")
}

Steps can be manually registered with the runner for customization using this code:
Step(`^I\s+have\s+(-?\d+)\s+cukes$`, (*simpleSuite).IHaveCukes).
Step(`^I\s+eat\s+(-?\d+)$`, (*simpleSuite).IEat).
Step(`^I\s+have\s+(-?\d+)\s+left$`, (*simpleSuite).IHaveLeft)
Step(`^I\s+have\s+(-?\d+)\s+cukes$`, (*suite).IHaveCukes).
Step(`^I\s+eat\s+(-?\d+)$`, (*suite).IEat).
Step(`^I\s+have\s+(-?\d+)\s+left$`, (*suite).IHaveLeft)
```

Copy these definitions into `simple_test.go`.
Expand Down
5 changes: 4 additions & 1 deletion find_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func (r *Runner) findStep(t *testing.T, step *messages.PickleStep) *stepDef {
return r.addStepDef(t, sig.regex, method.Func)
}

r.suggestions[sig.name] = sig
if !r.haveSuggestion[sig.name] {
r.haveSuggestion[sig.name] = true
r.suggestions = append(r.suggestions, sig)
}
t.Errorf("can't find step definition for: %s", step.Text)

return nil
Expand Down
11 changes: 6 additions & 5 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type Runner struct {
paths []string
parallel bool
stepDefs []*stepDef
suggestions map[string]methodSig
haveSuggestion map[string]bool
suggestions []methodSig
supportedSpecialArgs map[reflect.Type]specialArgGetter
suiteInjectors []*suiteInjector
beforeHooks []*stepDef
Expand Down Expand Up @@ -56,10 +57,10 @@ func NewRunner(t *testing.T, suiteType interface{}) *Runner {
initGlobalTagExpr()

r := &Runner{
topLevelT: t,
incr: &messages.Incrementing{},
parallel: false,
suggestions: map[string]methodSig{},
topLevelT: t,
incr: &messages.Incrementing{},
parallel: false,
haveSuggestion: map[string]bool{},
supportedSpecialArgs: map[reflect.Type]specialArgGetter{
// TestingT
reflect.TypeOf((*TestingT)(nil)).Elem(): func(runner *scenarioRunner) interface{} {
Expand Down
Loading