Skip to content

Commit 41dda56

Browse files
committed
test: add tests for missing and ambiguous step reporting from Feature Factory
1 parent 8aae362 commit 41dda56

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

cucumber_cpp/library/engine/test/TestFeatureFactory.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace cucumber_cpp::library::engine
2222
StepRegistry stepRegistry{ parameterRegistry };
2323

2424
test_helper::ContextManagerInstance contextManager;
25-
report::ReportForwarderImpl reportForwarderImpl{ contextManager };
25+
report::test_helper::ReportForwarderMock reportForwarderImpl{ contextManager };
2626
FeatureTreeFactory featureTreeFactory{ stepRegistry, reportForwarderImpl };
2727
};
2828

@@ -315,4 +315,30 @@ namespace cucumber_cpp::library::engine
315315
EXPECT_THAT(scenario1->Children()[0]->Table()[1][0].As<std::string>(), testing::StrEq("c"));
316316
EXPECT_THAT(scenario1->Children()[0]->Table()[1][1].As<std::string>(), testing::StrEq("d"));
317317
}
318+
319+
TEST_F(TestFeatureFactory, MissingStepsAreReported)
320+
{
321+
auto tmp = test_helper::TemporaryFile{ "tmpfile.feature" };
322+
323+
tmp << "Feature: Test feature\n"
324+
" Scenario: Test scenario\n"
325+
" Given this is a missing step\n";
326+
327+
EXPECT_CALL(reportForwarderImpl, StepMissing);
328+
329+
const auto feature = featureTreeFactory.Create(tmp.Path(), "");
330+
}
331+
332+
TEST_F(TestFeatureFactory, AmbiguousStepsAreReported)
333+
{
334+
auto tmp = test_helper::TemporaryFile{ "tmpfile.feature" };
335+
336+
tmp << "Feature: Test feature\n"
337+
" Scenario: Test scenario\n"
338+
" Given this is ambiguous\n";
339+
340+
EXPECT_CALL(reportForwarderImpl, StepAmbiguous);
341+
342+
const auto feature = featureTreeFactory.Create(tmp.Path(), "");
343+
}
318344
}

cucumber_cpp/library/engine/test_helper/StepImplementations.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,13 @@ THEN(R"(An expression with \\\{escaped braces\\} should keep the slash)")
110110
{
111111
/* do nothing */
112112
}
113+
114+
GIVEN("this is ambiguous")
115+
{
116+
// empty
117+
}
118+
119+
GIVEN("this is ambiguous( or not)")
120+
{
121+
// empty
122+
}

cucumber_cpp/library/report/test_helper/ReportForwarderMock.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef TEST_HELPER_REPORTFORWARDERMOCK_HPP
22
#define TEST_HELPER_REPORTFORWARDERMOCK_HPP
33

4+
#include "cucumber_cpp/library/engine/StepInfo.hpp"
45
#include "cucumber_cpp/library/report/Report.hpp"
56
#include <cstddef>
67
#include <filesystem>
@@ -15,6 +16,9 @@ namespace cucumber_cpp::library::report::test_helper
1516
using ReportForwarderImpl::ReportForwarderImpl;
1617
virtual ~ReportForwarderMock() = default;
1718

19+
MOCK_METHOD(void, StepMissing, (const std::string& stepText), (override));
20+
MOCK_METHOD(void, StepAmbiguous, (const std::string& stepText, const engine::StepInfo& stepInfo), (override));
21+
1822
MOCK_METHOD(void, Failure, (const std::string& error, std::optional<std::filesystem::path> path, std::optional<std::size_t> line, std::optional<std::size_t> column), (override));
1923
MOCK_METHOD(void, Error, (const std::string& error, std::optional<std::filesystem::path> path, std::optional<std::size_t> line, std::optional<std::size_t> column), (override));
2024
};

0 commit comments

Comments
 (0)