Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not apply Before and After Hooks to Test Cases with no Test Steps #1311

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cucumber.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions features/docs/iso-8859-1.feature
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions lib/cucumber/runtime/support_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions spec/cucumber/runtime/support_code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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