From c69d9f0c7dc18226eb3837cbd3059f63216a06fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Rasmusson?= Date: Sun, 22 Jul 2018 10:47:36 +0200 Subject: [PATCH] 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. --- cucumber.yml | 1 + features/docs/iso-8859-1.feature | 1 + lib/cucumber/runtime/support_code.rb | 2 ++ spec/cucumber/runtime/support_code_spec.rb | 36 ++++++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/cucumber.yml b/cucumber.yml index ad0442c936..4a1a6bc90c 100644 --- a/cucumber.yml +++ b/cucumber.yml @@ -1,6 +1,7 @@ <% cucumber_pro_opts = ENV['ENABLE_CUCUMBER_PRO'] ? "--format Cucumber::Pro --out /dev/null" : "" std_opts = "--format progress features -r features --strict #{cucumber_pro_opts}".dup +std_opts << " --tags 'not @wip'" std_opts << " --tags 'not @wip-jruby'" if defined?(JRUBY_VERSION) wip_opts = "--color -r features".dup diff --git a/features/docs/iso-8859-1.feature b/features/docs/iso-8859-1.feature index 9c6b5057c0..929c9660ac 100644 --- a/features/docs/iso-8859-1.feature +++ b/features/docs/iso-8859-1.feature @@ -1,5 +1,6 @@ # language: no # encoding: iso-8859-1 +@wip Egenskap: Alle bruker ikke UTF-8 Scenario: Dette bør gå bra Når jeg drikker en "øl" diff --git a/lib/cucumber/runtime/support_code.rb b/lib/cucumber/runtime/support_code.rb index 816b537f92..33029be516 100644 --- a/lib/cucumber/runtime/support_code.rb +++ b/lib/cucumber/runtime/support_code.rb @@ -112,12 +112,14 @@ def find_after_step_hooks(test_case) end def apply_before_hooks(test_case) + return test_case if test_case.test_steps.empty? scenario = RunningTestCase.new(test_case) hooks = registry.hooks_for(:before, scenario) BeforeHooks.new(hooks, scenario).apply_to(test_case) end def apply_after_hooks(test_case) + return test_case if test_case.test_steps.empty? scenario = RunningTestCase.new(test_case) hooks = registry.hooks_for(:after, scenario) AfterHooks.new(hooks, scenario).apply_to(test_case) diff --git a/spec/cucumber/runtime/support_code_spec.rb b/spec/cucumber/runtime/support_code_spec.rb index 6613c4b223..7c5a6f0f96 100644 --- a/spec/cucumber/runtime/support_code_spec.rb +++ b/spec/cucumber/runtime/support_code_spec.rb @@ -12,5 +12,41 @@ module Cucumber @rb = subject.ruby Object.new.extend(RbSupport::RbDsl) end + + describe '#apply_before_hooks' do + let(:test_case) { double } + let(:test_step) { double } + + it 'applies before hooks to test cases with steps' do + allow(test_case).to receive(:test_steps).and_return([test_step]) + allow(test_case).to receive(:with_steps).and_return(double) + + expect(subject.apply_before_hooks(test_case)).not_to equal(test_case) + end + + it 'does not apply before hooks to test cases with no steps' do + allow(test_case).to receive(:test_steps).and_return([]) + + expect(subject.apply_before_hooks(test_case)).to equal(test_case) + end + end + + describe '#apply_after_hooks' do + let(:test_case) { double } + let(:test_step) { double } + + it 'applies after hooks to test cases with steps' do + allow(test_case).to receive(:test_steps).and_return([test_step]) + allow(test_case).to receive(:with_steps).and_return(double) + + expect(subject.apply_after_hooks(test_case)).not_to equal(test_case) + end + + it 'does not apply after hooks to test cases with no steps' do + allow(test_case).to receive(:test_steps).and_return([]) + + expect(subject.apply_after_hooks(test_case)).to equal(test_case) + end + end end end