tests/testthat/test-validate.R

describe("validate_feature", {
  it("should have only one 'Feature:' keyword", {
    expect_snapshot_error(
      validate_feature(
        c(
          "Feature: feature 1",
          "  Scenario: scenario",
          "Feature: bar"
        )
      )
    )
  })

  it("shouldn't produce error feature with valid indentation", {
    withr::with_options(list(cucumber.indent = "^\\s{2}"), {
      expect_no_error(
        validate_feature(
          c(
            "Feature: foo",
            "  Scenario: bar",
            "    Given foo",
            "    When foo",
            "    Then foo"
          )
        )
      )
    })
  })

  it("should validate indent", {
    withr::with_options(list(cucumber.indent = "^\\s{4}"), {
      expect_snapshot_error(
        validate_feature(
          c(
            "Feature: foo",
            "  Scenario: bar",
            "    Given foo",
            "    When foo",
            "    Then foo"
          )
        )
      )
    })
  })
})

Try the cucumber package in your browser

Any scripts or data that you put into this service are public.

cucumber documentation built on June 8, 2025, 12:47 p.m.