Skip to content

Commit

Permalink
Merge #1311 'Do not apply Hooks to Test Cases with no Test Steps'
Browse files Browse the repository at this point in the history
Also update Changelog.md.
  • Loading branch information
brasmusson committed Jul 26, 2018
2 parents 7f43c95 + c69d9f0 commit 59311e4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

### Changed

* Do not apply Before and After Hooks to Test Cases with no Test Steps.
([#1311](https://github.com/cucumber/cucumber-ruby/pull/1311)
[brasmusson](https://github.com/brasmusson))
* Pass the registry to the Wire plugin.
([#1309](https://github.com/cucumber/cucumber-ruby/pull/1309)
[brasmusson](https://github.com/brasmusson))
Expand Down
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

0 comments on commit 59311e4

Please sign in to comment.