-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from jakubsob/4-indentation
✨ Allow setting feature file indentation
- Loading branch information
Showing
16 changed files
with
203 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: cucumber | ||
Type: Package | ||
Title: Behavior-Driven Development for R | ||
Version: 1.1.0 | ||
Version: 1.1.1 | ||
Authors@R: person("Jakub", "Sobolewski", email = "[email protected]", role = c("aut", "cre")) | ||
Description: Write executable specifications in a natural language that describes how your code should behave. | ||
Write specifications in feature files using 'Gherkin' language and execute them using functions implemented in R. | ||
|
@@ -24,6 +24,7 @@ Suggests: | |
Config/testthat/edition: 3 | ||
Imports: | ||
checkmate, | ||
cli, | ||
dplyr, | ||
fs, | ||
glue, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#' {cucumber} Options | ||
#' | ||
#' Internally used, package-specific options. | ||
#' They allow overriding the default behavior of the package. | ||
#' | ||
#' @details | ||
#' | ||
#' The following options are available: | ||
#' | ||
#' - `cucumber.indent` | ||
#' | ||
#' Regular expression for the indent of the feature files. | ||
#' | ||
#' default: `^\\s{2}` | ||
#' | ||
#' - `cucumber.interactive` | ||
#' | ||
#' Logical value indicating whether to ask which feature files to run. | ||
#' | ||
#' default: `FALSE` | ||
#' | ||
#' See [base::options()] and [base::getOption()] on how to work with options. | ||
#' | ||
#' @md | ||
#' @name opts | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#' Validate lines read from a feature file | ||
#' @keywords internal | ||
validate_feature <- function(lines) { | ||
# Remove comments and empty lines for validation | ||
clean_lines <- remove_comments(remove_empty_lines(lines)) | ||
clean_lines |> | ||
validate_indentation() | ||
invisible(lines) | ||
} | ||
|
||
#' @keywords internal | ||
#' @importFrom stringr str_detect | ||
#' @importFrom cli cli_abort | ||
validate_indentation <- function(lines) { | ||
indent <- getOption("cucumber.indent", default = "^\\s{2}") | ||
test_lines <- lines[!str_detect(lines, "^Feature")] |> | ||
remove_empty_lines() | ||
if (any(!str_detect(test_lines, indent))) { | ||
cli_abort(c( | ||
"All lines must be indented with {indent}", | ||
"i" = "Check the {.code getOption('cucumber.indent')} option if it is set to your feature file indent." | ||
)) | ||
} | ||
invisible(lines) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# validate_feature: should validate indent | ||
|
||
All lines must be indented with ^\s{4} | ||
i Check the `getOption('cucumber.indent')` option if it is set to your feature file indent. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
describe("validate_feature", { | ||
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" | ||
) | ||
) | ||
) | ||
}) | ||
}) | ||
}) |