Skip to content

Commit 72f4ba2

Browse files
committed
chore: add tests for failing hooks
1 parent f17ca43 commit 72f4ba2

File tree

3 files changed

+67
-15
lines changed

3 files changed

+67
-15
lines changed
Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
@bats
22
Feature: Test scenario and step hook bindings
33

4-
Background:
5-
Given a background step
6-
7-
@scenariohook @stephook
8-
Scenario: Run Scenario and Step hooks
4+
@fail_scenariohook_before
5+
Scenario: Run failing Scenario hooks before
96
Given a given step
10-
When a when step
11-
Then a then step
127

13-
@scenariohook
14-
Scenario: Run only Scenario hooks
8+
@fail_scenariohook_after
9+
Scenario: Run failing Scenario hooks after
1510
Given a given step
16-
When a when step
17-
Then a then step
1811

19-
@stephook
20-
Scenario: Run only Step hooks
12+
@throw_scenariohook
13+
Scenario: Run throwing Scenario hooks
2114
Given a given step
22-
When a when step
23-
Then a then step
15+
16+
Rule: These scenarios have a background
17+
18+
Background:
19+
Given a background step
20+
21+
@scenariohook @stephook
22+
Scenario: Run Scenario and Step hooks
23+
Given a given step
24+
When a when step
25+
Then a then step
26+
27+
@scenariohook
28+
Scenario: Run only Scenario hooks
29+
Given a given step
30+
When a when step
31+
Then a then step
32+
33+
@stephook
34+
Scenario: Run only Step hooks
35+
Given a given step
36+
When a when step
37+
Then a then step

cucumber_cpp/acceptance_test/hooks/Hooks.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cucumber_cpp/library/Hooks.hpp"
2+
#include "gmock/gmock.h"
23
#include <iostream>
34

45
HOOK_BEFORE_ALL()
@@ -30,3 +31,18 @@ HOOK_AFTER_STEP("@stephook and @bats")
3031
{
3132
std::cout << "HOOK_AFTER_STEP\n";
3233
}
34+
35+
HOOK_BEFORE_SCENARIO("@fail_scenariohook_before")
36+
{
37+
ASSERT_THAT(false, testing::IsTrue());
38+
}
39+
40+
HOOK_AFTER_SCENARIO("@fail_scenariohook_after")
41+
{
42+
ASSERT_THAT(false, testing::IsTrue());
43+
}
44+
45+
HOOK_BEFORE_SCENARIO("@throw_scenariohook")
46+
{
47+
throw "error";
48+
}

cucumber_cpp/acceptance_test/test.bats

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,25 @@ teardown() {
154154
assert_failure
155155
assert_output --partial "tests : 1/2 passed"
156156
}
157+
158+
@test "Test failing hook before results in error" {
159+
run .build/Host/cucumber_cpp/acceptance_test/Debug/cucumber_cpp.acceptance_test run --feature cucumber_cpp/acceptance_test/features --tag "@fail_scenariohook_before" --report console
160+
assert_failure
161+
assert_output --partial "skipped Given a given step"
162+
assert_output --partial "tests : 0/1 passed"
163+
}
164+
165+
@test "Test failing hook after results in error" {
166+
run .build/Host/cucumber_cpp/acceptance_test/Debug/cucumber_cpp.acceptance_test run --feature cucumber_cpp/acceptance_test/features --tag "@fail_scenariohook_after" --report console
167+
assert_failure
168+
assert_output --partial "Given a given step"
169+
assert_output --partial "-> done"
170+
assert_output --partial "tests : 0/1 passed"
171+
}
172+
173+
@test "Test throwing hook results in error" {
174+
run .build/Host/cucumber_cpp/acceptance_test/Debug/cucumber_cpp.acceptance_test run --feature cucumber_cpp/acceptance_test/features --tag "@throw_scenariohook" --report console
175+
assert_failure
176+
assert_output --partial "skipped Given a given step"
177+
assert_output --partial "tests : 0/1 passed"
178+
}

0 commit comments

Comments
 (0)