A set of bazel rules for BDD with cucumber/gherkin.
You'll need a Gemfile and Gemfile.lock in the root of your workspace with the following content:
source 'https://rubygems.org'
gem 'cucumber', '~> 10.2.0'
gem 'cucumber-wire', '~> 8.0.0'Run bundle install to generate the Gemfile.lock file.
Add the following to your MODULE.bazel (see examples/MODULE.bazel for complete example):
bazel_dep(name = "rules_gherkin", version = "0.1.0")
bazel_dep(name = "rules_ruby", version = "0.21.1")
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
name = "ruby",
version = "jruby-9.4.5.0",
)
ruby.bundle_fetch(
name = "cucumber",
gem_checksums = { ... }, # See examples/MODULE.bazel for complete checksums
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)
use_repo(ruby, "cucumber", "ruby", "ruby_toolchains")
register_toolchains("@ruby_toolchains//:all")Note: The gem_checksums dictionary is required for hermetic builds. See examples/MODULE.bazel for the complete list of checksums.
Create a BUILD.bazel file in your feature directory:
load("@rules_gherkin//gherkin:defs.bzl", "gherkin_library", "gherkin_test", "cc_gherkin_steps")
# Define your feature files
gherkin_library(
name = "feature_specs",
srcs = glob(["**/*.feature"]),
)
# Define step implementations in C++
cc_gherkin_steps(
name = "calculator_steps",
srcs = [
"CalculatorSteps.cpp",
],
visibility = ["//visibility:public"],
deps = [
"//Calc/src:calculator",
"@cucumber-cpp//:cucumber-cpp",
"@googletest//:gtest_main",
],
)
# Create test target
gherkin_test(
name = "calc_test",
steps = ":calculator_steps",
deps = [":feature_specs"],
)You can configure the cucumber output format using the --@rules_gherkin//:cucumber_format flag:
bazel test //path/to:test --@rules_gherkin//:cucumber_format=jsonAvailable formats:
pretty(default) - Human-readable outputjson- JSON formathtml- HTML reportjunit- JUnit XML format
Big thank you to 'Paolo Ambrosio', who authored the cucumber-cpp from whom I copied and modified the //examples directory in this repository. The examples/LICENCE.txt has been added to reflect the origins of the example.
