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: Add support for step argument (go-bdd#149) #150

Merged
merged 2 commits into from
Nov 24, 2023
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
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linters:
- golint
- scopelint
- gosec
- depguard

# Disabled after upgrading golangci-lint
# Enable them after issues are resolved
Expand Down
6 changes: 3 additions & 3 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package gobdd
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestContextNilInGetError(t *testing.T) {
ctx := NewContext()
ctx.Set("err", nil)

res, err := ctx.GetError("err")
assert.NoError(t, err)
assert.Nil(t, res)
require.NoError(t, err)
require.NoError(t, res)
}
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!
"""
16 changes: 10 additions & 6 deletions gobdd.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ type stepDef struct {
}

type StepTest interface {
Log(...interface{})
Logf(string, ...interface{})
Fatal(...interface{})
Fatalf(string, ...interface{})
Errorf(string, ...interface{})
Error(...interface{})
Log(args ...interface{})
Logf(format string, args ...interface{})
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Error(args ...interface{})

Fail()
FailNow()
Expand Down Expand Up @@ -541,6 +541,10 @@ 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
2 changes: 1 addition & 1 deletion gobdd_go1_16.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func WithFeaturesFS(fs fs.FS, path string) func(*SuiteOptions) {
return func(options *SuiteOptions) {
options.featureSource = fsFeatureSource{
fs: fs,
fs: fs,
path: path,
}
}
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
Loading