tests/testthat/test-parse_table.R

describe("parse_table", {
  it("should parse Gherkin table with 1 row", {
    # Arrange
    x <- c(
      "| start | eat | left |",
      "|    12 |   5 |    7 |"
    )

    # Act
    result <- parse_table(x)

    # Assert
    expect_equal(
      result,
      tibble::tibble(
        start = c("12"),
        eat = c("5"),
        left = c("7")
      )
    )
  })

  it("should parse Gherkin table with header only", {
    # Arrange
    x <- c(
      "| start | eat | left |"
    )

    # Act
    result <- parse_table(x)

    # Assert
    expect_equal(
      result,
      tibble::tibble(
        start = character(),
        eat = character(),
        left = character()
      )
    )
  })

  it("should parse Gherkin table with many rows", {
    # Arrange
    x <- c(
      "| start | eat | left |",
      "|    12 |   5 |    7 |",
      "|    13 |   6 |    7 |"
    )

    # Act
    result <- parse_table(x)

    # Assert
    expect_equal(
      result,
      tibble::tibble(
        start = c("12", "13"),
        eat = c("5", "6"),
        left = c("7", "7")
      )
    )
  })
})

Try the cucumber package in your browser

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

cucumber documentation built on June 30, 2024, 1:07 a.m.