{"id":18881148,"url":"https://github.com/godogx/expandvars","last_synced_at":"2026-04-29T22:03:47.972Z","repository":{"id":38187123,"uuid":"403869744","full_name":"godogx/expandvars","owner":"godogx","description":"Expand variables in cucumber/godog tests","archived":false,"fork":false,"pushed_at":"2024-03-01T18:21:18.000Z","size":70,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-12-31T03:27:01.974Z","etag":null,"topics":["bdd","cucumber","functional-testing","gherkin","go","godog","godog-extension","golang","integration-testing","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/godogx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-07T06:40:38.000Z","updated_at":"2021-11-21T12:27:47.000Z","dependencies_parsed_at":"2024-11-15T22:31:17.180Z","dependency_job_id":"bf7ad759-03cf-4d6d-8831-408fc1e6796b","html_url":"https://github.com/godogx/expandvars","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godogx%2Fexpandvars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godogx%2Fexpandvars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godogx%2Fexpandvars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godogx%2Fexpandvars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/godogx","download_url":"https://codeload.github.com/godogx/expandvars/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239850449,"owners_count":19707348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bdd","cucumber","functional-testing","gherkin","go","godog","godog-extension","golang","integration-testing","testing"],"created_at":"2024-11-08T06:47:43.457Z","updated_at":"2026-02-21T00:30:16.632Z","avatar_url":"https://github.com/godogx.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Variables Expander for Cucumber Steps\n\n[![GitHub Releases](https://img.shields.io/github/v/release/godogx/expandvars)](https://github.com/godogx/expandvars/releases/latest)\n[![Build Status](https://github.com/godogx/expandvars/actions/workflows/test.yaml/badge.svg)](https://github.com/godogx/expandvars/actions/workflows/test.yaml)\n[![codecov](https://codecov.io/gh/godogx/expandvars/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/godogx/expandvars)\n[![Go Report Card](https://goreportcard.com/badge/github.com/godogx/expandvars)](https://goreportcard.com/report/github.com/godogx/expandvars)\n[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/godogx/expandvars)\n\nA lifesaver expander for [`cucumber/godog`](https://github.com/cucumber/godog) because, sometimes, you have to use variables in your steps.\n\n## Prerequisites\n\n- `Go \u003e= 1.16`\n\n## Install\n\n```bash\ngo get github.com/godogx/expandvars\n```\n\n## Usage\n\nInitiate a new `StepExpander` with `expandvars.NewStepExpander()` then add it to `ScenarioInitializer` by\ncalling `StepExpander.RegisterContext(*testing.T, *godog.ScenarioContext)`\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"math/rand\"\n    \"strings\"\n    \"testing\"\n\n    \"github.com/cucumber/godog\"\n    \"github.com/godogx/expandvars\"\n    \"github.com/stretchr/testify/assert\"\n)\n\nfunc TestIntegration(t *testing.T) {\n    expander := expandvars.NewStepExpander(\n        strings.NewReplacer(\"$TO\", \"Berlin\"),\n        expandvars.Pairs{\n            \"HUSBAND\": \"John\",\n        },\n        func() expandvars.Pairs {\n            return expandvars.Pairs{\n                \"RAND\": fmt.Sprintf(\"%d\", rand.Int63()),\n            }\n        },\n        expandvars.BeforeScenario(func() expandvars.Pairs {\n            return expandvars.Pairs{\n                \"SCENARIO_RAND\": fmt.Sprintf(\"%d\", rand.Int63()),\n            }\n        }),\n        func(s string) string {\n            return strings.ReplaceAll(s, \"$FROM\", \"Paris\")\n        },\n        expandvars.Expander(func(s string) string {\n            return strings.ReplaceAll(s, \"$TRANSPORT\", \"by bus\")\n        }),\n        // OS env vars.\n        expandvars.EnvExpander,\n    )\n\n    suite := godog.TestSuite{\n        Name: \"Integration\",\n        ScenarioInitializer: func(ctx *godog.ScenarioContext) {\n            expander.RegisterContext(ctx)\n        },\n        Options: \u0026godog.Options{\n            Strict:    true,\n            Randomize: rand.Int63(),\n        },\n    }\n\n    // Run the suite.\n}\n```\n\nIn your tests, just use `$VARIABLE_NAME` in the step or the argument, like this:\n\n```gherkin\n    Scenario: var is replaced\n        Given var NAME is replaced in step text: $NAME\n\n        Then step text is:\n        \"\"\"\n        map var NAME is replaced in step text: John\n        \"\"\"\n\n        Given var NAME is replaced in step argument (string)\n        \"\"\"\n        NAME=$NAME\n        \"\"\"\n\n        Then step argument is a string:\n        \"\"\"\n        NAME=John\n        \"\"\"\n\n        Given env var NAME is replaced in step argument (table)\n            | col 1   | col 2 | col 3   |\n            | value 1 | $NAME | value 3 |\n\n        Then step argument is a table:\n            | col 1   | col 2 | col 3   |\n            | value 1 | John  | value 3 |\n```\n\n```gherkin\n    Scenario: .github files\n        Then there should be only these files in \"$TEST_DIR/.github\":\n        \"\"\"\n        - workflows:\n            - golangci-lint.yaml\n            - test.yaml\n        \"\"\"\n```\n\n### Expanders\n\nThe expanders could be any of these:\n\n1. A `Replacer` interface\n\n```go\ntype Replacer interface {\n    Replace(string) string\n}\n```\n\n2. A `Replacer` `func(string) string` function. \u003cbr/\u003e\u003cbr/\u003e\n   For example, you could use `os.ExpandEnv` or its alias `expandvars.EnvExpander`\n\n3. A map or vars (without the `$`) `map[string]string`\n\n```go\nvar _ = expandvars.NewStepExpander(expandvars.Pairs{\n    \"HUSBAND\": \"John\",\n    \"WIFE\":    \"Jane\",\n})\n```\n\n4. A provider that provides a map of vars (without the `$`) `map[string]string`. The provider will be called every step.\n\n```go\nvar _ = expandvars.NewStepExpander(func() expandvars.Pairs {\n    return map[string]string{\n        \"RAND\": fmt.Sprintf(\"%d\", rand.Int63()),\n    }\n})\n```\n\n5. A `BeforeScenario` provides a map of vars (without the `$`) `map[string]string`. The provider will be called only once before every scenario.\n\n**Note**: If you need `expandvars.EnvExpander` or `os.ExpandEnv`, put it in the end of the chain. Because it replaces not-found vars with empty strings, other\nexpanders won't have a chance to do their jobs if you put it in the beginning.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgodogx%2Fexpandvars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgodogx%2Fexpandvars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgodogx%2Fexpandvars/lists"}