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

fix: example tests #27

Merged
merged 2 commits into from
Jan 8, 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
5 changes: 3 additions & 2 deletions custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"regexp"
"testing"

"github.com/regen-network/gocuke"
"github.com/stretchr/testify/require"

"github.com/regen-network/gocuke"
)

func TestCustomSteps(t *testing.T) {
gocuke.NewRunner(t, &customStepsSuite{}).
Path("_examples/simple/simple.feature").
Path("examples/simple/simple.feature").
Step(`I have (\d+) cukes`, (*customStepsSuite).A).
Step(regexp.MustCompile(`I eat (\d+)`), (*customStepsSuite).B).
Step(`I have (\d+) left`, (*customStepsSuite).C).
Expand Down
File renamed without changes.
10 changes: 8 additions & 2 deletions _examples/api/api_test.go → examples/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"net/http/httptest"
"testing"

"github.com/regen-network/gocuke"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/regen-network/gocuke"
)

type suite struct {
Expand All @@ -19,7 +20,12 @@ type suite struct {

func TestApi(t *testing.T) {
scope := &suite{TestingT: t, resp: httptest.NewRecorder()}
gocuke.NewRunner(t, scope).
run := gocuke.NewRunner(t, scope)
run.Before(func() {
scope.resp = httptest.NewRecorder()
})

run.
Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, scope.ISendRequestTo).
Step(`^the response code should be (\d+)$`, scope.TheResponseCodeShouldBe).
Step(`^the response should match json:$`, scope.TheResponseShouldMatchJson).
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestSimple(t *testing.T) {
gocuke.NewRunner(t, &simpleSuite{}).Path("_examples/simple/simple.feature").Run()
gocuke.NewRunner(t, &simpleSuite{}).Path("examples/simple/simple.feature").Run()
}

type simpleSuite struct {
Expand All @@ -31,7 +31,7 @@ func (s *simpleSuite) IHaveLeft(a int64) {

// test if a struct that doesn't use a pointer and a global var
func TestSimpleNonPointer(t *testing.T) {
gocuke.NewRunner(t, simpleSuiteNP{}).Path("_examples/simple/simple.feature").Run()
gocuke.NewRunner(t, simpleSuiteNP{}).Path("examples/simple/simple.feature").Run()
}

var globalCukes int64
Expand Down
Loading