From 2609eb24f62f026db336774965ec741e2382b166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Br=C3=A4ndli?= Date: Fri, 30 Oct 2026 10:15:31 +0000 Subject: [PATCH 1/2] Add wire protocol tests for doc string arguments Cucumber-Ruby 7.1 and 10 send a doc string as an additional string argument in the invoke request, which the existing tests for string arguments already cover. Add a test for a doc string that spans multiple lines and contains indentation and quotes, and check that a step definition receives such a doc string unchanged. Assisted-by: Claude Code --- tests/integration/WireProtocolTest.cpp | 74 ++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/integration/WireProtocolTest.cpp b/tests/integration/WireProtocolTest.cpp index d11fb041..21ea578a 100644 --- a/tests/integration/WireProtocolTest.cpp +++ b/tests/integration/WireProtocolTest.cpp @@ -1,5 +1,9 @@ #include #include +#include +#include +#include +#include "utils/StepManagerTestDouble.hpp" #include @@ -182,6 +186,25 @@ TEST_F(WireMessageCodecTest, handlesInvokeMessageWithNullArg) { .run(engine); } +TEST_F(WireMessageCodecTest, handlesInvokeMessageWithMultilineDocStringArg) { + MockCukeEngine engine; + EXPECT_CALL( + engine, + invokeStep( + "42", ElementsAre("p1", "first line\n \"indented\" line\n\nlast line"), ElementsAre() + ) + ) + .Times(1); + + decode(R"json([ + "invoke", { + "id": "42", + "args": ["p1", "first line\n \"indented\" line\n\nlast line"] + } + ])json") + .run(engine); +} + TEST_F(WireMessageCodecTest, handlesEndScenarioMessageWithoutArgument) { MockCukeEngine engine; EXPECT_CALL(engine, endScenario(ElementsAre())).Times(1); @@ -391,3 +414,54 @@ TEST(WireCommandsTest, throwingAnythingInvokeReturnsFailure) { EXPECT_PTRTYPE(FailureResponse, response.get()); // TODO Test empty } + +/* + * Request handling with step definitions + */ + +class StepWithArgAndDocString : public GenericStep { +public: + void body() override { + REGEX_PARAM(string, arg); + REGEX_PARAM(string, docString); + EXPECT_EQ("p1", arg); + EXPECT_EQ("first line\n indented line", docString); + } +}; + +class WireProtocolHandlerTest : public Test { +protected: + const JsonWireMessageCodec codec; + CukeEngineImpl engine; + const WireProtocolHandler handler; + + WireProtocolHandlerTest() : + handler(codec, engine) { + } + + void SetUp() override { + std::shared_ptr stepInfo( + std::make_shared>("^a step with (.+):$", "") + ); + stepInfo->id = 42; + StepManagerTestDouble::addStep(stepInfo); + } + + void TearDown() override { + StepManagerTestDouble::clearSteps(); + } +}; + +TEST_F(WireProtocolHandlerTest, passesDocStringArgToStepDefinition) { + EXPECT_EQ(handler.handle(R"(["begin_scenario"])"), R"(["success"])"); + EXPECT_EQ( + handler.handle(R"json([ + "invoke", { + "id": "42", + "args": ["p1", "first line\n indented line"] + } + ])json"), + R"(["success"])" + ); + EXPECT_EQ(handler.handle(R"(["end_scenario"])"), R"(["success"])"); +} From e7c5e6221bbcf0b02af9b4b82b79354547e176bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Br=C3=A4ndli?= Date: Fri, 30 Oct 2026 10:15:37 +0000 Subject: [PATCH 2/2] Add a doc string example to FeatureShowcase Show how a step definition receives a doc string: as the last argument, after the regex parameters. The steps check the received text exactly, including line breaks and indentation, for a doc string without and with content type and for one following a regex parameter. The content type itself is not sent over the wire. As the functional tests run this example, they also check that the doc strings arrive unchanged over the wire. Assisted-by: Claude Code --- examples/FeatureShowcase/CMakeLists.txt | 1 + examples/FeatureShowcase/README.txt | 2 +- .../features/docstring.feature | 32 +++++++++ .../step_definitions/DocStringSteps.cpp | 67 +++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 examples/FeatureShowcase/features/docstring.feature create mode 100644 examples/FeatureShowcase/features/step_definitions/DocStringSteps.cpp diff --git a/examples/FeatureShowcase/CMakeLists.txt b/examples/FeatureShowcase/CMakeLists.txt index 9706df68..96e5feff 100644 --- a/examples/FeatureShowcase/CMakeLists.txt +++ b/examples/FeatureShowcase/CMakeLists.txt @@ -13,6 +13,7 @@ if(TARGET GTest::gtest) add_cucumber_executable( features/step_definitions/TagSteps.cpp features/step_definitions/TableSteps.cpp + features/step_definitions/DocStringSteps.cpp ) endif() diff --git a/examples/FeatureShowcase/README.txt b/examples/FeatureShowcase/README.txt index 044d7175..190b49e3 100644 --- a/examples/FeatureShowcase/README.txt +++ b/examples/FeatureShowcase/README.txt @@ -1,2 +1,2 @@ -This sample shows a few advanced features: tags and table arguments. +This sample shows a few advanced features: tags, table and doc string arguments. diff --git a/examples/FeatureShowcase/features/docstring.feature b/examples/FeatureShowcase/features/docstring.feature new file mode 100644 index 00000000..491f9da4 --- /dev/null +++ b/examples/FeatureShowcase/features/docstring.feature @@ -0,0 +1,32 @@ +# language: en +Feature: Doc string + In order to explain how to use doc strings + I have to make this silly example + + Scenario: Doc string + Given the following quote: + """ + I'm gonna make him an offer + he can't refuse. + + "The Godfather", 1972 + """ + Then the quote should keep its line breaks and indentation + + Scenario: Doc string with content type + Given the following quote: + """json + { + "actor": "Marlon Brando", + "quote": "I'm gonna make him an offer he can't refuse." + } + """ + Then the quote should be the plain JSON text + + Scenario: Doc string after a regex parameter + Given Morgan Freeman said: + """ + Get busy living, + or get busy dying. + """ + Then Morgan Freeman should be quoted on two lines diff --git a/examples/FeatureShowcase/features/step_definitions/DocStringSteps.cpp b/examples/FeatureShowcase/features/step_definitions/DocStringSteps.cpp new file mode 100644 index 00000000..b9afe679 --- /dev/null +++ b/examples/FeatureShowcase/features/step_definitions/DocStringSteps.cpp @@ -0,0 +1,67 @@ +#include +#include + +#include + +using cucumber::ScenarioScope; + +struct Quote { + std::string author; + std::string text; +}; + +/* + * The doc string is passed as the last argument, after the regex parameters. + */ + +GIVEN("^the following quote:$") { + REGEX_PARAM(std::string, text); + ScenarioScope context; + + context->text = text; +} + +GIVEN("^(.+) said:$") { + REGEX_PARAM(std::string, author); + REGEX_PARAM(std::string, text); + ScenarioScope context; + + context->author = author; + context->text = text; +} + +THEN("^the quote should keep its line breaks and indentation$") { + ScenarioScope context; + + ASSERT_EQ( + "I'm gonna make him an offer\n" + " he can't refuse.\n" + "\n" + "\"The Godfather\", 1972", + context->text + ); +} + +/* + * The content type of a doc string is not sent over the wire, only its content. + */ + +THEN("^the quote should be the plain JSON text$") { + ScenarioScope context; + + ASSERT_EQ( + "{\n" + " \"actor\": \"Marlon Brando\",\n" + " \"quote\": \"I'm gonna make him an offer he can't refuse.\"\n" + "}", + context->text + ); +} + +THEN("^(.+) should be quoted on two lines$") { + REGEX_PARAM(std::string, author); + ScenarioScope context; + + ASSERT_EQ(author, context->author); + ASSERT_EQ("Get busy living,\nor get busy dying.", context->text); +}