Skip to content

Commit 1a51997

Browse files
committed
Only apply before and after hooks to test cases with test steps
Also mark the iso-8859-1.feature as wip since the gherkin library (v5.1.0) does not support using iso-8859-1 in feature files.
1 parent b90cce8 commit 1a51997

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

cucumber.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<%
22
cucumber_pro_opts = ENV['ENABLE_CUCUMBER_PRO'] ? "--format Cucumber::Pro --out /dev/null" : ""
33
std_opts = "--format progress features -r features --strict #{cucumber_pro_opts}".dup
4+
std_opts << " --tags 'not @wip'"
45
std_opts << " --tags 'not @wip-jruby'" if defined?(JRUBY_VERSION)
56
67
wip_opts = "--color -r features".dup

features/docs/iso-8859-1.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# language: no
22
# encoding: iso-8859-1
3+
@wip
34
Egenskap: Alle bruker ikke UTF-8
45
Scenario: Dette bør gå bra
56
Når jeg drikker en "øl"

lib/cucumber/runtime/support_code.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ def find_after_step_hooks(test_case)
112112
end
113113

114114
def apply_before_hooks(test_case)
115+
return test_case if test_case.test_steps.empty?
115116
scenario = RunningTestCase.new(test_case)
116117
hooks = registry.hooks_for(:before, scenario)
117118
BeforeHooks.new(hooks, scenario).apply_to(test_case)
118119
end
119120

120121
def apply_after_hooks(test_case)
122+
return test_case if test_case.test_steps.empty?
121123
scenario = RunningTestCase.new(test_case)
122124
hooks = registry.hooks_for(:after, scenario)
123125
AfterHooks.new(hooks, scenario).apply_to(test_case)

spec/cucumber/runtime/support_code_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,41 @@ module Cucumber
1212
@rb = subject.ruby
1313
Object.new.extend(RbSupport::RbDsl)
1414
end
15+
16+
describe '#apply_before_hooks' do
17+
let(:test_case) { double }
18+
let(:test_step) { double }
19+
20+
it 'applies before hooks to test cases with steps' do
21+
allow(test_case).to receive(:test_steps).and_return([test_step])
22+
allow(test_case).to receive(:with_steps).and_return(double)
23+
24+
expect(subject.apply_before_hooks(test_case)).not_to equal(test_case)
25+
end
26+
27+
it 'does not apply before hooks to test cases with no steps' do
28+
allow(test_case).to receive(:test_steps).and_return([])
29+
30+
expect(subject.apply_before_hooks(test_case)).to equal(test_case)
31+
end
32+
end
33+
34+
describe '#apply_after_hooks' do
35+
let(:test_case) { double }
36+
let(:test_step) { double }
37+
38+
it 'applies after hooks to test cases with steps' do
39+
allow(test_case).to receive(:test_steps).and_return([test_step])
40+
allow(test_case).to receive(:with_steps).and_return(double)
41+
42+
expect(subject.apply_after_hooks(test_case)).not_to equal(test_case)
43+
end
44+
45+
it 'does not apply after hooks to test cases with no steps' do
46+
allow(test_case).to receive(:test_steps).and_return([])
47+
48+
expect(subject.apply_after_hooks(test_case)).to equal(test_case)
49+
end
50+
end
1551
end
1652
end

0 commit comments

Comments
 (0)