Skip to content

Commit

Permalink
feat: Add support for step argument (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlalanne committed Nov 23, 2023
1 parent 625de17 commit 713e2b0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions features/argument.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Argument feature
Scenario: compare text with argument
When I concat text "Hello " and argument:
"""
World!
"""
Then the result should equal argument:
"""
Hello World!
"""
Scenario: compare text with multiline argument
When I concat text "Hello " and argument:
"""
New
World!
"""
Then the result should equal argument:
"""
Hello New
World!
"""
3 changes: 3 additions & 0 deletions gobdd.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ func (s *Suite) runStep(ctx Context, t *testing.T, step *msgs.GherkinDocument_Fe
}

params := def.expr.FindSubmatch([]byte(step.Text))[1:]
if argument, ok := step.Argument.(*msgs.GherkinDocument_Feature_Step_DocString_); ok {
params = append(params, []byte(argument.DocString.Content))
}
t.Run(fmt.Sprintf("%s %s", strings.TrimSpace(step.Keyword), step.Text), func(t *testing.T) {
// NOTE consider passing t as argument to step hooks
ctx.Set(TestingTKey{}, t)
Expand Down
8 changes: 8 additions & 0 deletions gobdd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func TestParameterTypes(t *testing.T) {
suite.Run()
}

func TestArguments(t *testing.T) {
suite := NewSuite(t, WithFeaturesPath("features/argument.feature"))
suite.AddStep(`the result should equal argument:`, checkt)
suite.AddStep(`I concat text {text} and argument:`, concat)

suite.Run()
}

func TestScenarioOutlineExecutesAllTests(t *testing.T) {
c := 0
suite := NewSuite(t, WithFeaturesPath("features/outline.feature"))
Expand Down

0 comments on commit 713e2b0

Please sign in to comment.