Skip to content

Commit 59d4a5c

Browse files
committed
Tagged hooks for JRuby. Fixes #467.
1 parent 4419df3 commit 59d4a5c

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

src/main/java/cucumber/runtime/jruby/JRubyBackend.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ public void registerStepdef(RubyObject stepdefRunner) {
123123
glue.addStepDefinition(new JRubyStepDefinition(this, stepdefRunner));
124124
}
125125

126-
public void registerBeforeHook(RubyObject procRunner) {
127-
glue.addBeforeHook(new JRubyHookDefinition(this, new String[0], procRunner));
126+
public void registerBeforeHook(RubyObject procRunner, String[] tagExpressions) {
127+
glue.addBeforeHook(new JRubyHookDefinition(this, tagExpressions, procRunner));
128128
}
129129

130-
public void registerAfterHook(RubyObject procRunner) {
131-
glue.addAfterHook(new JRubyHookDefinition(this, new String[0], procRunner));
130+
public void registerAfterHook(RubyObject procRunner, String[] tagExpressions) {
131+
glue.addAfterHook(new JRubyHookDefinition(this, tagExpressions, procRunner));
132132
}
133133

134134
public void registerWorldBlock(RubyObject procRunner) {

src/main/resources/cucumber/runtime/jruby/dsl.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ def pattern
9393
end
9494

9595
module Dsl
96-
def Before(&proc)
97-
$backend.registerBeforeHook(HookRunner.new(proc))
96+
def Before(*tag_expressions, &proc)
97+
$backend.registerBeforeHook(HookRunner.new(proc), tag_expressions)
9898
end
9999

100-
def After(&proc)
101-
$backend.registerAfterHook(HookRunner.new(proc))
100+
def After(*tag_expressions, &proc)
101+
$backend.registerAfterHook(HookRunner.new(proc), tag_expressions)
102102
end
103103

104104
def World(*modules_or_proc)

src/test/resources/cucumber/runtime/jruby/test/cukes.feature

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
Feature: Cukes
22

3+
@tag
4+
Scenario: running tagged hook
5+
Then tagged hook ran
6+
7+
Scenario: not running tagged hook
8+
Then tagged hook didn't run
9+
310
Scenario: in the belly
411
Given I have 4 "cukes" in my belly
512
Then I am "happy"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'cucumber/api/jruby/en'
2+
3+
Before('@tag') do
4+
@tagged_hook_ran = true
5+
end
6+
7+
Then /^tagged hook ran$/ do
8+
raise "Tagged hook didn't run when it should" unless @tagged_hook_ran
9+
end
10+
11+
Then /^tagged hook didn't run$/ do
12+
raise "Tagged hook ran when it shouldn't" if @tagged_hook_ran
13+
end

0 commit comments

Comments
 (0)