From 8ae0e452e6feec1824d68953f277bbefec06efa5 Mon Sep 17 00:00:00 2001 From: Vincent LALANNE Date: Thu, 23 Nov 2023 08:20:11 +0000 Subject: [PATCH] feat: Add support for step argument (go-bdd#149) --- features/argument.feature | 21 +++++++++++++++++++++ gobdd.go | 3 +++ gobdd_test.go | 8 ++++++++ 3 files changed, 32 insertions(+) create mode 100644 features/argument.feature diff --git a/features/argument.feature b/features/argument.feature new file mode 100644 index 0000000..2e2807e --- /dev/null +++ b/features/argument.feature @@ -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! + """ diff --git a/gobdd.go b/gobdd.go index 28edfe8..22b410f 100644 --- a/gobdd.go +++ b/gobdd.go @@ -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) diff --git a/gobdd_test.go b/gobdd_test.go index 0b915d8..3764619 100644 --- a/gobdd_test.go +++ b/gobdd_test.go @@ -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"))