11#include " cucumber_cpp/library/engine/FeatureFactory.hpp"
22#include " cucumber_cpp/library/engine/StepType.hpp"
3- #include < filesystem>
4- #include < fstream>
3+ #include " cucumber_cpp/library/engine/test_helper/TemporaryFile.hpp"
54#include < functional>
65#include < gmock/gmock.h>
76#include < gtest/gtest.h>
1110
1211namespace cucumber_cpp ::library::engine
1312{
14- struct TemporaryFile
15- {
16- TemporaryFile (std::string_view name)
17- : path{ std::filesystem::temp_directory_path () / name }
18- {
19- }
20-
21- ~TemporaryFile ()
22- {
23- ofs.close ();
24- std::filesystem::remove (path);
25- }
26-
27- TemporaryFile& operator <<(const auto & data)
28- {
29- ofs << data; // NOLINT
30- ofs.flush ();
31- return *this ;
32- }
33-
34- std::filesystem::path Path () const
35- {
36- return path;
37- }
38-
39- private:
40- std::ofstream CreateOfstream ()
41- {
42- std::filesystem::create_directories (path.parent_path ());
43- return { path };
44- }
45-
46- std::filesystem::path path;
47- std::ofstream ofs{ CreateOfstream () };
48- };
4913
5014 struct TestFeatureFactory : testing::Test
5115 {
@@ -54,7 +18,7 @@ namespace cucumber_cpp::library::engine
5418
5519 TEST_F (TestFeatureFactory, CreateEmptyFeature)
5620 {
57- auto tmp = TemporaryFile{ " tmpfile.feature" };
21+ auto tmp = test_helper:: TemporaryFile{ " tmpfile.feature" };
5822
5923 tmp << " Feature: Test feature\n "
6024 " Custom\n "
@@ -73,7 +37,7 @@ namespace cucumber_cpp::library::engine
7337
7438 TEST_F (TestFeatureFactory, CreateScenario)
7539 {
76- auto tmp = TemporaryFile{ " tmpfile.feature" };
40+ auto tmp = test_helper:: TemporaryFile{ " tmpfile.feature" };
7741
7842 tmp << " Feature: Test feature\n "
7943 " Custom\n "
@@ -98,7 +62,7 @@ namespace cucumber_cpp::library::engine
9862
9963 TEST_F (TestFeatureFactory, CreateRules)
10064 {
101- auto tmp = TemporaryFile{ " tmpfile.feature" };
65+ auto tmp = test_helper:: TemporaryFile{ " tmpfile.feature" };
10266
10367 tmp << " Feature: Test feature\n "
10468 " Custom\n "
@@ -115,9 +79,6 @@ namespace cucumber_cpp::library::engine
11579 " Scenario: Test scenario2\n "
11680 " Custom Scenario\n "
11781 " Description\n " ;
118- // " Given I have a step\n"
119- // " When I do something\n"
120- // " Then I expect something\n";
12182
12283 const auto feature = featureTreeFactory.Create (tmp.Path (), " " );
12384 EXPECT_THAT (feature->Rules ().size (), testing::Eq (2 ));
@@ -148,7 +109,7 @@ namespace cucumber_cpp::library::engine
148109
149110 TEST_F (TestFeatureFactory, CreateSteps)
150111 {
151- auto tmp = TemporaryFile{ " tmpfile.feature" };
112+ auto tmp = test_helper:: TemporaryFile{ " tmpfile.feature" };
152113
153114 tmp << " Feature: Test feature\n "
154115 " Scenario: Test scenario1\n "
@@ -203,7 +164,7 @@ namespace cucumber_cpp::library::engine
203164
204165 TEST_F (TestFeatureFactory, CreateBackground)
205166 {
206- auto tmp = TemporaryFile{ " tmpfile.feature" };
167+ auto tmp = test_helper:: TemporaryFile{ " tmpfile.feature" };
207168
208169 tmp << " Feature: Test feature\n "
209170 " Background: Test background\n "
@@ -249,7 +210,7 @@ namespace cucumber_cpp::library::engine
249210
250211 TEST_F (TestFeatureFactory, CreateTagsTags)
251212 {
252- auto tmp = TemporaryFile{ " tmpfile.feature" };
213+ auto tmp = test_helper:: TemporaryFile{ " tmpfile.feature" };
253214
254215 tmp << " @feature\n "
255216 " Feature: Test feature\n "
@@ -273,7 +234,7 @@ namespace cucumber_cpp::library::engine
273234
274235 TEST_F (TestFeatureFactory, SelectTags)
275236 {
276- auto tmp = TemporaryFile{ " tmpfile.feature" };
237+ auto tmp = test_helper:: TemporaryFile{ " tmpfile.feature" };
277238
278239 tmp << " @feature\n "
279240 " Feature: Test feature\n "
@@ -297,7 +258,7 @@ namespace cucumber_cpp::library::engine
297258
298259 TEST_F (TestFeatureFactory, CreateMultipleScenariosInOneRule)
299260 {
300- auto tmp = TemporaryFile{ " tmpfile.feature" };
261+ auto tmp = test_helper:: TemporaryFile{ " tmpfile.feature" };
301262
302263 tmp << " Feature: Test feature\n "
303264 " Rule: Test rule\n "
@@ -327,7 +288,7 @@ namespace cucumber_cpp::library::engine
327288
328289 TEST_F (TestFeatureFactory, CreateTable)
329290 {
330- auto tmp = TemporaryFile{ " tmpfile.feature" };
291+ auto tmp = test_helper:: TemporaryFile{ " tmpfile.feature" };
331292
332293 tmp << " Feature: Test feature\n "
333294 " Scenario: Test scenario1\n "
0 commit comments