{"id":18001619,"url":"https://github.com/jakubsob/cucumber","last_synced_at":"2025-03-26T08:30:53.073Z","repository":{"id":221762140,"uuid":"755315592","full_name":"jakubsob/cucumber","owner":"jakubsob","description":"Behavior-Driven Development for R","archived":false,"fork":false,"pushed_at":"2025-03-20T21:08:20.000Z","size":8584,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-20T21:16:53.620Z","etag":null,"topics":["acceptance-testing","behavior-driven-development","cucumber","r","testing"],"latest_commit_sha":null,"homepage":"https://jakubsob.github.io/cucumber/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jakubsob.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","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":"2024-02-09T21:48:09.000Z","updated_at":"2025-03-20T20:46:22.000Z","dependencies_parsed_at":"2024-03-18T22:43:40.844Z","dependency_job_id":"1dd360db-967b-4355-ba6b-a3b2c18d5af8","html_url":"https://github.com/jakubsob/cucumber","commit_stats":null,"previous_names":["jakubsob/cucumber"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubsob%2Fcucumber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubsob%2Fcucumber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubsob%2Fcucumber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubsob%2Fcucumber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakubsob","download_url":"https://codeload.github.com/jakubsob/cucumber/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244794872,"owners_count":20511516,"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":["acceptance-testing","behavior-driven-development","cucumber","r","testing"],"created_at":"2024-10-29T23:18:13.596Z","updated_at":"2025-03-26T08:30:53.035Z","avatar_url":"https://github.com/jakubsob.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"\n# cucumber \u003cimg src=\"man/figures/logo.png\" align=\"right\" alt=\"\" width=\"120\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/jakubsob/cucumber/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jakubsob/cucumber/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/jakubsob/cucumber/branch/main/graph/badge.svg)](https://app.codecov.io/gh/jakubsob/cucumber?branch=main)\n[![CRAN status](https://www.r-pkg.org/badges/version/cucumber)](https://CRAN.R-project.org/package=cucumber)\n[![Grand total](http://cranlogs.r-pkg.org/badges/grand-total/cucumber)](https://cran.r-project.org/package=cucumber)\n[![Last month](http://cranlogs.r-pkg.org/badges/last-month/cucumber)](https://cran.r-project.org/package=cucumber)\n\u003c!-- badges: end --\u003e\n\nAn implementation of the [Cucumber](https://cucumber.io/) testing framework in R. Fully native, no external dependencies.\n\nUse it as an extension of your `testthat` tests or as a standalone testing stage.\n\n## Introduction\n\nThe package parses [Gherkin](https://cucumber.io/docs/gherkin/reference/) documents\n\n```gherkin\n# tests/testthat/addition.feature\nFeature: Addition\n  Scenario: Adding 2 integers\n    When I add 1 and 1\n    Then the result is 2\n  Scenario: Adding integer and float\n    When I add 1 and 1.1\n    Then the result is 2.1\n  Scenario: Adding float and float\n    When I add 1.1 and 1.1\n    Then the result is 2.2\n```\n\nand uses step definitions to run the tests\n\n```r\n# tests/testthat/steps/steps_definitions.R\nwhen(\"I add {int} and {int}\", function(x, y, context) {\n  context$result \u003c- x + y\n})\n\nthen(\"the result is {int}\", function(expected, context) {\n  expect_equal(context$result, expected)\n})\n\nwhen(\"I add {int} and {float}\", function(x, y, context) {\n  context$result \u003c- x + y\n})\n\nwhen(\"I add {float} and {float}\", function(x, y, context) {\n  context$result \u003c- x + y\n})\n\nthen(\"the result is {float}\", function(expected, context) {\n  expect_equal(context$result, expected)\n})\n```\n\n### Running cucumber tests with `testthat` tests.\n\nTo run `cucumber` as a part of `testthat` suite, create a `test-cucumber.R` file:\n\n```r\n#' tests/testthat/test-cucumber.R\ncucumber::test(\".\", \"./steps\")\n```\n\nWhen you run:\n- `testthat::test_dir(\"tests/testthat\")`,\n- `testthat::test_file(\"tests/testthat/test-cucumber.R\")`,\n- or `devtools::test()`,\n\nit will use the [testthat reporter](https://testthat.r-lib.org/reference/Reporter.html) to show the results.\n\n\nThe building blocks of the cucumber tests are Features and Scenarios.\n- Each Feature will be treated as a separate [context](https://testthat.r-lib.org/reference/context.html?q=context#ref-usage) – their results will be reported as if they were `test-*.R` files, e.g. `'test-Feature: Addition.R'`.\n- Each Scenario is equivalent to a `testthat::test_that` or `testthat::it` case. You get feedback on each Scenario separately. Only if all steps in a scenario are successful, the scenario is considered successful.\n\nThat means a succesful run for an `Addition` feature would produce the following output (with [ProgressReporter](https://testthat.r-lib.org/reference/ProgressReporter.html)).\n\n```r\n| v | F W  S  OK | Context           |\n| v | 3          | Feature: Addition |\n== Results ================================================\n[ FAIL 0 | WARN 0 | SKIP 0 | PASS 3 ]\n```\n\nAnd if it doesn't succeed, it will report which Scenarios failed in the Feature.\n\n```r\n| v | F W  S  OK | Context           |\n| x | 2        1 | Feature: Addition |\n--------------------------------------------------------------------------------\nFailure ('test-cucumber.R:1:1'): Scenario: Adding integer and float\ncontext$result (`actual`) not equal to `expected` (`expected`).\n`actual`: 2\n`expected`: 5\nBacktrace:\nx\n1. \\-global `\u003cstep\u003e`(expected = 5L, context = `\u003cenv\u003e`)\n2.   \\-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:2\nFailure ('test-cucumber.R:1:1'): Scenario: Adding float and float\ncontext$result (`actual`) not equal to `expected` (`expected`).\n`actual`: 2\n`expected`: 5\nBacktrace:\nx\n1. \\-global `\u003cstep\u003e`(expected = 5L, context = `\u003cenv\u003e`)\n2.   \\-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:2\n--------------------------------------------------------------------------------\n== Results =====================================================================\n-- Failed tests ----------------------------------------------------------------\nFailure ('test-cucumber.R:1:1'): Scenario: Adding integer and float\ncontext$result (`actual`) not equal to `expected` (`expected`).\n`actual`: 2\n`expected`: 5\nBacktrace:\nx\n1. \\-global `\u003cstep\u003e`(expected = 5L, context = `\u003cenv\u003e`)\n2.   \\-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:2\nFailure ('test-cucumber.R:1:1'): Scenario: Adding float and float\ncontext$result (`actual`) not equal to `expected` (`expected`).\n`actual`: 2\n`expected`: 5\nBacktrace:\nx\n1. \\-global `\u003cstep\u003e`(expected = 5L, context = `\u003cenv\u003e`)\n2.   \\-testthat::expect_equal(context$result, expected) at ./steps/addition.R:7:2\n[ FAIL 1 | WARN 0 | SKIP 0 | PASS 2 ]\n```\n\n## Running cucumber tests separately to unit tests\n\nIf you want to run cucumber tests separately, for example as a different testing step on CI, just put `cucumber` tests in other directory (or use [testthat::test_dir filter parameter](https://testthat.r-lib.org/reference/test_dir.html)).\n\nThis may be especially useful, if `cucumber` tests are significantly slower than unit tests. It may often be the case as `cucumber` tests should target integration of different parts of the system and provide a high level confirmation if the system works as expected.\n\n```\n├── tests/\n│   ├── cucumber/\n│   │   ├── steps/\n│   │   │   ├── feature_1_steps.R\n│   │   │   ├── feature_2_steps.R\n│   │   ├── feature_1.feature\n│   │   ├── feature_2.feature\n│   │   ├── test-cucumber.R\n│   ├── testthat/\n│   │   ├── test-unit_test_1.R\n│   │   ├── test-unit_test_2.R\n```\n\nIn that case you would run `cucumber` tests with `testthat::test_dir(\"tests/cucumber\")`.\n\n## Examples\n\nSee the [examples directory](https://github.com/jakubsob/cucumber/tree/main/inst/examples) to help you get started.\n\n## How it works\n\nThe `.feature` files are parsed and matched against step definitions.\n\nStep functions are defined using:\n- `description`: a [cucumber expression](https://github.com/cucumber/cucumber-expressions).\n- and an implementation function. It must have the parameters that will be matched in the description and a `context` parameter - an environment for managing state between steps.\n\nIf a step parsed from one of `.feature` files is not found, an error will be thrown.\n\n### Parameter types\n\nStep implementations receive data from the `.feature` files as parameters. The values are detected via regular expressions and casted with a transformer function.\n\nThe following parameter types are available by default:\n\n| Parameter Type | Description                                                                                                                                                                                                   |\n| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `{int}`        | Matches integers, for example `71` or `-19`. Converts value with `as.integer`.                                                                                                                                |\n| `{float}`      | Matches floats, for example `3.6`, `.8` or `-9.2`. Converts value with `as.double`.                                                                                                                           |\n| `{word}`       | Matches words without whitespace, for example banana (but not banana split).                                                                                                                                  |\n| `{string}`     | Matches single-quoted or double-quoted strings, for example \"banana split\" or 'banana split' (but not banana split). Only the text between the quotes will be extracted. The quotes themselves are discarded. |\n\nSee `cucumber::define_parameter_type()` how to define your own parameter types.\n\n## Supported Gherkin syntax:\n\n- [x] Feature\n- [x] Scenario\n- [x] Example\n- [x] Given\n- [x] When\n- [x] Then\n- [x] And\n- [x] But\n- [x] *\n- [x] Background\n- [x] Scenario Outline (or Scenario Template)\n- [x] Examples (or Scenarios)\n- [ ] Rule\n- [x] `\"\"\"` (Doc Strings)\n- [x] `|` (Data Tables)\n- [ ] `@` (Tags)\n- [x] `#` (Comments)\n- [x] Free-format text\n- [ ] Localization\n\n# Installation\n\nTo install the stable version from CRAN:\n\n```r\ninstall.packages(\"cucumber\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakubsob%2Fcucumber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakubsob%2Fcucumber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakubsob%2Fcucumber/lists"}