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 7b4f70a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.47
version: v1.55

coverage:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18']
go: ['1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21']
env:
GOFLAGS: -mod=readonly
GOPROXY: https://proxy.golang.org
Expand Down
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) {

Check failure on line 547 in gobdd.go

View workflow job for this annotation

GitHub Actions / Lint

expressions should not be cuddled with blocks (wsl)
// 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 7b4f70a

Please sign in to comment.